Operating System CentOS

How to Install MODX Revolution 3 with Nginx on AlmaLinux 9 or Rocky Linux 9

Set up MODX Revolution 3 on AlmaLinux 9 or Rocky Linux 9 with Nginx, PHP-FPM and MariaDB, with SELinux left enabled and friendly URLs working.

This guide installs MODX Revolution 3, the current major version of the MODX content management system, on AlmaLinux 9 or Rocky Linux 9 (CentOS Stream 9 works the same way). You end up with Nginx serving the site, PHP-FPM running MODX, MariaDB holding the data, SELinux still enforcing, and friendly URLs ready to switch on.

Older tutorials for this setup targeted CentOS 7 with MODX 2.6 and PHP 7.2. CentOS 7 reached end of life in June 2024, and MODX 3.2 and later require PHP 8.1 or newer, so none of the old package sources apply. AlmaLinux and Rocky Linux are the usual replacements for CentOS and provide everything needed from their own repositories.

Requirements

  • An AlmaLinux 9 or Rocky Linux 9 server and a user with sudo rights.
  • A domain name pointing at the server. The examples use modx.example.com.
  • MODX 3.2 or later needs PHP 8.1+ (8.2 or higher is recommended) and MySQL 5.7+; MariaDB 10.6 or newer is recommended. PHP must have the curl, dom, fileinfo, gd, json, pdo, pdo_mysql, simplexml, xml, xmlwriter, zip and zlib extensions; mbstring and intl are recommended.

Update the system first:

sudo dnf -y update

Install Nginx

sudo dnf -y install nginx
sudo systemctl enable --now nginx
sudo firewall-cmd --permanent --add-service=http --add-service=https
sudo firewall-cmd --reload

Install PHP-FPM

The default PHP on release 9 is 8.0, which is too old for MODX 3.2. Newer versions are provided as module streams. List them, then enable the newest one offered; at the time of writing that is 8.3:

sudo dnf module list php
sudo dnf -y module reset php
sudo dnf -y module enable php:8.3

Install PHP-FPM with the extensions MODX needs:

sudo dnf -y install php-fpm php-cli php-mysqlnd php-gd php-xml php-mbstring php-intl php-pecl-zip php-opcache unzip

Add a small configuration file with your time zone and limits that suit a CMS. MODX recommends a memory limit of at least 64M; there is no reason to make it unlimited.

sudo tee /etc/php.d/99-modx.ini > /dev/null <<'EOF'
date.timezone = UTC
memory_limit = 128M
upload_max_filesize = 30M
post_max_size = 30M
EOF

The packaged PHP-FPM pool in /etc/php-fpm.d/www.conf runs as the apache user and listens on the socket /run/php-fpm/www.sock, which the nginx user is already allowed to connect to. You do not need to edit it. Start the service and confirm the extensions are loaded:

sudo systemctl enable --now php-fpm
php -m | grep -Ei 'curl|dom|fileinfo|gd|pdo_mysql|simplexml|xmlwriter|zip|mbstring|intl'

Install MariaDB and create the database

The default MariaDB on release 9 is 10.5. MODX runs on it, but recommends 10.6 or newer, and a 10.11 module stream is available. Check with sudo dnf module list mariadb; if the stream is not listed on your system, skip the first command.

sudo dnf -y module enable mariadb:10.11
sudo dnf -y install mariadb-server
sudo systemctl enable --now mariadb
sudo mariadb-secure-installation

Open a database shell as root and create a database and a user for MODX:

sudo mariadb
CREATE DATABASE modx CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'modx'@'localhost' IDENTIFIED BY 'replace-with-a-strong-password';
GRANT ALL PRIVILEGES ON modx.* TO 'modx'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Get the MODX files

MODX publishes its ready-to-run traditional package on the MODX download page, which has to be fetched in a browser, and it documents a build from the project's Git repository, which can be done entirely on the server. Use one of the two.

Option 1: the traditional zip package

This is the route MODX recommends for most sites. On your own computer, open the MODX download page, download the current traditional package of MODX Revolution 3, and copy it to the server, for example with scp:

scp modx-traditional.zip deploy@203.0.113.10:/tmp/modx.zip

Replace modx-traditional.zip with the name of the file you downloaded. On the server, unpack it and look at the result:

cd /tmp
unzip -q modx.zip -d modx-unpacked
ls modx-unpacked modx-unpacked/*

The MODX files (index.php, core/, manager/, connectors/ and setup/) normally sit inside one wrapper directory. Copy the contents of that directory to the web root. If your listing shows the files directly in modx-unpacked, remove the /* from the path:

sudo mkdir -p /var/www/modx
sudo cp -a /tmp/modx-unpacked/*/. /var/www/modx/

Option 2: build a release from Git

MODX documents installing from its GitHub repository: clone the code, install the PHP dependencies with Composer, build the core package, then run the same web installer. The documentation clones the 3.x development branch; for a website, check out a release tag instead. v3.2.4-pl is the newest release tag at the time of writing; look at the tags page of the modxcms/revolution repository for a newer one.

sudo dnf -y install git
cd ~
git clone --depth 1 -b v3.2.4-pl https://github.com/modxcms/revolution.git modx-src

Download Composer and check the file against its published checksum. The last command must print composer.phar: OK:

