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.
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 [email protected] << 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.
The preferred way to do this:
- ssh into your server (for example, username root & server ip 1.1.1.1:
ssh [email protected]
). - 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!
php artisan schedule:run
–
Stenotypy 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.
With Mac terminal
Step 1 sh [email protected] 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.
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
© 2022 - 2024 — McMap. All rights reserved.