Anchor is a lightweight, open-source blogging CMS written in PHP. Its source code is hosted on GitHub. This guide provides a step-by-step tutorial for installing Anchor CMS on a CentOS 7 system.
Requirements
Your server must meet the following requirements:
- MySQL 5.6 or greater (MySQL 5.7 recommended)
- PHP 5.6 or greater with these PHP extensions:
curl, mcrypt, gd, mbstring, pdo_mysql
orpdo_sqlite
- Apache or Nginx (Nginx used in this tutorial)
Prerequisites
- CentOS 7 operating system
- A non-root user with
sudo
privileges
Initial Steps
First, verify your CentOS system version:
cat /etc/centos-release # CentOS Linux release 7.5.1804 (Core)
Set the timezone:
timedatectl list-timezones sudo timedatectl set-timezone 'Region/City'
Update your operating system’s packages:
sudo yum update -y
Install useful packages if they are not already installed:
sudo yum install -y vim wget curl git unzip bash-completion
Step 1 – Install PHP and Necessary PHP Extensions
Since the default CentOS repositories have an older version of PHP, add the Webtatic repository to get a newer version.
Setup the Webtatic YUM repo:
sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Install PHP along with the required extensions:
sudo yum install -y php72w php72w-cli php72w-fpm php72w-common php72w-mbstring php72w-curl php72w-mysql php72w-sqlite3 php72w-gd php72w-mcrypt php72w-dom
Verify PHP version:
php --version
# PHP 7.2.12 (cli) (built: Nov 11 2018 14:54:16) ( NTS )
# Copyright (c) 1997-2018 The PHP Group
# Zend Engine v3.2.0, Copyright (c) 1998-2018 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 Anchor CMS
Anchor supports MySQL/MariaDB and SQLite databases. Use the official MariaDB repository for an up-to-date version.
Create the MariaDB YUM repository:
sudo vim /etc/yum.repos.d/MariaDB.repo
Paste the following into the file:
# MariaDB 10.2 CentOS repository list - created 2017-12-11 23:19 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[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
Verify the MariaDB version:
mysql --version # mysql Ver 15.1 Distrib 10.2.19-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 the MySQL secure installation script:
sudo mysql_secure_installation
Configure MariaDB with the steps below:
Enter current password for root (enter for none): Set root password? [Y/n]: Y 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 shell:
mysql -u root -p # Enter password
Create a MariaDB database and user for Anchor CMS:
CREATE DATABASE dbname; GRANT ALL ON dbname.* TO 'username' IDENTIFIED BY 'password'; FLUSH PRIVILEGES;
Exit MariaDB shell:
quit
Step 3 – Install and Configure Nginx
Install Nginx:
sudo yum install -y nginx
Verify Nginx version:
nginx -v # nginx version: nginx/1.12.2
Start and enable Nginx service:
sudo systemctl start nginx.service sudo systemctl enable nginx.service
Create the Nginx configuration file for Anchor:
sudo vim /etc/nginx/conf.d/anchor.conf
Add the following configuration to the file:
server {
listen 80;
server_name example.com;
root /var/www/anchor;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Test Nginx configuration:
sudo nginx -t
Reload Nginx:
sudo systemctl reload nginx.service
Step 4 – Install Composer
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') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { 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
Verify Composer version:
composer --version # Composer version 1.8.0 2018-12-03 10:31:16
Step 5 – Install Anchor CMS
Create a document root directory:
sudo mkdir -p /var/www/anchor
Change ownership of the directory to your user:
sudo chown -R [your_user]:[your_user] /var/www/anchor
Navigate to the document root:
cd /var/www/anchor
Download Anchor CMS using Composer:
composer create-project anchorcms/anchor-cms .
Change ownership of the /var/www/anchor
directory to nginx
:
sudo chown -R nginx:nginx /var/www/anchor
Create the directory /var/lib/php/session
and set ownership to nginx
:
sudo mkdir -p /var/lib/php/session && sudo chown -R nginx:nginx /var/lib/php
Update PHP-FPM user and group settings to nginx
by editing the configuration file:
sudo vim /etc/php-fpm.d/www.conf # user = nginx # group = nginx
Restart the PHP-FPM service:
sudo systemctl restart php-fpm.service
Step 6 – Complete the Anchor CMS Setup
Open your web browser and visit http://example.com. You should see the installation page:
Click “Run the installer” to start the web installer. Then, configure language and timezone:
Select your settings and click “Next Step” to proceed to the database configuration:
Enter database details and click “Next Step.” Proceed to site metadata configuration page:
Set your site name and description, or leave defaults. Move on to creating your first account:
After creating the account, click “Complete” to finish the installation. For security, remove the install
folder:
sudo rm -rf /var/www/anchor/install
Links
FAQ
- What version of PHP is required for Anchor CMS?
- Anchor CMS requires PHP 5.6 or greater.
- Can I use Apache web server instead of Nginx?
- Yes, although this tutorial demonstrates installation with Nginx, Anchor CMS is compatible with Apache as well.
- How do I secure my MariaDB installation?
- After installation, run the
mysql_secure_installation
script to enhance security. - What should I do if I encounter permission issues?
- Ensure that the ownership settings of your directories and files are correctly assigned to Nginx or the relevant user.