Table of Contents[Hide][Show]
WordPress is one of the most popular content management systems (CMS) in the world, powering over 40% of all websites on the internet. Its flexibility, ease of use, and extensive plugin ecosystem make it an ideal choice for bloggers, businesses, and developers alike. If you’re running a CentOS 8 server and want to set up WordPress, this guide will walk you through the entire process step-by-step.
In this article, we will cover how to install WordPress on CentOS 8, including setting up a LAMP stack (Linux, Apache, MySQL, and PHP), configuring the necessary components, and securing your WordPress installation. By the end of this guide, you’ll have a fully functional WordPress site running on your CentOS 8 server.
Prerequisites
Before we dive into the installation process, ensure that you have the following:
- A CentOS 8 server: You should have
root
orsudo
access to the server. - A domain name: Point your domain to your server’s IP address using your DNS provider.
- Basic command-line knowledge: Familiarity with the Linux command line will be helpful.
How to Install WordPress on CentOS 8
Step 1: Update Your System
Before installing any software, it’s a good practice to update your system to ensure all existing packages are up to date. Run the following command:
sudo dnf update -y
This command updates all installed packages to their latest versions.
Step 2: Install a LAMP Stack
WordPress requires a web server, a database, and PHP to function. We’ll use the LAMP stack, which consists of:
- Linux: CentOS 8 (already installed)
- Apache: Web server
- MySQL/MariaDB: Database management system
- PHP: Scripting language
2.1 Install Apache
Apache is one of the most popular web servers. To install it, run:
sudo dnf install httpd -y
Once installed, start and enable Apache to run on boot:
sudo systemctl start httpd sudo systemctl enable httpd
You can verify that Apache is running by visiting your server’s IP address in a web browser. You should see the default Apache welcome page.
2.2 Install MariaDB
WordPress uses a database to store its content. MariaDB is a popular open-source database management system. Install it with:
sudo dnf install mariadb-server -y
Start and enable MariaDB:
sudo systemctl start mariadb sudo systemctl enable mariadb
Secure your MariaDB installation by running the following command and following the prompts:
sudo mysql_secure_installation
This script will guide you through setting a root password, removing anonymous users, disallowing remote root login, and removing test databases.
2.3 Install PHP
WordPress is written in PHP, so you’ll need to install PHP and its required extensions. Run the following command:
sudo dnf install php php-mysqlnd php-json php-gd php-mbstring php-xml php-xmlrpc php-opcache php-zip php-curl -y
After installation, restart Apache to load the PHP module:
sudo systemctl restart httpd
Step 3: Create a Database for WordPress
WordPress requires a database to store its data. Log in to MariaDB as the root user:
sudo mysql -u root -p
Create a new database and user for WordPress:
CREATE DATABASE wordpress; CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost'; FLUSH PRIVILEGES; EXIT;
Replace your_password
with a strong password. This database and user will be used during the WordPress installation.
Step 4: Download and Configure WordPress
Now that the LAMP stack is set up, it’s time to install WordPress.
4.1 Download WordPress
Navigate to the web root directory:
cd /var/www/html
Download the latest version of WordPress:
sudo wget https://wordpress.org/latest.tar.gz
Extract the downloaded file:
sudo tar -xvzf latest.tar.gz
This will create a wordpress
directory. Move its contents to the web root directory:
sudo mv wordpress/* .
Set the correct permissions for the WordPress files:
sudo chown -R apache:apache /var/www/html sudo chmod -R 755 /var/www/html
4.2 Configure WordPress
Rename the sample configuration file:
sudo mv wp-config-sample.php wp-config.php
Edit the wp-config.php
file to add your database details:
sudo nano wp-config.php
Find the following lines and replace them with your database information:
define('DB_NAME', 'wordpress'); define('DB_USER', 'wordpressuser'); define('DB_PASSWORD', 'your_password'); define('DB_HOST', 'localhost');
Save and exit the file.
Step 5: Complete the WordPress Installation
Open your web browser and navigate to your server’s IP address or domain name. You should see the WordPress installation wizard.
- Select Language: Choose your preferred language and click “Continue.”
- Database Information: The database details should already be filled in. Click “Submit.”
- Run the Installation: Click “Run the installation.”
- Site Information: Enter your site title, username, password, and email address. Click “Install WordPress.”
Once the installation is complete, you can log in to your WordPress dashboard using the credentials you just created.
Step 6: Secure Your WordPress Installation
Security is crucial for any website. Here are some steps to secure your WordPress installation:
6.1 Set Up a Firewall
CentOS 8 comes with firewalld
pre-installed. Allow HTTP and HTTPS traffic:
sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --reload
6.2 Install an SSL Certificate
Secure your site with an SSL certificate using Let’s Encrypt:
Install the Certbot tool:
sudo dnf install certbot python3-certbot-apache -y
Obtain and install the SSL certificate:
sudo certbot --apache
Follow the prompts to complete the process. Certbot will automatically configure Apache to use HTTPS.
6.3 Harden WordPress
- Use Strong Passwords: Ensure all user accounts have strong passwords.
- Install Security Plugins: Plugins like Wordfence or iThemes Security can help protect your site.
- Regular Updates: Keep WordPress, themes, and plugins up to date.
Step 7: Optimize WordPress Performance
To ensure your WordPress site runs smoothly, consider the following optimizations:
- Caching: Install a caching plugin like W3 Total Cache or WP Super Cache.
- Content Delivery Network (CDN): Use a CDN like Cloudflare to serve static content faster.
- Optimize Images: Compress images before uploading them to your site.
- Database Optimization: Use plugins like WP-Optimize to clean up your database.
Conclusion
Installing WordPress on CentOS 8 is a straightforward process if you follow the steps outlined in this guide. By setting up a LAMP stack, configuring the necessary components, and securing your installation, you can create a robust and reliable WordPress site.
Remember to regularly update your software, back up your site, and monitor its performance to ensure a smooth user experience. With WordPress’s flexibility and CentOS’s stability, you have a powerful combination for building and managing your website.
By following this guide on how to install WordPress on CentOS 8, you’re well on your way to creating a successful online presence. Happy blogging!