How to Install WordPress on CentOS 7
WordPress is the most popular Content Management System (CMS) on the Internet. Powering over 60% of websites, the platform is a great choice for web designers and developers due to its easy-to-use tools.
To run WordPress on your server, a web server stack like the Linux, Apache, MySQL, PHP (LAMP) combination works best to host websites on your server. In this guide, you will install WordPress on a LAMP configuration CentOS 7 server. In case you don’t have the LAMP stack installed, follow the instructions here.
Prerequisites
- A Vultr CentOS 7 server instance
- A non-root user account with sudo privileges
- A LAMP stack installed on your server
Create a MySQL Database
With the LAMP Stack installed on your CentOS 7 server, you need to create a database that WordPress will use to create new tables necessary for the CMS functions. By default, CentOS 7 supports the MariaDB database and not the base MySQL. However, all commands and table structures remain the same because MariaDB is a free fork of MySQL.
Log into MariaDB as root and create a new WordPress database.
create database myexample;
Create a new database user and assign it a password.
CREATE USER 'user'@'localhost' IDENTIFIED BY '12345678Aa';
Now, grant the user full rights to the new WordPress database.
MariaDB [(none)]> use myexample;
MariaDB [myexample]> GRANT ALL PRIVILEGES ON myexample.* TO 'user'@'localhost';
Exit the console.
MariaDB [myexample]>EXIT
Install PHP and Extensions
On CentOS 7, PHP 5.4 is the base supported version, but WordPress requires PHP 7.4 and above to run. So, let’s install PHP 7.4 through the Remi repository.
$ sudo yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Update yum.
$ sudo yum update
Now, run the command below to install PHP 7.4 and all necessary extensions.
$ sudo yum --enablerepo=remi-php74 install php php-bz2 php-mysql php-curl php-gd php-intl php-common php-mbstring php-xml
After installation is complete, restart Apache to enable PHP and extensions for hosted websites.
$ sudo systemctl restart httpd
Install WordPress
To install WordPress, you need to download the latest tar achieve from WordPress.org using wget.
Install wget
$ sudo yum install wget
Use wget to download the latest WordPress version.
$ wget http://WordPress.org/latest.tar.gz
Unzip the downloaded WordPress tar archive.
$ sudo tar -xzvf latest.tar.gz
Now, move the extracted file contents to /var/www/html
.
$ sudo mv WordPress/* /var/www/html/
Next, change ownership of the html directory to the web server user and its associated group for full read, write, execute permissions.
$ sudo chown -R apache.apache /var/www/html/
Configure WordPress
Visit your public server IP or associated domain name to start the WordPress web installer in a web browser.
http://YOUR_SERVER_IP OR http://YOUR_DOMAIN_NAME
You will be presented a Welcome to WordPress page, click Let’s go
to start the installation process.
Next, enter your database name, username, and associated password to connect WordPress and the database server.
Once a connection is established, enter your preferred website title, administrator username, password, and email address to configure your WordPress installation.
Success, WordPress will be installed on your server. Now, click login to enter your administrator username and password to proceed with building your first website.
Troubleshooting WordPress
The WordPress installation process should be error-free, but you should know how to fix errors in any case where errors arise. Common errors may arise from improper permissions for the web server, incorrect PHP version, or issues with your database connection, and here is how to fix them on your CentOS 7 server.
Error Establishing Database Connection
Check and confirm that MariaDB is up and running on your server.
$ sudo systemctl status mariadb
$ sudo systemctl start mariadb
Change and confirm the WordPress database and user credentials entered in the wp-config.php file.
$ sudo nano /var/www/html/wp-config.php
Check and confirm if the database settings are correct.
/** The name of the database for WordPress */
define( 'DB_NAME', 'myexample' );
/** MySQL database username */
define( 'DB_USER', 'user' );
/** MySQL database password */
define( 'DB_PASSWORD', '12345678Aa' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );
If you imported backed-up WordPress files, confirm the table prefix entry to match the format of your database tables.
$table_prefix = 'wp_';
If not, change the prefix to match the format of your imported database tables.
A Critical error occurred on your website
Check your current PHP version if your WordPress version supports it, the latest version supports PHP 7.4 and above.
$ php -v
PHP 7.4.24 (cli) (built: Sep 21 2021 11:23:11) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
Check the current web server permissions whether Apache can read and write to the WordPress files directory.
$ ls -l /var/www/html/
total 220
-rw-r--r--. 1 apache apache 405 Feb 6 2020 index.php
-rw-r--r--. 1 apache apache 19915 Jan 1 2021 license.txt
-rw-r--r--. 1 apache apache 7346 Jul 6 12:23 readme.html
drwxr-xr-x. 2 apache apache 4096 Oct 8 23:09 WordPress
-rw-r--r--. 1 apache apache 7165 Jan 21 2021 wp-activate.php
drwxr-xr-x. 9 apache apache 4096 Sep 9 02:20 wp-admin
If not, change files and directory ownership to the user and group Apache.
$ chown -R apache.apache /var/www/html/
Site can’t be reached
Check if the Apache webserver is up and running.
$ sudo service httpd status
Check if http and https traffic is allowed by the firewall.
$ sudo firewall-cmd --permanent --list-all
If not, open the https and http protocols for the web server to function well.
$ sudo firewall-cmd --permanent --zone=public --add-service=http
$ sudo firewall-cmd --permanent --zone=public --add-service=https
$ sudo systemctl reload firewalld
Congratulations, once WordPress is up and running on your web server, you can build and design dynamic websites on the world’s most popular content management system (CMS).