
How to Install WordPress on latest CentOS
Setting up WordPress on the latest CentOS is a fundamental skill every developer and sysadmin should master. Whether you’re spinning up a new blog, client site, or staging environment, understanding this process inside-out saves you headaches down the road. We’ll walk through the complete installation process, from initial server prep to final WordPress configuration, plus tackle the gotchas that always seem to pop up at 2 AM when you’re trying to get a site live.
Prerequisites and System Requirements
Before diving in, let’s make sure your environment is ready. You’ll need root or sudo access to a fresh CentOS Stream 9 (or CentOS 8 if you’re still running it) installation. The minimum requirements are pretty modest:
- 2GB RAM (4GB+ recommended for production)
- 20GB disk space minimum
- Network connectivity and a non-root user with sudo privileges
First, update your system and install essential packages:
sudo dnf update -y
sudo dnf install -y wget curl vim unzip
Installing the LAMP Stack
WordPress needs Apache, MySQL/MariaDB, and PHP to function. Let’s get these components installed and configured properly.
Apache Installation and Configuration
sudo dnf install -y httpd
sudo systemctl start httpd
sudo systemctl enable httpd
# Configure firewall
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
MariaDB Setup
CentOS repositories include MariaDB by default, which is a drop-in MySQL replacement:
sudo dnf install -y mariadb-server mariadb
sudo systemctl start mariadb
sudo systemctl enable mariadb
# Secure the installation
sudo mysql_secure_installation
During the secure installation, set a strong root password and answer ‘Y’ to all prompts for security hardening.
PHP Installation
For optimal WordPress performance, install PHP 8.1 or later:
sudo dnf install -y php php-mysqlnd php-gd php-xml php-mbstring php-json php-curl php-zip php-intl php-soap
# Restart Apache to load PHP
sudo systemctl restart httpd
Database Configuration
Create a dedicated database and user for WordPress. Never use the root MySQL user for web applications:
sudo mysql -u root -p
In the MySQL prompt:
CREATE DATABASE wordpress_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'your_secure_password_here';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
WordPress Installation Process
Download and extract WordPress to your web directory:
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz
sudo cp -R wordpress/* /var/www/html/
# Set proper ownership and permissions
sudo chown -R apache:apache /var/www/html/
sudo chmod -R 755 /var/www/html/
sudo chmod -R 775 /var/www/html/wp-content/
Create the WordPress configuration file:
cd /var/www/html/
sudo cp wp-config-sample.php wp-config.php
sudo vim wp-config.php
Update the database configuration section:
define('DB_NAME', 'wordpress_db');
define('DB_USER', 'wp_user');
define('DB_PASSWORD', 'your_secure_password_here');
define('DB_HOST', 'localhost');
Generate security keys from WordPress.org’s secret key generator and replace the placeholder values in wp-config.php.
Performance Optimization and Security Hardening
PHP Configuration Tweaks
Edit /etc/php.ini for better performance:
sudo vim /etc/php.ini
Key settings to modify:
memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300
max_input_vars = 3000
Apache Virtual Host Configuration
Create a proper virtual host instead of using the default:
sudo vim /etc/httpd/conf.d/wordpress.conf
<VirtualHost *:80>
ServerName your-domain.com
DocumentRoot /var/www/html
<Directory /var/www/html>
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/wordpress_error.log
CustomLog /var/log/httpd/wordpress_access.log combined
</VirtualHost>
Common Issues and Troubleshooting
SELinux Complications
CentOS enables SELinux by default, which can block WordPress operations. Check if SELinux is causing issues:
sudo setsebool -P httpd_can_network_connect 1
sudo setsebool -P httpd_can_network_connect_db 1
sudo chcon -R -t httpd_exec_t /var/www/html/
File Permission Problems
WordPress needs write access to specific directories:
# For uploads and plugin installations
sudo chmod 775 /var/www/html/wp-content/uploads/
sudo chmod 775 /var/www/html/wp-content/plugins/
sudo chmod 775 /var/www/html/wp-content/themes/
Memory and Performance Issues
Issue | Symptom | Solution |
---|---|---|
PHP Memory Limit | White screen of death | Increase memory_limit in php.ini |
Slow Database Queries | Page load timeouts | Install query caching plugin, optimize database |
Large File Uploads Failing | Upload errors in media library | Increase upload_max_filesize and post_max_size |
Real-World Use Cases and Best Practices
Development vs Production Considerations
For development environments, you might want to enable WordPress debugging:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
For production, always disable debugging and implement proper backup strategies:
# Automated daily backups
sudo crontab -e
# Add: 0 2 * * * mysqldump -u wp_user -p'password' wordpress_db > /backups/wp_$(date +\%Y\%m\%d).sql
Multi-Site Considerations
If you’re planning to run multiple WordPress sites, consider using separate databases and virtual hosts for each site rather than WordPress multisite, unless you specifically need shared user management.
Alternative Approaches and Technology Comparisons
Approach | Pros | Cons | Best For |
---|---|---|---|
Manual LAMP Installation | Full control, educational | Time-consuming, error-prone | Learning, custom configurations |
Docker WordPress | Isolated, reproducible | Additional complexity layer | Development, microservices |
Managed WordPress Hosting | Hands-off, optimized | Less control, higher cost | Production sites, non-technical users |
SSL/TLS Implementation
Don’t forget to secure your WordPress installation with HTTPS. Install Certbot for free Let’s Encrypt certificates:
sudo dnf install -y certbot python3-certbot-apache
sudo certbot --apache -d your-domain.com
Performance Monitoring and Maintenance
Set up log rotation and monitoring to keep your WordPress installation healthy:
sudo vim /etc/logrotate.d/wordpress
/var/log/httpd/wordpress_*.log {
daily
missingok
rotate 52
compress
notifempty
create 640 apache apache
postrotate
systemctl reload httpd
endscript
}
Regular maintenance tasks should include updating WordPress core, plugins, and themes, monitoring disk space, and reviewing security logs. Consider setting up automated security updates for critical patches.
For production deployments on robust infrastructure, check out VPS hosting solutions or dedicated servers that provide the performance and reliability needed for high-traffic WordPress sites.
The key to successful WordPress deployment on CentOS is understanding each component’s role and maintaining proper security practices from day one. Take time to document your configuration choices and backup procedures β your future self will thank you when it’s time to replicate or troubleshoot the setup.

This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.
This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.