Installing MODX CMS on CentOS 7 with Nginx, PHP 7.2, and MariaDB

MODX is an open-source content management system written in PHP, utilizing MySQL or MariaDB for data storage. It is ideal for businesses where consistent web presence is essential. MODX offers developers the freedom to define the layout and architecture, while also including a WYSIWYG interface for non-technical users. This CMS combines versatility with the potential for high-speed performance.

This walkthrough is built around MODX version 2.6.1, but it should be compatible with newer releases as well.

Requirements

  • A CentOS 7 server
  • User access with sudo privileges
  • A domain configured to direct traffic to your server

Throughout this tutorial, we will refer to modx.example.com as the domain name. Make sure to replace it with your actual domain when following the steps.

System Preparation

First, update your base system by following the instructions in the guide “How to Update CentOS 7”. Once updated, install the necessary packages.

Installing Nginx

Nginx is a high-performance web server suitable for running modern web apps. Begin by installing Nginx:

sudo yum -y install epel-release
sudo yum -y install nginx

Enable and start Nginx so it runs on boot:

sudo systemctl start nginx
sudo systemctl enable nginx

Installing PHP 7.2

MODX supports PHP versions above 5.4. To ensure better performance and security, install PHP 7.2. Since this version isn’t in the default repository, enable the Remi repository first:

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 7.2 and the extensions 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 PHP configuration file:

Uncomment and set the appropriate timezone:

date.timezone = Asia/Kolkata

Set memory limit as follows to allow unlimited memory usage:

Update the following setting to disable path info processing:

Open and modify the PHP-FPM pool configuration file:

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

Replace the default listener configuration:

;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php-fpm.sock

Update the user and group settings:

listen.owner = nginx
listen.group = nginx

user = nginx
group = nginx

Restart PHP-FPM and set it to launch at boot:

sudo systemctl restart php-fpm
sudo systemctl enable php-fpm

Create and set permissions for the session directory:

sudo mkdir /var/lib/php/session
sudo chmod -R 777 /var/lib/php/session

You are now ready to proceed with the MariaDB installation.

 

 

Setting Up MariaDB

MariaDB, a community-developed fork of MySQL, requires a newer version than what’s included in CentOS’s default YUM repository. Add the MariaDB repository to begin:

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

Proceed with the MariaDB installation:

sudo yum -y install mariadb mariadb-server

Start MariaDB and configure it to run on boot:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Secure the database server with the following command:

sudo mysql_secure_installation

You’ll be prompted for the root password—by default, there’s none. Press Enter to continue. Set a strong root password and accept all recommended settings by answering “Y” to each prompt.

Next, access the MySQL shell as the root user:

Use the following SQL commands to set up a database and user for MODX:

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 personalize the database name and credentials. Be sure to use a robust password in place of StrongPassword.

Installing MODX

Download the MODX archive from the official site:

wget https://modx.com/download/direct?id=modx-2.6.1-pl.zip -O modx.zip

To find the latest version, visit the MODX downloads page. Next, install the unzip utility:

Extract the contents to the Nginx web root:

sudo unzip modx.zip -d /usr/share/nginx/

Rename the extracted folder to modx:

cd /usr/share/nginx/
sudo mv modx-*/ modx/

Change the default ht.access file to .htaccess:

sudo mv /usr/share/nginx/modx/ht.access /usr/share/nginx/modx/.htaccess

Create a cache directory and assign it to the nginx user:

sudo mkdir /usr/share/nginx/modx/core/cache
sudo chown nginx:nginx /usr/share/nginx/modx/core/cache

Set up an empty configuration file with the correct ownership:

sudo touch /usr/share/nginx/modx/core/config/config.inc.php
sudo chown -R nginx:nginx /usr/share/nginx/

Finally, adjust the firewall to permit HTTP and HTTPS access:

sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --zone=public --permanent --add-service=https
sudo firewall-cmd --reload

 

Configure Nginx Virtual Host

To serve your MODX website through Nginx, set up a new virtual host configuration file:

sudo nano /etc/nginx/conf.d/modx.example.com.conf

Add the following configuration content to 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 Your Configuration

Once you’ve saved the virtual host file, test Nginx to ensure the syntax is correct:

If everything is correctly configured, you’ll see the following messages:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Apply the changes by restarting the Nginx service:

sudo systemctl restart nginx

Finalizing the Installation

To finish installing MODX, open your web browser and go to:

http://modx.example.com/setup

The MODX setup wizard will appear, allowing you to choose your preferred language. Click through and select the “New Installation” option. Then, enter your MariaDB or MySQL database information and set up an administrator account.

Once you click “Install,” MODX will store the setup data in the database and complete the installation. You’ll then be redirected to the administrative dashboard where you can begin building your site.

 

Conclusion

With MODX successfully installed on your CentOS 7 server using Nginx, PHP 7.2, and MariaDB, your platform is now ready for content creation and web application development. You’ve configured a secure and flexible environment tailored for both developers and non-technical users. The administrative dashboard provides full control over site customization and content management. From here, you can begin crafting your website to match your business needs.

Source: vultr.com

Create a Free Account

Register now and get access to our Cloud Services.

Posts you might be interested in: