How to Install MODX CMS and Nginx on CentOS 7
MODX is a free and open source content management system written in PHP. It uses MySQL or MariaDB to store its database. MODX is designed for the business in which maintaining a website is critical. It provides flexibility to developers to create a website by choosing their own design and structure. It also features a WYSIWYG
editor for non-technical users in the business. Apart from being flexible, it can be optimized for blazing fast speed.
This tutorial was written for MODX 2.6.1 and may also work for newer versions.
Prerequisites
- A Vultr CentOS 7 server instance.
- A sudo user.
- A domain name pointed towards the instance.
For this tutorial, we will use modx.example.com
as the domain name pointed towards the Vultr instance. Please make sure to replace all occurrences of the example domain name with the actual one.
Update your base system using the guide How to Update CentOS 7. Once your system has been updated, proceed to install the dependencies.
Install Nginx
Nginx is a production web server to run web applications. Install Nginx.
sudo yum -y install epel-release
sudo yum -y install nginx
Start Nginx and enable it to automatically run at boot time.
sudo systemctl start nginx
sudo systemctl enable nginx
Install PHP 7.2
MODX supports all PHP versions above 5.4. We will install the latest available version of PHP. Using PHP 7.2 will ensure maximum speed and security. Add and enable the Remi repository as PHP version 7.2 is not available in default YUM
repository.
sudo rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum -y install yum-utils
sudo yum-config-manager --enable remi-php72
Install PHP version 7.2 along with the modules required by MODX.
sudo yum -y install php php-zlib php-mysqli php-curl php-json php-cli php-pear php-gd php-openssl php-xml php-mbstring php-fpm ImageMagick
Edit the loaded PHP configuration file.
sudo nano /etc/php.ini
Find the following line. Uncomment it and set the appropriate timezone.
date.timezone = Asia/Kolkata
;Replace "Asia/Kolkata" with your appropriate time zone
Also, set an appropriate memory limit on the following line. Setting it to -1
will give unlimited available memory to a script.
memory_limit = -1
Next, find the following line and set its value to 0
after uncommenting it.
cgi.fix_pathinfo=0
Save the file and open the php-fpm
configuration file.
sudo nano /etc/php-fpm.d/www.conf
Find the existing listen = 127.0.0.1:9000
, comment it and append a new line as shown below.
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php-fpm.sock
Also, change the users as shown below.
listen.owner = nginx
listen.group = nginx
...
user = nginx
group = nginx
Save the file and start php-fpm
and enable it to automatically start at boot time.
sudo systemctl restart php-fpm
sudo systemctl enable php-fpm
Provide writing permissions to the session directory.
sudo mkdir /var/lib/php/session
sudo chmod -R 777 /var/lib/php/session
Now, proceed to the installation of MariaDB.
Install MariaDB
MariaDB is a fork of MySQL. Add the MariaDB repository to your system. The default YUM
repository contains an older version of MariaDB.
echo "[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1" | sudo tee /etc/yum.repos.d/mariadb.repo
Install MariaDB.
sudo yum -y install mariadb mariadb-server
Start MariaDB and enable it to automatically start at boot time.
sudo systemctl start mariadb
sudo systemctl enable mariadb
Before configuring the database, you will need to secure MariaDB.
sudo mysql_secure_installation
You will be asked for the current MariaDB root password. By default, there is no root password in a fresh MariaDB installation. Press the "Enter
" key to proceed. Set a strong password for the root
user of your MariaDB server and answer "Y
" to all of the other questions that are asked. The questions asked are self-explanatory.
Log into the MySQL shell as root.
mysql -u root -p
Provide the password for the MariaDB root user to log in.
Run the following queries to create a database and a database user for the MODX installation.
CREATE DATABASE modx_data CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'modx_user'@'localhost' IDENTIFIED BY 'StrongPassword';
GRANT ALL PRIVILEGES ON modx_data.* TO 'modx_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
You can replace the database name modx_data
and username modx_user
according to your choice. Please make sure to change StrongPassword
to a very strong password.
Install MODX
Download the MODX zip archive.
wget https://modx.com/download/direct?id=modx-2.6.1-pl.zip -O modx.zip
You can always look for the link to the latest version of the application on the MODX download page.
Install unzip.
sudo yum -y install unzip
Extract the archive into the webroot directory of Nginx.
sudo unzip modx.zip -d /usr/share/nginx/
Change the name of the directory.
cd /usr/share/nginx/
sudo mv modx-*/ modx/
Also, rename the ht.access
file to .htaccess
.
sudo mv /usr/share/nginx/modx/ht.access /usr/share/nginx/modx/.htaccess
Create a session cache directory and provide ownership to the nginx user.
sudo mkdir /usr/share/nginx/modx/core/cache
sudo chown nginx:nginx /usr/share/nginx/modx/core/cache
Finally, create an empty configuration file and provide appropriate permissions.
sudo touch /usr/share/nginx/modx/core/config/config.inc.php
sudo chown -R nginx:nginx /usr/share/nginx/
Allow traffic on ports 80
and 443
through the firewall.
sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --zone=public --permanent --add-service=https
sudo firewall-cmd --reload
Create Virtual Host
To host your MODX site, create a new virtual host.
sudo nano /etc/nginx/conf.d/modx.example.com.conf
Populate the file.
server {
listen 80;
server_name modx.example.com;
root /usr/share/nginx/modx;
index index.php;
client_max_body_size 30M;
location / {
root /usr/share/nginx/modx;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_ignore_client_abort on;
fastcgi_param SERVER_NAME $http_host;
}
location ~ /\.ht {
deny all;
}
}
Test the Nginx web server configuration.
sudo nginx -t
You will see the following output.
[user@vultr nginx]$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
If you see no errors in the configuration, restart Nginx so that the new configuration can take effect.
sudo systemctl restart nginx
Wrapping Up
Before you can access the installation, you will need to complete the installation via the web installer. Access the web-based installation on http://modx.example.com/setup
. You will see an interface to change the language of installation.
Choose the language according to your preference and on next page, select the "New Installation
" option. On the following page, provide your MySQL or MariaDB database credentials and create a new administrator account. Finally, click the "Install
" button and the installer will write its data into the database.
At this point, you are all set to create your website from the administrative dashboard.