- CentOS
- Nginx and virtual hosts
- Php fpm & cli, composer
- Node, npm, yarn
- Redis
- Basic security
- Add (multiple) laravel projects (any laravel version) with Zero-Downtime deployment
The scripts are all bash, and kept very simple so you can tweak them to your needs if you want to.
Very easy project deployment by calling the project's puller
script
- bring up a bare centos 8 server somewhere
- ssh as root and run:
yum -y install tar
curl -s -L https://github.com/diyarit/laravel-stack-deployer-centos/archive/refs/tags/1.0.tar.gz | tar -xz
cd laravel-stack-deployer-centos-1.0
./setup_full
That's it. Now you can add laravel apps:
Log in as the default (created) user and run
addzhost <<domain>> <<git repository>> <<initial tag>>
You need access privileges from this server on the repository.
- For github or gitlab, Go to settings->ssh keys and add the contents of
~/.ssh/id_rsa.pub
to a new ssh key.
$ addzhost myapp.example.com git@gitlab.com:myprojects/myapp.git v1.0.3
Now you can browse to myapp.example.com and enjoy your v1.0.3 release (make sure DNS has been set up)
-
adds
/var/www/myapp.example.com
for the laravel app (make sure to configure DNS to the IP of this server) -
creates a nginx config in
/etc/nginx/sites-available
and enables it -
creates
/var/www/myapp.example.com/releases
dir for each inidividual release -
creates
/var/www/myapp.example.com/storage
dir which is linked into each release -
creates (stub)
/var/www/myapp.example.com/.env
file which is linked into each release. Tweak this to your needs. -
generates a
puller
script (in /var/www/myapp.example.com) to pull a version (tag) from the repository and release it -
generates a
rollback
script to roll back to a previous release (any of the releases available in the releases dir) -
uses
puller
to release the initial tag into production. if it fails you can rollback everything and try again.
Usage: $ /var/www/[domain]/puller [tag]
Puller is generated by addzhost on the top project directory: /var/www/[domain]/puller
- Creates a new release in the releases directory and uses
git archive
to download the release - create symbolic links of
/var/www/[domain]/storage
and/var/www/[domain]/.env
into the release - runs
composer install
- You can create a custom post-deployment script in the root of your repository called
after_deploy
with your own artisan/composer/npm commands. a typical after_deploy could look like thisecho "DEPLOY" php artisan migrate --force yarn install yarn run production
- Makes sure everything has the right chown and chmod applied
- swaps the
/var/www/[domain]/current
link towards the new release to make it available with zero downtime
If any of the steps failed puller
aborts before making the release current.
You can call puller
from your local development machine for further integration:
server=[user]@[host]
dir=[deploy directory]
tag=`git describe --abbrev=0 --tags` # latest tag
echo "$dir/puller $tag;" | ssh $server
Usage: rollback [tag]
Rollback is generated by addzhost on the top project directory: /var/www/[domain]/rollback
- swaps the /var/www/[domain]/current link to the old release to make it available with zero downtime
parts are numbered to show the order in which they should be run.
create the default user and allow sudo. Block using passwords and only allow access using your public key for security.
- asks for username
- asks for ssh public key to access this account remotely. Paste the contents of your ~/.ssh/id_rsa.pub
changes the hostname
Add remi and epel repo, updates the system and yum
the basics
secures the root user
firewalls, sshd security and fail2ban - disable password logins and secure it further with fail2ban
color prompts, timezone settings, ntp server, fortune and cowsay (just for fun)
Set up php 74 including fpm and composer
Installs node, npm and yarn
installs mariadb and sets it up for production
- MariaDB asks some questions during install, like the root password to be used
set up nginx for php-fpm and prepare for multiple virtual hosts with the sites-enabled/sites-available pattern
Actually no laravel project is installed, but everything is prepared for adding a zero-downtime-deployment project using the addzhost
command
Optionally install redis
logout as root. At this moment the server is ready for project deployments but none is deployed yet.
- artisan - shortcut to
php artisan
- clear-laravel - clears all possible caches and restores path permissions
- logtail - tails the latest laravel log for a live logview (from any laravel top directory)
- dbRemote2local - copy a remote mysql database to a local database