7

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Youssef Had
  • 137
  • 1
  • 2
  • 6
  • 1
    Is 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 Answers5

10

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.

Matkey
  • 378
  • 4
  • 17
0

The preferred way to do this:

  1. ssh into your server (for example, username root & server ip 1.1.1.1: ssh root@1.1.1.1).
  2. go to your project folder (for example: cd /var/....)
  3. 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!

Robin Dirksen
  • 3,322
  • 25
  • 40
0

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.

MiloTheGreat
  • 710
  • 7
  • 14
0

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.

-5

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

David
  • 746
  • 6
  • 18