Installing Fork CMS on CentOS 7

Updated on November 21, 2023
Installing Fork CMS on CentOS 7 header image

Fork is an open source CMS written in PHP. Fork's source code is hosted on GitHub. This guide will show you how to install Fork CMS on a fresh CentOS 7.4 Vultr instance.

Requirements

  • PHP 7.1 or higher.
  • MySQL 5.0 or higher.
  • NGINX or Apache 2.0 with .htaccess, mod rewrite, mod expires (optional but recommended) and mod deflate (optional) enabled.

Before you Begin

Check the CentOS version.

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

Create a new non-root user account with sudo access and switch to it.

useradd -c "John Doe" johndoe && passwd johndoe
usermod -aG wheel johndoe
su - johndoe

NOTE: Replace johndoe with your username.

Set up the timezone.

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

Ensure that your system is up to date.

sudo yum update -y

Install required and useful packages.

sudo yum install -y wget vim unzip bash-completion

Disable SELinux.

sudo setenforce 0

Step 1 - Install PHP, required PHP extensions, NGINX and MySQL

CentOS does not provide the latest PHP version in its default software repositories. We’ll need to add a Webtatic YUM repo. For how to do that you can follow this Vultr guide.

Download and install PHP 7.2 and required PHP extensions.

sudo yum install -y php72w-cli php72w-fpm php72w-common php72w-mbstring php72w-gd php72w-intl php72w-mysql php72w-xml

Check the PHP version.

php --version
PHP 7.2.2 (cli) (built: Feb  4 2018 10:14:07) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Install NGINX.

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

# Copy/paste this to the /etc/yum.repos.d/nginx_mainline.repo file

[nginx]
name=nginx repo
baseurl=https://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=1
enabled=1

wget https://nginx.org/keys/nginx_signing.key
sudo rpm --import nginx_signing.key
rm nginx_signing.key

sudo yum install -y nginx

Check the NGINX version.

sudo nginx -v

Start and enable NGINX.

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

Install MariaDB.

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

# Copy/paste this 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

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.

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

Run the mysql_secure_installation script to improve the security of your MariaDB installation.

sudo mysql_secure_installation

Log in to MariaDB as the root user.

mysql -u root -p
# Enter password:

Create a new MariaDB database and user, and remember the credentials.

create database dbname;
grant all on dbname.* to 'username' identified by 'password';

Exit MySQL.

exit

Step 2 - Configure NGINX

Run sudo vi /etc/nginx/conf.d/fork.conf and populate it with the following.

server {
    listen 80;

    root /var/www/fork;
    index index.php index.html;

    server_name example.com;

    location / {
        # Checks whether the requested url exists as a file $uri or directory $uri/ in the root, else redirect to /index.php.
        try_files $uri $uri/ @redirects;
    }

    location @redirects {
        rewrite ^ /index.php;
    }

    location ~ \.php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000; # Make sure to doublecheck this!
        fastcgi_index index.php;
        fastcgi_read_timeout 60;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    # Don't pollute the logs with common requests
    location = /robots.txt  { access_log off; log_not_found off; }
    location = /favicon.ico { access_log off; log_not_found off; }

    # As Fork CMS has the app_root as doc_root, we need to restrict access to a few things for security purposes!
    location ~* ^/(composer\..*|vendor\/.*|Procfile$|\.git\/.*|src\/Console.*|.*\.gitignore|\.editorconfig|\.travis.yml|autoload\.php|bower\.json|phpunit\.xml\.dist|.*\.md|app\/logs\/.*|app\/config\/.*|src\/Frontend\/Cache\/CompiledTemplates.*|src\/Frontend\/Cache\/Locale\/.*\.php|src\/Frontend\/Cache\/Navigation\/.*\.php|src\/Frontend\/Cache\/Search\/.*|src\/Backend\/Cache\/CompiledTemplates\/.*|src\/Backend\/Cache\/Locale\/.*\.php)$ {
        deny all;
        access_log off;
        log_not_found off;
    }

    # Deny access to dot-files.
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }
}

A summary of the changes that you will be making are as follows.

  • Change the value of the root directive to point to the correct location of your website, such as /var/www/fork.
  • Change the value of the server_name directive to point to your domain name or IP address.
  • Make sure you check if fastcgi_pass is set correctly.

Test the NGINX configuration.

sudo nginx -t

Reload NGINX.

sudo systemctl reload nginx.service

Step 3 - Download and install Composer

Download Composer dependencies.

sudo yum install -y curl git unzip

Download and install Composer, the dependency manager for PHP.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { 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 the Composer version.

composer --version
# Composer version 1.6.3 2018-01-31 16:28:17

Step 4 - Download and install Fork CMS via Composer

Create a document root directory.

sudo mkdir -p /var/www/fork

Change ownership of the /var/www/fork directory to johndoe.

sudo chown -R johndoe:johndoe /var/www/fork

Download the latest stable release of Fork CMS from the command line.

cd /var/www/fork
composer create-project forkcms/forkcms .

Change ownership of the /var/www/fork directory to nginx.

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

Run sudo vim /etc/php-fpm.d/www.conf and set user and group to nginx.

sudo vim /etc/php-fpm.d/www.conf
# user = nginx
# group = nginx

Restart php-fpm.service.

sudo systemctl restart php-fpm.service

Edit the app/config/parameters.yml.dist file and set database information.

sudo vim /var/www/fork/app/config/parameters_install.yml

Create /var/lib/php/session directory and change its ownership to user nginx.

sudo mkdir -p /var/lib/php/session
sudo chown -R nginx:nginx /var/lib/php/session

Finally, using your preferred web browser, open your site and follow the Fork CMS installer. After following the installer you should have Fork up and running. To access the Fork admin area just append /private to your site URL.