There is a new version of this tutorial available for CentOS 8.

How to Install Laravel based PyroCMS with Nginx on CentOS 7

PyroCMS is a powerful modular CMS and development platform built with Laravel 5, which allows you to build better Laravel websites and applications faster.

In this tutorial, we will walk you through the PyroCMS installation process on a CentOS 7 operating system by using NGINX as a web server, MariaDB as a database server, and optionally you can secure the transport layer by using acme.sh client and Let's Encrypt certificate authority to add SSL support.

Requirements

To install PyroCMS, make sure your system meets the following requirements:

  • At least 1GB of RAM or Swap configured
  • PHP version 7.0 or greater with PDO, cURL, SQLite, OpenSSL, Mbstring, Fileinfo, Tokenizer, GD PHP extensions.
  • MariaDB
  • NGINX

Prerequisites

  • A system running CentOS 7 system.
  • A non-root user with sudo privileges.

Initial steps

Check your CentOS version:

cat /etc/centos-release
# CentOS Linux release 7.6.1810 (Core)

Set up the timezone:

timedatectl list-timezones
sudo timedatectl set-timezone 'Region/City'

Update your operating system packages (software). This is an important first step because it ensures you have the latest updates and security fixes for your operating system's default software packages:

sudo yum update -y

Install some essential packages that are necessary for basic administration of the CentOS operating system:

sudo yum install -y curl wget vim git unzip socat bash-completion epel-release

Step 1 - Install PHP and necessary PHP extensions

Setup the Webtatic YUM repo:

sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

Download and install PHP and required PHP extensions:

sudo yum install -y php72w php72w-cli php72w-fpm php72w-mysqlnd php72w-curl php72w-sqlite3 php72w-mbstring php72w-gd php72w-xml

To show PHP compiled in modules, you can run:

php -m

ctype
curl
exif
fileinfo
. . .
. . .

Check the PHP version:

php --version
# PHP 7.2.19 (cli) (built: Jan 12 2019 12:47:33) ( NTS )
# Copyright (c) 1997-2018 The PHP Group
# Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
# with Zend OPcache v7.2.14, Copyright (c) 1999-2018, by Zend Technologies

Start and enable PHP-FPM service:

sudo systemctl start php-fpm.service
sudo systemctl enable php-fpm.service

Step 2 - Install MariaDB and create a database for PyroCMS

Install MariaDB from the official MariaDB repository. Create a repository first:

sudo vim /etc/yum.repos.d/MariaDB.repo

Copy and paste following fragment to the /etc/yum.repos.d/MariaDB.repo file:

[mariadb]
name = MariaDB
baseurl = https://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Install MariaDB:

sudo yum install -y MariaDB-server MariaDB-client

Check the MariaDB version:

mysql --version
# mysql Ver 15.1 Distrib 10.2.13-MariaDB, for Linux (x86_64) using readline 5.1

Start and enable MariaDB service:

sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Run mysql_secure installation script to improve MariaDB security and set the password for MariaDB root user:

sudo mysql_secure_installation

Answer each of the questions:

Enter current password for root (enter for none): Press Enter
Set root password? [Y/n] Y
New password: your_secure_password
Re-enter new password: your_secure_password
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Log into MariaDB as the root user:

sudo mysql -u root -p
# Enter password

Create a MariaDB database and user that you will use for your installation of PyroCMS, and remember the credentials:

CREATE DATABASE dbname;
GRANT ALL ON dbname.* TO 'username' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;

Replace dbname and username with appropriate names for your setup. Replace password with a strong password.

Exit from MariaDB shell:

quit

Step 3 - Install Acme.sh client and obtain Let's Encrypt certificate (optional)

Securing your website with HTTPS is not necessary, but it is a good practice to secure your site traffic. In order to obtain an SSL certificate from Let's Encrypt we will use Acme.sh client. Acme.sh is a pure UNIX shell software for obtaining SSL certificates from Let's Encrypt with zero dependencies. 

Download and install acme.sh:

sudo su - root
git clone https://github.com/Neilpang/acme.sh.git
cd acme.sh
./acme.sh --install --accountemail [email protected]
source ~/.bashrc
cd ~

Check acme.sh version:

acme.sh --version
# v2.8.1

