Install CachetHQ on CentOS 7

In this tutorial, we will show you how to install CachetHQ on a CentOS 7.1 VPS with MariaDB, PHP-FPM 5.6, and Nginx. CachetHQ is an open source system built on top of Laravel 5. This tutorial should work on other Linux VPS systems, but was tested and written for CentOS 7 VPS. Login to your VPS via SSH

ssh [email protected]

Update the system and install the required packages

[furious]$ sudo yum -y upgrade
[furious]$ sudo yum install git curl

Install MariaDB

MariaDB 5.5 ships by default with the CentOS 7 repository, to install it, simply run:

[furious]$ sudo yum install mariadb-server

To start the MariaDB service and enable it to autostart, run the following commands:

[furious]$ sudo systemctl start mariadb.service
[furious]$ sudo systemctl enable mariadb.service

Run the following command to secure your installation:

[furious]$ sudo mysql_secure_installation

Next, we need to create a database for our CachetHQ instance.

[furious]$ mysql -uroot -p
MariaDB [(none)]> CREATE DATABASE cachet;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON cachet.* TO 'cachetuser'@'localhost' IDENTIFIED BY 'cachetuser_passwd';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> q

Install PHP and Nginx

Nginx is not available in the default CentOS 7 repository, so we will use the official Nginx repository:

[furious]$ sudo rpm -UVh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
[furious]$ sudo yum -y install nginx

Enable EPEL repository:

[furious]$ sudo yum install epel-release

CentOS 7 ships with PHP version 5.4, in order to be able to install the latest PHP version, version 5.6 we will include the Webtatic repository:

[furious]$ sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

Install PHP 5.6 and all required extensions:

[furious]$ sudo yum install php56w-cli php56w-process php56w-mcrypt php56w-mbstring php56w-common php56w-fpm php56w-xml php56w-opcache php56w-pecl-apcu php56w-pdo php56w-mysqlnd

Install Composer

Composer is a dependency manager for PHP with which you can install packages. Composer will pull in all the required libraries and dependencies you need for your project.

[furious]$ curl -sS https://getcomposer.org/installer | php
[furious]$ sudo mv composer.phar /usr/local/bin/composer

Install Gulp and Bower node

We need to install Gulp and Bower.

[furious]$ sudo yum install -y nodejs npm
[furious]$ sudo npm install -g bower
[furious]$ sudo npm install -g gulp

Install CachetHQ

Create a root directory for your application.

[furious]$ mkdir -p ~/CachetHQ

Clone the project repository from GitHub:

[furious]$ git clone https://github.com/cachethq/Cachet.git ~/CachetHQ
[furious]$ cd  ~/CachetHQ

Install all dependencies:

[furious]$ composer install --no-dev -o

Copy file .env.example .env

[furious]$ cp .env.example .env

Generate and install an application key:

[furious]$ php artisan key:generate

and edit the corresponding values:

[furious]$ vim .env
APP_ENV=production
APP_DEBUG=false
APP_URL=http://localhost
APP_KEY=SomeRandomString

DB_DRIVER=mysql
DB_HOST=localhost
DB_DATABASE=cachet
DB_USERNAME=cachetuser
DB_PASSWORD=cachetuser_passwd

CACHE_DRIVER=apc
SESSION_DRIVER=file
QUEUE_DRIVER=sync

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null

Starting the database migration and populating the database with sample data:

[furious]$ php artisan migrate
[furious]$ php artisan db:seed

Post assets:

[furious]$ npm install
[furious]$ bower install
[furious]$ gulp

Setting up Nginx and PHP

Create a new PHP-FPM pool for your user:

[furious]$ sudo vim /etc/php-fpm.d/your_users.conf
[your_user]
user = ваш_пользователь
group = ваш_пользователь
listen = /var/run/php-fpm/your_user.sock  
listen.owner = ваш_пароль
listen.group = ваш_пользователь 
listen.mode = 0666  
pm = ondemand  
pm.max_children = 5  
pm.process_idle_timeout = 10s;  
pm.max_requests = 200  
chdir = /

Remember to change your_user to your username.

Restart PHP-FPM

[furious]$ sudo systemctl restart php-fpm.service

Generating SSL Certificate:

[furious]$ sudo mkdir -p /etc/nginx/ssl
[furious]$ cd /etc/nginx/ssl
[furious]$ sudo openssl genrsa -des3 -passout pass:x -out cachet.pass.key 2048
[furious]$ sudo openssl rsa -passin pass:x -in cachet.pass.key -out cachet.key
[furious]$ sudo rm cachet.pass.key
[furious]$ sudo openssl req -new -key cachet.key -out cachet.csr
[furious]$ sudo openssl x509 -req -days 365 -in cachet.csr -signkey cachet.key -out cachet.crt

Then create a new Nginx server block:

[furious]$ sudo vim /etc/nginx/sites-available/CachetHQ.conf
server {
    listen      443 default;
    server_name CachetHQ;

    ssl on;
    ssl_certificate     /etc/nginx/ssl/cachet.crt;
    ssl_certificate_key /etc/nginx/ssl/cachet.key;
    ssl_session_timeout 5m;

    ssl_ciphers               'AES128+EECDH:AES128+EDH:!aNULL';
    ssl_protocols              TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    root /home/your_user/CachetHQ/public;

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log  /var/log/nginx/cachet.access.log;
    error_log   /var/log/nginx/cachet.error.log;

    sendfile off;

    location ~ .php$ {
        fastcgi_split_path_info ^(.+.php)(/.+)$;
        fastcgi_pass unix:/var/run/php-fpm/your_user.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }

    location ~ /.ht {
        deny all;
    }
}

server {
    listen      80;
    server_name CachetHQ;

    add_header Strict-Transport-Security max-age=2592000;
    rewrite ^ https://$server_name$request_uri? permanent;
}

Don’t forget to change your_user to your username.

Finally, restart Nginx:

[furious]$ sudo systemctl restart nginx.service

That’s all. You have successfully installed CachetHQ on your Centos 7 VPS. If you don’t change the default username and password, you can login with ‘[email protected]’ and ‘test123’.

For more information on CachetHQ, please refer to the website CachetHQ

Sidebar