Skip to content

diyarit/laravel-stack-deployer-centos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple Centos Laravel stack for Zero-Downtime deployment

Installs a fresh server with

  • 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

how to install

  • 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:

Add a new laravel app with Zero Downtime Deployment

Log in as the default (created) user and run

    addzhost <<domain>> <<git repository>> <<initial tag>>

Note:

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.

Example:

$ 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.

puller

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 this
    echo "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

rollback (generated by addzhost)

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

Overview of individual installation parts run by setup_full

parts are numbered to show the order in which they should be run.

01 user create

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

02 set hostname

changes the hostname

03 repos and yums

Add remi and epel repo, updates the system and yum the basics

04 root password

secures the root user

05 security

firewalls, sshd security and fail2ban - disable password logins and secure it further with fail2ban

06 global settings

color prompts, timezone settings, ntp server, fortune and cowsay (just for fun)

07 php

Set up php 74 including fpm and composer

08 node and npm

Installs node, npm and yarn

09 mysql / mariadb

installs mariadb and sets it up for production

  • MariaDB asks some questions during install, like the root password to be used

10 nginx

set up nginx for php-fpm and prepare for multiple virtual hosts with the sites-enabled/sites-available pattern

11 laravel

Actually no laravel project is installed, but everything is prepared for adding a zero-downtime-deployment project using the addzhost command

12 redis

Optionally install redis

Finally

logout as root. At this moment the server is ready for project deployments but none is deployed yet.

extra utilities in ~/bin

  • 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

About

simple Centos Laravel stack for Zero-Downtime deployment

Resources

Stars

Watchers

Forks

Packages

No packages published