Obtain RSA and ECC/ECDSA certificates for your domain/hostname:

# RSA 2048
acme.sh --issue --standalone -d example.com --keylength 2048
# ECDSA
acme.sh --issue --standalone -d example.com --keylength ec-256

If you want fake certificates for testing you can add --staging flag to the above commands.

To list your issued certs you can run:

acme.sh --list

Create a directory to store your certs. We will use /etc/letsencrypt directory.

mkdir -p /etc/letsencrypt/example.com
sudo mkdir -p /etc/letsencrypt/example.com_ecc

Install/copy certificates to /etc/letsencrypt directory.

# RSA
acme.sh --install-cert -d example.com \
--cert-file /etc/letsencrypt/example.com/cert.pem \
--key-file /etc/letsencrypt/example.com/private.key \
--fullchain-file /etc/letsencrypt/example.com/fullchain.pem \
--reloadcmd "sudo systemctl reload nginx.service"

# ECC/ECDSA
acme.sh --install-cert -d example.com --ecc \
--cert-file /etc/letsencrypt/example.com_ecc/cert.pem \
--key-file /etc/letsencrypt/example.com_ecc/private.key \
--fullchain-file /etc/letsencrypt/example.com_ecc/fullchain.pem \
--reloadcmd "sudo systemctl reload nginx.service"

After running the above commands, your certificates and keys will be in:

  • For RSA: /etc/letsencrypt/example.com directory.
  • For ECC/ECDSA: /etc/letsencrypt/example.com_ecc directory.

All the certificates will be automatically renewed every 60 days.

After obtaining certs, exit from root user and return back to normal sudo user:

exit

Step 4 - Install NGINX and configure NGINX for PyroCMS

Install the NGINX web server:

sudo yum install -y nginx

Check the NGINX version:

nginx -v

Start and enable Nginx service:

sudo systemctl start nginx.service
sudo systemctl enable nginx.service

Configure NGINX for PyroCMS by running:

sudo vim /etc/nginx/conf.d/pyro.conf

And populate the file with the following configuration:

server {
  listen 80;
  listen 443 ssl;
server_name example.com;
index index.php index.html;
root /var/www/pyro/public;

ssl_certificate /etc/letsencrypt/status.example.com/fullchain.cer;
ssl_certificate_key /etc/letsencrypt/status.example.com/status.example.com.key;
ssl_certificate /etc/letsencrypt/status.example.com_ecc/fullchain.cer;
ssl_certificate_key /etc/letsencrypt/status.example.com_ecc/status.example.com.key;

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

location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
}
}

Check NGINX configuration for syntax errors:

sudo nginx -t

Reload NGINX service:

sudo systemctl reload nginx.service

Step 5 - Install Composer

Install Composer, the PHP dependency manager globally:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php -r "if (hash_file('sha384', 'composer-setup.php') === 'a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php

php -r "unlink('composer-setup.php');"

sudo mv composer.phar /usr/local/bin/composer

Check Composer version:

composer --version
# Composer version 1.9.0 2019-08-02 10:52:10

Step 6 - Install PyroCMS

Create a document root directory where PyroCMS should reside in:

sudo mkdir -p /var/www/pyro

Change ownership of the /var/www/pyro directory to your_username that you should have created before and you should be logged in as this user. 

sudo chown -R your_username:your_username /var/www/pyro

NOTE: Don't forget to replace your_username with the name that you have chosen.

Navigate to document root:

cd /var/www/pyro

Download the latest stable release of PyroCMS via composer:

composer create-project pyrocms/pyrocms .

Change ownership of the /var/www/pyro directory to www-data.

sudo chown -R nginx:nginx /var/www/pyro

Run sudo vim /etc/php-fpm.d/www.conf and set the user and group to nginx. Initially, they will be set to apache. Run:

sudo vim /etc/php-fpm.d/www.conf

And set user and group to nginx, like below:

user = nginx
group = nginx

And finally, restart PHP-FPM service for these changes to take effect:

sudo systemctl restart php-fpm.service

Step 7 - Complete the PyroCMS setup

Access your site in a web browser via domain name or IP address and follow the PyroCMS web installation wizard.

Accept PyroCMS license

After you have filled all the required information, your PyroCMS installation is complete.

Links

Share this page:

0 Comment(s)