When I ssh into my local vagrant machine I can execute all artisan commands. Hower outside of it, any commands that needs database access such as artisan migrate gives Access denied for user 'root'#'localhost'. If it is possible, how can I use artisan without having to log in to the vagrant machine?
I would also like to do for example Artisian::call('migrate') for example during testing. But that gives the same error.
The reason for the access denied error is that mysql by default limits access to databases to the local machine. It is possible to open up for remote connections as described here, but it wouldn't be a good idea for production environments.
A better way is to add aliases for the commands you want as described here.
For doing calls to artisan etc in code, Laravel has a built in way of running commands on remote servers. First add connection information to the app/config/remote.php file. For vagrant it should look something like this:
'connections' => array(
'production' => array(
'host' => 'localhost',
'username' => 'vagrant',
'password' => 'vagrant',
'key' => '',
'keyphrase' => '',
'root' => '/vagrant',
),
),
Then execute artisan migrate like this:
SSH::run(array('cd /vagrant', 'php artisan migrate'));
You can do more advanced things as well. Here is the documentation.
Related
I have my project ready and I have just uploaded to a shared hosting server. Everything works perfectly fine on my local machine but the page is displaying the error:
"SQLSTATE[28000] [1045] Access denied for user 'root'#'localhost' (using password: NO)"
I have checked my password and username and they are both correct. The server requirements are also as I already have 2 other Laravel sites running with the same host.
I have done php artisan config:cache php artisan cache:clear But no headway.
What could be causing this and how do I get it solved? I earnestly need a solutions as this has kept me sleepless for nights now.
try to with these 3 artisan command.
1) php artisan config:clear
2) php artisan cache:clear
3) php artisan config:cache
different config? it's saying your password is empty ;)
"I have checked my password and username"
"(using password: NO)"
app/config/database.php:
'mysql' => array(
'read' => array(
'host' => '192.168.1.1',
),
'write' => array(
'host' => '196.168.1.2'
),
'driver' => 'mysql',
'database' => 'database',
'username' => 'root',
'password' => '<insert password here?>',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
Open terminal and type
sudo mysql -u root -p
It will prompt you in mysql, here you can fire any mysql commands.
Use mysql table for change table type, so we can use empty password. Bellow is command for it
USE mysql;
Now we change type of table by following command
UPDATE user SET plugin='mysql_native_password' WHERE User='root';
now we have to flush the privileges, because we have used UPDATE. If you use INSERT, UPDATE or DELETE on grant tables directly you need use FLUSH PRIVILEGES in order to reload the grant tables.
FLUSH PRIVILEGES;
now exit from mysql by following command
exit;
now restart mysql server by following command
service mysql restart
Hope this may help
Thank you.
Anytime you deploy a project, you should typically run the php artisan config:cache command as part of your production deployment routine. I suggest you
Remove the configuration cache file
Flush the application cache
Create a cache file for faster configuration loading
To do this, run the following Artisan commands on your command line
php artisan config:clear
php artisan cache:clear
php artisan config:cache
Where you don't have access to the command line on your server, you can programmatically execute commands by adding the following to your routes:
Route::get('/clear-cache', function() {
$exitCode = Artisan::call('config:clear');
$exitCode = Artisan::call('cache:clear');
$exitCode = Artisan::call('config:cache');
return 'DONE'; //Return anything
});
And then call the clear-cache route from your browser.
I'm using spatie/laravel-backup in a WAMP localhost.
It works fine when I type manually in the windows cmd:
php artisan backup:run
But when I try to run the backup using the laravel Artisan class:
Artisan::call('backup:run');
It throw an error:
'mysqldump' not recognized ...
In the laravel mysql config I've also specified the path to the dumper:
'mysql' => [
'driver' => 'mysql',
// ...
'dump' => [
'dump_binary_path' => 'E:/wamp/wamp64/bin/mysql/mysql5.7.9/bin',
],
],
How can i fix that?
EDIT
Probably it's just support "bug" for windows (finded out thanks Loek's answer), as the author says, so can I run a backup in a controller without a command safely? maybe with something like:
use Spatie\Backup\Tasks\Backup\BackupJobFactory;
BackupJobFactory::createFromArray(config('laravel-backup'))->run();
As the command itself.
I believe it's the forward slashes. Try this:
'mysql' => [
'driver' => 'mysql',
// ...
'dump' => [
'dump_binary_path' => 'E:\\wamp\\wamp64\\bin\\mysql\\mysql5.7.9\\bin',
],
],
EDIT
Support for Windows is wonky at best, with multiple "This package doesn't support Windows" comments from the creators on GitHub issues. This one is the latest: https://github.com/spatie/laravel-backup/issues/311
It could also be a permission problem. Executing from the command line is probably happening from another user than executing from the web server, so Windows is denying access to mysqldump.
2nd edit
As long as you make sure the controller only gets called when it needs to be, I don't see why this wouldn't work!
I'm using Laravel 5 but I'm not being able to migrate my database table. I have a macbook pro and I'm using Terminal. I'm using php artisan command:
php artisan migrate.
When I execute this command, I get the following error message: [PDOException]
SQLSTATE[HY000] [2002] Connection refused.
I have configured my database.php following the official tutorial videos on laracasts.com. My database.php file looks like the following:
...
'fetch' => PDO::FETCH_CLASS,
...
'default' => env('DB_CONNECTION', 'sqlite'),
...
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => database_path('database.sqlite'),
'prefix' => '',
],
....
I have read many comments on stackoverflow.com about this issue. Most of them are talking about modifying the ".env" file. The thing is I can't find this file! Which makes me wonder if my installation of Laravel is complete or not! I read that my ".env" file might be overriding my "database.php" file but I can't file the ".env" file!
The env file is most likely hidden.
Run defaults write com.apple.finder AppleShowAllFiles YES and Killall Finder in Terminal.
Open Finder and you should be able to see the .env file.
Edit your .env file.
When I run php artisan migrate on my local server (running by php artisan serve) I get the following error:
[ErrorExeption]
Undefined index: REMOTE_ADDR
I tried also php artisan migrate --database db_name, output is like this:
[InvalidArgumentExeption]
Database [db_name] not configured.
My app/config/local/database.php looks like following:
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost', // also tried 127.0.0.1
'database' => 'db_name',
'username' => 'root',
'password' => 'mypassword',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
)
)
I'm sure MySQL works, I checked it via command line and phpMyAdmin.
Also I included HostnameLookups On inside my httpd.conf, then restarted apache, but nothing helps.
I use Laravel 4.2, Debian.
Any ideas? Thanks in advance.
P.S. Sorry for my English:)
UPD:
Output of php artisan env is Current application environment: local
UPD2:
I created simple route:
Route::get('/test', function() {
return $_SERVER["REMOTE_ADDR"];
});
It returns ::1, but when I execute echo $_SERVER["REMOTE_ADDR"]; in php interactive mode (php -a) I get a Notice: Undefined index: REMOTE_ADDR
When you get an artisan error, that error has possibly nothing to do with the command currently tried to run with artisan, but with some any other coding error you recently made. Search in your code for any recent reference to REMOTE_ADDR.
If you haven't done so, make sure you're accessing SERVER_ADDR using the $_SERVER array to obtain the value of SERVER_ADDR, which is an element of this array.
$_SERVER['SERVER_ADDR'];
If that doesn't work, it may mean that your server doesn't provide that information.
From PHP.net:
There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here.
We have a appserver3 over LAN, means there is folder in remote server and I just map that folder in my my compurt and suppose it got the drive letter G. now when I excute the following
php artisan migrate --package=cartalyst/sentry
but it try to install db in my localhost. But I want to db operation in appserver3. please help me
I assume you have the web server and database up on your appserver3. You could add a new set of config files for your "appserver3" machine, and make sure the db host points to the appserver3's ip address. Something like this:
app/config/appserver3/database.php:
'connections' => array(
...
'host' => 'your appserver3 ip address',
...
)
Then you can run artisan command and specify the environment:
php artisan migrate --package=cartalyst/sentry --env=appserver3