نحوه نصب Anchor CMS در CentOS 7

Anchor is a lightweight open source blog CMS written in PHP. Anchor’s source code is hosted on GitHub. This tutorial will show you how to install Anchor CMS on a CentOS 7 system.

Requirements

Make sure your server meets the following requirements.

  • MySQL 5.6 or greater (MySQL 5.7 recommended)
  • PHP 5.6 or greater with the following PHP extensions: (curl, mcrypt, gd, mbstring, pdo_mysql or pdo_sqlite)
  • Apache or Nginx. In this tutorial we will use Nginx.
  • CentOS 7 operating system.
  • A non-root user with sudo privileges.

Initial steps

Check your CentOS system version:

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

Set up the timezone:

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

Update your operating system’s packages:

sudo yum update -y

Install some 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

Anchor CMS requires PHP version 5.6 or greater. Default CentOS repositories contain an older version of PHP, and thus we will need to set up a third-party repository to install a newer PHP version. We will use Webtatic repository.

Setup the Webtatic YUM repo:

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

Install PHP, as well as the necessary PHP 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

Check the 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. Default CentOS repository contains an unsupported version of MariaDB. Because of that, we will use the official MariaDB repository that contains a newer version of MariaDB.

Create MariaDB YUM repository for CentOS:

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

Copy and paste the following text into it:

# 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

After the file is in place, install MariaDB by running:

sudo yum install -y MariaDB-server MariaDB-client

Check 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 mysql_secure installation script to improve MariaDB security and set the password for MariaDB root user:

sudo mysql_secure_installation

Answer all the questions as shown 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 as the user root:

mysql -u root -p
# Enter password

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

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

Exit from MariaDB shell:

quit

Step 3 – Install and configure Nginx

Install Nginx web server:

sudo yum install -y nginx

Check the 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

Run sudo vim /etc/nginx/conf.d/anchor.conf and populate the file with the following configuration:

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 – Download and install Composer

To successfully install Anchor, we will need to install Composer, the dependency manager for PHP applications:

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

Check the Composer version.

composer --version
# Composer version 1.8.0 2018-12-03 10:31:16

Step 5 – Download and install Anchor CMS

Create a document root directory:

sudo mkdir -p /var/www/anchor

Change ownership of the /var/www/limesurvey directory to [jour_user]:

sudo chown -R [your_user]:[your_user] /var/www/anchor

Navigate to document root:

cd /var/www/anchor

Download the latest release of Anchor CMS by 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

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

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 type the URL “http://example.com”. You will be redirected to the following page:

Anchor CMS web installer

Click on the “Run the installer” button, to initiate Anchor CMS web installer. After, language and timezone page should appear:

Select Language and Time zone

Select the settings that you want and click on the “Next Step” button to proceed to the database configuration page:

Database settings

Enter your database details, and click on the “Next Step” button to proceed to site metadata configuration page:

Site Metadata

You can set site name or site description here, or leave the defaults and change it later via Anchor backend interface. Click on the “Next Step” button for the next step which is setting your first account:

Create admin account

After setting up your first account, click on the “Complete” button to finish the installation process.

Once you have completed the install, make sure to delete install folder for security purposes.

sudo rm -rf /var/www/anchor/install

نوشته های مشابه