'Pulling updates from Git on running project
I have a laravel app deployed on an apache2 server in an ubuntu VM. It took an awful lot of time to set up, but I would like to make some more changes to the website, e.g. now I added a footer.
Is it safe / possible to just pull
in the repository so the updates get installed on the project and then restart apache?
I did google but haven't found anything specific, hence why I am asking here.
Since it took so long to setup I am scared that I break something.
Solution 1:[1]
Yes, you can pull your code and run these commands to remove your old version caches.
php artisan view:clear
php artisan route:clear
php artisan cache:clear
php artisan view:cache
php artisan route:cache
you didn't need to restart your apache service.
Solution 2:[2]
Make sure that the file permissions and ownership is correct. If the files are owned by www-data, and you git pull with your own user, and a new file is created, the new file will be owned by your own user instead of www-data. It's possible to create a git hook that will chown
file files for you, but you might as well just do it in your own script after pulling the changes (e.g. chown -R www-data
). You can also use sudo
to run the git operations as the www-data user, e.g. sudo -u www-data git pull --ff-only
.
Additionally, make sure you use git pull --ff-only
. --ff-only
will refuse to merge if for some reason the repository on the server and in the upstream differ due to conflicts (e.g. a force push). This will prevent git pull from creating merge conflict markers in files, which will probably break your code with syntax errors.
It may be safer to move your git repository into a different folder, do the git operations there, then fix the file permissions etc. and then rsync or otherwise overwrite the files in the directory which Apache is using.
As for Laravel, you'll want to follow the deployment steps outlined in the documentation.
composer install --no-interaction --optimize-autoloader --no-dev
php artisan config:cache
php artisan route:cache
php artisan view:cache
The :cache
commands clear existing caches and re-cache the configuration files, route lists, and compiled Blade templates. If you're previously used the cache commands, you'll need to run these or your new code changes related to configs, routes and views won't take effect. If you haven't previously used these, you probably won't need to use them.
You may also need to run php artisan migrate
if you have new database migrations. You may also need to run npm install
and npm run prod
or other npm related build commands, if you're using Laravel Mix, for example.
After this, you'll want to finally reload your Apache2 instance (sudo service apache2 reload
) to clear the Apache2 opcache (if you are using opcache).
Finally, if you're using queues, you'll need to restart your queue workers. The procedure here differs depending on what you're using to keep the workers alive. For example, if you use supervisor
as documented here, you might do sudo supervisorctl restart laravel-worker:*
. Do this after all of the previous operations, so that the workers are running on the latest code.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | kousha ghodsizad |
Solution 2 |