This guide explains how (my usual) deployment worked and what the different steps are. It is a deployment of a symfony app.

This guide may be out of date, so just use it as a general reference.

Start: Set up env

FCGI_PORT=9100
export SYMFONY_ENV='prod'
export SYMFONY_DEBUG=0
PROJECT_USER='www-data'
touch MAINTENANCE

This also writes a MAINTENANCE file, that puts the application in maintenance mode. In the front controller the existence of this file is checked and all request are directly aborted (with a nice maintenance status page) if it is present.

1) Git pull

ssh-agent bash -c 'ssh-add $(pwd)/.ssh/id_ed25519 ; git pull origin master'

2) Update Dependencies

npm ci
composer install --no-dev --optimize-autoloader --classmap-authoritative --no-interaction

3) Clear PHP OpCode caches

cachetool --fcgi="127.0.0.1:$FCGI_PORT" stat:clear --no-interaction
echo "Stat cache cleared."
cachetool --fcgi="127.0.0.1:$FCGI_PORT" opcache:reset --no-interaction
echo "Opcache cleared."
cachetool --fcgi="127.0.0.1:$FCGI_PORT" opcache:status --no-interaction

4) Symfony cache clear

composer symfony:dump-env -- prod
php bin/console cache:clear --no-warmup --no-interaction

5) Build Assets

Now you would run your node processes, that build the actual asset files.

6) Warm up cache

php bin/console cache:warmup --no-interaction

7) Run migrations

php bin/console doctrine:migrations:migrate --no-interaction

8) Fix permissions

chown -R "$PROJECT_USER:$PROJECT_USER" ./*
chown root:root .deploy* .ssh*
chmod 0700 .deploy* .ssh*

End: Disable maintenance

rm MAINTENANCE

Photo credit: Joao Branco