Set Up WordPress with WooCommerce on AlmaLinux 9 or Rocky Linux 9
Install WordPress and WooCommerce on AlmaLinux 9 or Rocky Linux 9 with Nginx, PHP-FPM 8.3 and MariaDB 10.11, replacing the old CentOS 6 setup.
This guide builds a WooCommerce store from a clean server: Nginx, PHP-FPM 8.3 and MariaDB 10.11 on AlmaLinux 9 or Rocky Linux 9 (CentOS Stream 9 works the same way), WordPress on top, then the WooCommerce plugin and the server settings a shop needs. At the end you have a working store at your own domain, served over HTTPS.
Older tutorials on this topic were written for CentOS 6, which reached end of life in 2020. Nothing WooCommerce needs today can be installed on it. AlmaLinux 9 and Rocky Linux 9 are the maintained successors in the same family and use the same commands.
Requirements
WooCommerce publishes its server requirements, and they are stricter than those of plain WordPress. For current WooCommerce releases:
- PHP 8.3 or later
- MySQL 8.0 or later, or MariaDB 10.6 or later
- A WordPress memory limit of 256 MB or more
- HTTPS support
The default packages on a RHEL 9 family system are PHP 8.0 and MariaDB 10.5, which are both too old, so this guide installs the newer module streams instead. You also need:
- An up-to-date AlmaLinux 9 or Rocky Linux 9 server (the PHP 8.3 stream arrived with the 9.6 minor release) and a user with
sudorights. - A domain pointing at the server. The examples use
example.com. - Enough memory. A shop runs PHP, a database and a web server together; 2 GB of RAM is a sensible starting point and a busy catalogue needs more.
Step 1: Update the system and open the firewall
sudo dnf -y update
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reloadStep 2: Install Nginx, PHP 8.3 and MariaDB 10.11
Select the module streams first, then install the packages:
sudo dnf module enable -y php:8.3 mariadb:10.11
sudo dnf install -y nginx mariadb-server php-fpm php-mysqlnd php-gd php-xml php-mbstring php-intl php-soap php-opcache php-pecl-zip tar policycoreutils-python-utilsConfirm the versions:
php -v
mariadb --versionStart the three services and enable them at boot:
sudo systemctl enable --now nginx php-fpm mariadbStep 3: Create the database
Run the hardening script and answer its questions (remove anonymous users, disallow remote root login, remove the test database):
sudo mariadb-secure-installationOpen a database shell as root:
sudo mariadbCreate a database and a user for WordPress. Replace the password with a long random one:
CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'replace-with-a-strong-password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;Step 4: Download WordPress
cd /tmp
curl -O https://wordpress.org/latest.tar.gz
sudo mkdir -p /var/www/example.com
sudo tar -xzf latest.tar.gz -C /var/www/example.com --strip-components=1On these systems the PHP-FPM pool runs as the apache user, even when Nginx is the web server. Give that user ownership so WordPress can install plugins and store uploads:
sudo chown -R apache:apache /var/www/example.comSELinux is enforcing by default. Label the site as writable web content, and allow PHP to make outgoing connections (WordPress needs them to download plugins and updates, WooCommerce to reach payment gateways):
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/example.com(/.*)?"
sudo restorecon -R /var/www/example.com
sudo setsebool -P httpd_can_network_connect 1Step 5: Configure PHP
Raise PHP's limits to what a shop needs. Create a drop-in file rather than editing php.ini:
sudo vi /etc/php.d/90-woocommerce.inimemory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 120Check which socket PHP-FPM listens on; you need the path for Nginx:
grep -E '^(user|group|listen)' /etc/php-fpm.d/www.confThe packaged default is listen = /run/php-fpm/www.sock. Restart PHP-FPM to apply the new limits:
sudo systemctl restart php-fpmStep 6: Configure Nginx
Create a server block for the site:
sudo vi /etc/nginx/conf.d/example.com.confserver {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com;
index index.php;
client_max_body_size 64m;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php-fpm/www.sock;
}
location ~* \.(css|js|jpg|jpeg|png|gif|webp|svg|ico|woff2)$ {
expires 30d;
log_not_found off;
}
location ~ /\.(?!well-known) {
deny all;
}
}The try_files line in location / is what makes WordPress permalinks work, and WooCommerce product, cart and checkout URLs depend on it.
Two settings in the main file are worth a look on a shop. Open /etc/nginx/nginx.conf and make sure worker_processes is set to auto, so Nginx starts one worker per CPU core. Leave worker_connections at 1024 unless you measure a need for more; it is a per-worker limit on open connections, not something to derive from the amount of RAM.
Test and reload:
sudo nginx -t
sudo systemctl reload nginxStep 7: Add HTTPS
A store handles logins, addresses and payments, so do not run it over plain HTTP. Get a certificate before you run the WordPress installer, so the site address is stored as https:// from the start. Certbot is available from the EPEL repository:
sudo dnf install -y epel-release
sudo dnf install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.comCertbot edits the server block to add the certificate and a redirect from HTTP to HTTPS.
Step 8: Run the WordPress installer
Open https://example.com in a browser. Choose a language, then enter the database details from step 3: database name wordpress, user wpuser, your password, host localhost. WordPress writes wp-config.php for you. Then set the site title and create the administrator account. Use a unique username and a strong password, not admin.
Afterwards, set the WordPress memory limit that WooCommerce asks for. Open the configuration file:
sudo vi /var/www/example.com/wp-config.phpAdd this line above the comment that says to stop editing:
define( 'WP_MEMORY_LIMIT', '256M' );In the dashboard, go to Settings → Permalinks, select Post name and save.
Step 9: Install WooCommerce
WooCommerce is a free plugin in the WordPress plugin directory. You do not need an account or a manual download.
- In the dashboard, go to Plugins → Add New Plugin.
- Search for WooCommerce, click Install Now, then Activate.
- Follow the setup wizard: store location, currency, what you sell, and which payment and shipping options you want.
The wizard creates the Shop, Cart, Checkout and My account pages. Add products under Products, and configure taxes, shipping zones and payment methods under WooCommerce → Settings.
Step 10: Verify the setup
Go to WooCommerce → Status. The System Status report shows the PHP version, database version, memory limit and HTTPS state, and marks anything below the requirements in red. Fix what it flags before you take orders. Then place a test order with a payment method in test mode and check that the order emails arrive.
Maintenance
- Updates: apply WordPress, WooCommerce, theme and plugin updates from Dashboard → Updates, and system updates with
sudo dnf -y update. Take a backup first; WooCommerce updates can include database migrations. - Backups: a store's data changes with every order. Dump the database regularly and copy
wp-contentoff the server:
sudo mariadb-dump --single-transaction wordpress | gzip > ~/wordpress-$(date +%F).sql.gz
sudo tar -czf ~/wp-content-$(date +%F).tar.gz -C /var/www/example.com wp-content- Caching: if you add a page cache, exclude the cart, checkout and account pages. Caching them shows one customer's cart to another.
Troubleshooting
- 502 Bad Gateway: PHP-FPM is not running, or the socket path in the Nginx block does not match the
listenvalue in/etc/php-fpm.d/www.conf. - WordPress asks for FTP credentials or cannot install plugins: ownership or the SELinux label is wrong. Repeat the
chown,semanageandrestoreconcommands from step 4. - Product pages return 404: save the permalink settings again, and check the
try_filesline in the Nginx block. - SELinux denials:
sudo ausearch -m avc -ts recentshows what was blocked.
Frequently asked questions
Can I run WooCommerce on a server with 512 MB or 1 GB of RAM?
It will install, but WooCommerce itself asks for a 256 MB PHP memory limit per request, and MariaDB and Nginx need memory too. On a very small server a few simultaneous visitors are enough to exhaust it. Treat 2 GB as the practical minimum for a live shop and add swap as a safety net, not as a substitute.
Why not use the PHP and MariaDB versions that come with the system by default?
The defaults on a RHEL 9 family system are PHP 8.0 and MariaDB 10.5. WooCommerce now requires PHP 8.3 and MariaDB 10.6 or later, and WordPress itself recommends PHP 8.3 and MariaDB 10.11 or later. The module streams used here come from the distribution's own repositories, so they still receive updates through dnf.
Do I need Apache for WooCommerce?
No. WooCommerce's requirements name Apache or Nginx as recommended and state that any server supporting PHP and MySQL works. With Nginx there is no .htaccess; rewrite rules that a plugin tells you to put there have to be translated into the Nginx server block.
How do I move an existing CentOS 6 shop to the new server?
Set up the new server as above, then copy the old site's wp-content directory and a dump of its database across, and import the dump into the new database. Bring WordPress, WooCommerce and all plugins up to date on the new server, test with your hosts file pointing the domain at the new IP, and only then change DNS. An in-place upgrade from CentOS 6 is not possible.