You can run artisan commands from a route/controller by using `
Artisan::call('command', [parameters])`.
This is what I use to run the '
artisan migrate', '
artisan optimize', '
artisan config:cache', and '
artisan route:cache' commands on the server. (
source: https://stackoverflow.com/questions/37236206/run-artisan-command-in-laravel-5)
For Composer Install/Update, I simply do this before I upload it to the server. You would want to do '
composer install --no-dev' to make sure you aren't putting dev-only files on the server. When you go to upload it to the server, make sure you are including the '
vendor' folder.
To help speed up the process of uploading the site to the server, I just make a batch/bash file with all the commands I need to do, adding on to that a zip command to zip all the folders and files I would need to upload to the server, and then a command reverting back to the files before I ran the shell script (using `
git checkout -- .`). I then simply upload the zip file from the online cpanel file explorer and unzip it from there in the correct directory, but only after I have already deleted the old files and folders (except for the `.env` file). You could also probably have an ftp command in the shell file to automatically upload the zip file onto the server - but you would probably still need to unzip it from the file manager on cpanel.
This is the code I use for the bash script:
Code:
#!/bin/bash
# Distribute website
# make sure all the cache is cleared
php artisan route:clear
php artisan config:clear
php artisan cache:clear
php artisan view:clear
# use production files only
npm run production
composer install --no-dev
# zip required files and folders for server
zip -r ./updates/update$1.zip ./app/ ./bootstrap/ ./config/ ./database/ ./public/ ./resources/ ./routes/ ./storage/ ./vendor/ ./artisan ./composer.json ./composer.lock ./package.json ./phpunit.xml ./server.php ./webpack.mix.js ./yarn.lock
# add zip file to git and revert back to dev files
git add ./update$1.zip
git commit -m "add update zip"
git checkout -- .
composer install
I would run this command passing in the version number as an argument: `
./dist.sh 1.5`. Also, you may need to add more directories or files that are being zipped up in the shell script.
Hope this helps!