I'm using Laravel 4.2 in remote server and I want to execute Laravel commands php artisan migrate
but I don't know how.

- 19,824
- 17
- 99
- 186

- 137
- 1
- 2
- 6
-
1Is your remote server Linux? Do a web search for "server SSH tutorial", that should cover it. Check with your hosting provider that SSH access is provided. If not you might have to run these commands via a script, which is not ideal. – halfer Sep 14 '14 at 21:46
-
(Please note that questions this brief, and not featuring any evidence of prior research, will usually be closed here). – halfer Sep 14 '14 at 21:47
5 Answers
You can ssh to the server and perform the command, you can add your servers public key to the remote server to do this without a password. I made a bash script with the following code which I can then execute manually via command line or from a program, lets say I call it myscript.sh with the following code
ssh root@127.0.0.1 << EOF
cd /var/www/app/;
php artisan migrate --force; // force prevents artisan from asking for a yes/no on production
exit;
EOF
now I can write 'sh myscript.sh' and it will run migrations on the remote server.

- 378
- 4
- 17
The preferred way to do this:
- ssh into your server (for example, username root & server ip 1.1.1.1:
ssh root@1.1.1.1
). - go to your project folder (for example:
cd /var/....
) - run the command
php artisan migrate
.
Original post (not the best way):
You can setup a cronjob like this:
* * * * * /usr/bin/php /var/www/app/artisan schedule:run
This will run every minute and run the migration.
You can change this to everything you want.
If you want to open a url what while be excecuting the command.
Use this code:
Artisan::call('migrate');
Hope this works!

- 3,322
- 25
- 40
-
1
-
It's an example, he could also call another command like: `php artisan schedule:run` – Robin Dirksen Mar 30 '18 at 17:41
For the completeness of this article, you do this with Windows host using PS remote (enable first) then...
$Username = "{domain}\{domain account}"
$PasswordSS = ConvertTo-SecureString '{domain account password}' -AsPlainText -Force
$Cred = New-Object System.management.Automation.PSCredential $Username,$PasswordSS
Invoke-Command -ComputerName {server name} -ScriptBlock { cd d:\wwwroot\{website};php artisan migrate } -Credential $Cred
This will return the result to your local machine.
I use this in VSTS release deployments all the time.

- 710
- 7
- 14
With Mac terminal
Step 1 sh root@your.ip.address e.g 181.6.41.221
Step 2 Enter your password
Step 3 cd /home/admin/web/yourdomain.com/public_html
Step 4 Laravel command: "php artisan migrate"
Without the "quote"
Ask your host for your IP address and Password if not known by you.

- 1
- 3
The solution to this problem could be running once a php code (on the server) like this:
<?php
// installation.php file
echo exec('php /var/www/laravel-app/artisan migrate:install');
and than you need to visit installation.php
in your browser.
After migration you should remove the installation file, so nobody can execute it again

- 746
- 6
- 18