Installing WordPress on CentOS
Welcome to our detailed walkthrough on installing WordPress on a CentOS server. WordPress is a powerful, open-source content management system (CMS) that powers a significant portion of the web. It's renowned for its flexibility and ease of use, making it an excellent choice for bloggers, businesses, and everyone in between. CentOS, with its reputation for stability and reliability, provides a robust platform for hosting WordPress websites.
In this tutorial, we'll cover every step, from setting up your CentOS server to customizing your WordPress installation. We'll use command-line instructions and provide explanations for each step. Regardless of if you're a seasoned sysadmin or a newcomer to server management, this guide will help you get your WordPress site up and running smoothly.
Prerequisites
Before we dive in, ensure you have the following:.
- A CentOS server with root access or a user with sudo privileges.
- A domain name pointed to your server's IP address.
- Basic knowledge of using the command line and SSH.
Step 1: Update Your System
To begin, it's crucial to update your CentOS packages to the latest versions. This ensures you have the most recent security patches and software improvements.
sudo yum update -y
Output:.
...
Complete!
Step 2: Install LAMP Stack (Linux, Apache, MySQL, PHP)
WordPress requires a LAMP stack to operate. Let's install each component.
Install Apache
sudo yum install -y httpd
Output:.
...
Installed:.
httpd.x86_64 0:2.4.37-10.el7
...
Complete!
Install MySQL
sudo yum install -y mysql-server
Expected Output:.
...
Installed:.
mysql-server.x86_64 0:5.5.65-1.el7
...
Complete!
Install PHP and Required Extensions
sudo yum install -y php php-mysql php-gd php-xml php-mbstring php-pear php-fpm
Output:.
...
Installed:.
php.x86_64 0:5.4.16-45.el7
php-cli.x86_64 0:5.4.16-45.el7
php-common.x86_64 0:5.4.16-45.el7
php-fpm.x86_64 0:5.4.16-45.el7
php-gd.x86_64 0:5.4.16-45.el7
php-mbstring.x86_64 0:5.4.16-45.el7
php-mysql.x86_64 0:5.4.16-45.el7
php-pear.noarch 1:1.10.5-1.el7
php-xml.x86_64 0:5.4.16-45.el7
...
Complete!
Start Apache and MySQL Services
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl start mysqld
sudo systemctl enable mysqld
Secure MySQL
Run the mysql_secure_installation
script to set a root password and remove anonymous users.
sudo mysql_secure_installation
Follow the on-screen instructions to complete the MySQL setup.
Step 3: Configure SELinux
SELinux can sometimes interfere with Apache and MySQL. Let's adjust the necessary booleans.
sudo setsebool -P httpd_can_network_connect_db 1
sudo setsebool -P httpd_can_network_connect 1
Step 4: Create a Database for WordPress
Log in to MySQL and create a database and user for WordPress.
mysql -u root -p
Once logged in, execute the following SQL commands:.
CREATE DATABASE wordpressdb;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON wordpressdb.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Expected Output:.
...
Query OK, 0 rows affected (0.00 sec)
...
Step 5: Install WordPress
Download the latest WordPress package.
cd /var/www/html
sudo wget https://wordpress.org/latest.tar.gz
Output:.
...
Saving to: ‘latest.tar.gz’
...
Extract the files.
sudo tar xzf latest.tar.gz
Expected Output:.
...
wordpress/
wordpress/.htaccess
wordpress/index.php
...
Move the extracted files to the root directory.
sudo mv wordpress/* /var/www/html/
Set the correct ownership and permissions.
sudo chown -R apache:apache /var/www/html/
sudo find /var/www/html/ -type d -exec chmod 755 {} \;
sudo find /var/www/html/ -type f -exec chmod 644 {} \;
Step 6: Configure WordPress
Create the wp-config.php
file by copying the sample file.
sudo cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php
Edit wp-config.php
to add your database information.
sudo nano /var/www/html/wp-config.php
Replace 'database_name_here'
, 'username_here'
, and 'password_here'
with the database name, username, and password you created earlier.
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpressdb');
/** MySQL database username */
define('DB_USER', 'wpuser');
/** MySQL database password */
define('DB_PASSWORD', 'your_password');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
Save and close the file.
Step 7: Complete WordPress Installation
Open your web browser and navigate to your server's domain name or IP address. You should see the WordPress installation page.
Follow the instructions to complete the installation, which includes setting up an admin account and configuring site settings.
Step 8: Secure Your WordPress Site
- SSL Certificate: Use Let's Encrypt to install a free SSL certificate.
- Firewall: Consider using a firewall like
firewalld
oriptables
. - Security Plugins: Install security plugins like Wordfence or Sucuri.
Step 9: Maintenance and Updates
Regularly update WordPress, themes, and plugins to their latest versions to ensure security and functionality.
Troubleshooting Common Issues
- White Screen of Death: This could be due to a plugin or theme conflict. Try disabling all plugins and switching to a default theme.
- Error Establishing Database Connection: Ensure your database credentials in
wp-config.php
are correct and that the MySQL service is running.
You now have a fully functional WordPress installation on your CentOS server. Remember to keep your server and WordPress installation up to date with the latest security patches. With regular maintenance and the right security measures, your WordPress site will be a powerful and secure presence on the web.