curl -fsSLO https://getcomposer.org/download/latest-stable/composer.phar
curl -fsSLO https://getcomposer.org/download/latest-stable/composer.phar.sha256sum
sha256sum -c composer.phar.sha256sum

Install the dependencies, which Composer places in core/vendor:

cd ~/modx-src
php ~/composer.phar install

Create the two build configuration files from their samples (no changes are needed) and build the core package:

cd ~/modx-src/_build
cp build.config.sample.php build.config.php
cp build.properties.sample.php build.properties.php
php transport.core.php

The build finishes with a message that the transport zip was created. Remove the Git metadata, which has no place in a web root, and copy the tree into place:

rm -rf ~/modx-src/.git ~/modx-src/.github
sudo mkdir -p /var/www/modx
sudo cp -a ~/modx-src/. /var/www/modx/

Set ownership

Whichever option you used, hand the files to the PHP-FPM user:

sudo chown -R apache:apache /var/www/modx

Set the SELinux context

SELinux is enforcing by default and stops PHP from writing into /var/www. MODX needs to write to core/cache, core/config, core/packages, core/import and core/export, and its package manager writes into several other directories when you install Extras. Label the MODX tree as writable web content and allow PHP to make outgoing connections so the package manager can download Extras:

sudo dnf -y install policycoreutils-python-utils
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/modx(/.*)?"
sudo restorecon -R /var/www/modx
sudo setsebool -P httpd_can_network_connect 1

Do not use chmod 777 or disable SELinux to get past permission errors.

Configure the Nginx server block

Create a configuration file for the site:

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

This follows the server block from the MODX documentation, adapted to the PHP-FPM socket on this system. The two deny blocks keep the core directory and configuration file from being requested over the web.

server {
    listen 80;
    listen [::]:80;
    server_name modx.example.com;

    root /var/www/modx;
    index index.php;
    client_max_body_size 30M;

    location @modx {
        rewrite ^/(.*)$ /index.php?q=$1&$args last;
    }

    location / {
        absolute_redirect off;
        try_files $uri $uri/ @modx;
    }

    location ~ /\.ht {
        deny all;
    }

    location ~ ^/(_build|_gitify|_backup|core|config\.core\.php) {
        deny all;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SERVER_NAME $host;
        fastcgi_ignore_client_abort on;
    }
}

Test the configuration and reload Nginx:

sudo nginx -t
sudo systemctl reload nginx

Run the MODX installer

Open http://modx.example.com/setup/ in your browser and work through the installer:

  1. Choose your language and select New Installation. The file permission fields can keep their defaults. If you built MODX from Git, the installer shows a welcome screen first, and the options Core package has been manually unpacked and Files are already in-place must both be ticked; they are normally preselected.
  2. Enter the database connection: host localhost, the modx user and password you created, database name modx, and the table prefix (modx_ by default). Test the connection, then select the utf8mb4 character set with the utf8mb4_general_ci collation.
  3. Create the Manager administrator. Pick a username other than admin, a strong password and a real e-mail address.
  4. Review the pre-installation checks. If a directory is reported as not writable, recheck the ownership and SELinux commands above. Then click Install.
  5. On the final screen, tick the option to delete the setup directory and log in to the Manager at http://modx.example.com/manager/.

Confirm that the installer is gone. If the directory still exists, remove it by hand:

sudo rm -rf /var/www/modx/setup

After the installation

Enable friendly URLs

The @modx rewrite in the server block already sends unknown paths to index.php. In the Manager, open the system settings, filter for the Friendly URL area, and set friendly_urls to Yes. Then give your resources aliases and clear the cache.

Add HTTPS

A Manager login should not travel over plain HTTP. Certbot and its Nginx plugin are available from EPEL and will obtain a certificate and adjust the server block for you:

sudo dnf -y install epel-release
sudo dnf -y install certbot python3-certbot-nginx
sudo certbot --nginx -d modx.example.com

Updates and backups

Apply operating system updates with sudo dnf -y update. Before upgrading MODX itself, back up both parts of the site:

sudo mariadb-dump modx > ~/modx-$(date +%F).sql
sudo tar -czf ~/modx-files-$(date +%F).tar.gz -C /var/www modx

More detail is in the MODX documentation on server requirements and Nginx friendly URLs.

Frequently asked questions

The installer says a directory is not writable although the owner is correct. Why?

That is almost always SELinux. Run ls -Zd /var/www/modx/core/cache; the context should contain httpd_sys_rw_content_t. If it does not, repeat the semanage fcontext and restorecon commands. Files copied after the labelling rule exists get the right context when you run restorecon again.

Can I run MODX 3 on the PHP 8.0 that the distribution installs by default?

No. MODX 3.2 and later need PHP 8.1 at minimum. Enable a newer module stream as shown above; you do not need a third-party PHP repository for that.

Should I move the core directory out of the web root?

It is a worthwhile hardening step, described in the MODX hardening documentation. If you leave core in place, keep the deny rule in the Nginx configuration, since MODX's .htaccess protections do nothing under Nginx.

Does MODX work with PostgreSQL?

A third-party PostgreSQL implementation exists, but MySQL and MariaDB are the supported choice, and many Extras only ship MySQL drivers. Microsoft SQL Server support was removed in MODX 3.0.

Share story:

Continue reading other guides on How VPS.