In this article, we are going to learn how to install WordPress on CentOS 8.
WordPress is a free and open-source content management system (CMS). It is written in PHP programming language, and it uses MySQL or MariaDB for the database. 60 million websites are using WordPress, and it comprises 33.6% of the top 10 million websites as of April 2019. It has more than 56,000 plugins available. WordPress is a nice choice for getting a website up and running fastly.
Preconditions to install WordPress
- A VPS or a local server on which CentOS 8 is running.
- You must log-in with a root user or a non-root user with sudo privilege.
- You must have installed LAMP (Linux, Apache, MySQL, and PHP) stack on your CentOS 8 server.
- Internet connection
If you don’t have installed LAMP stack then follow the link first LAMP stack installation on CentOS/RHEL 7/8.
When you complete the LAMP stack installation then you can follow the below steps.
Step 1: Creating a database
In the first step, we are going to create a database. WordPress uses MySQL or MariaDB to manage the database. As we have already installed the MariaDB as part of the LAMP stack, but here we need to create a database that will work with WordPress.
To login to the MySQL or MariaDB, as the root user. Use the below command.
mysql -u root -p
You will get a prompt for the password of the root account. This is the same password when you created your MySQL account. Once you will enter the password, it will give the MySQL command prompt.
We are using the below command to create a WordPress database with the name wordpress, but you can name it as you want.
CREATE DATABASE wordpress;
Note: Whenever you type any command on MySQL or MariaDB command prompt, it always ends with a semi-colon (;). So please make sure you have ended the commands with a semi-colon.
Step 2: Creating a user for wordpress database
As we have created a database with name wordpress and now we need to create a user who can manage this database. I am going to create a user with the name wpadmin and I will put the password as the password. You can create the user with any name and you can put the password as per your choice but make sure you do remember it for later use.
CREATE USER 'wpadmin'@'localhost' IDENTIFIED BY 'password';
Step 3: Granting permission to the newly created user
As per now, we have created a database with name wordpress and a user with the name wpadmin. This is the time to permit the database so the user wpadmin can access it.
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpadmin'@'localhost' IDENTIFIED BY 'password';
Note: You can replace anything in red with your database name, username, and password.
Step 4: Flushing the privileges
The user has access to the database. This is the time to let MySQL knows the recent privilege changes. So we are going to flush the privileges.
Once you will complete the above step, you can now exit from the MySQL database. Use the below command to exit.
You can now use the regular command prompt.
Step 5: Installation of the wget tool
Wget is a computer tool created by the GNU Project and You can use it to get content and files from various web servers. The name is a combination of the World Wide Web and the word get. It supports downloads via FTP, SFTP, HTTP, and HTTPS. If you have already installed wget then you can proceed to step 6 otherwise install the wget first.
sudo dnf install wget
Step 6: Installation of a PHP module
This is the PHP module which helps to resize the images for thumbnail. This is a necessary module. We can install it from the default repository of CentOS.
sudo dnf install php-gd
Restart the Apache service using the below command.
sudo systemctl restart httpd
Step 7: Installation of WordPress
As we have completed all the preconditions, now it is time to download the WordPress software package and install it. So let’s go in our home directory using the below command.
Use the below command to download the latest version of WordPress.
This command will download the latest WordPress software package in a compressed archive file. We are going to extract using tar.
tar xzvf latest.tar.gz
After extracting the file, you will get the new directory with the name wordpress in your home directory. Now we have to transfer these unpacked files in public_html so it can serve up the content for our website.
We have to use the same permission, for that reason we are going to use the rsync command.
sudo rsync -avP ~/wordpress/ /var/www/html/
We need to create a directory for WordPress to store the uploaded files. Use the below command for this.
Lastly, update the Apache permissions for new WordPress files.
sudo chown -R apache:apache /var/www/html/*
Step 8: Configuration of WordPress
Next, we have to update the wp-config.php file in WordPress, so it will connect to the database. So let’s go to the html folder where WordPress files are located.
Create a wp-config.php file by copying the sample file WordPress has provided.
cp wp-config-sample.php wp-config.php
Now, we need to edit the new wp-config.php file with the correct database information we created in step 2. I am using vim editors here but you can use it as per your preference.
Next, we need to add information into the following fields of the database, user, and password we created in Step 2.
After changing the value, i.e in red color. It will look like the below.
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define( 'DB_NAME', 'wordpress' ); /** MySQL database username */ define( 'DB_USER', 'wpadmin' ); /** MySQL database password */ define( 'DB_PASSWORD', 'password' );
And save it after pressing Esc key and then typing:wq for vim editors.
Step 9: Completing the installation using a web interface
As per this time, we have completed the wordpress configuration, now we can complete the installation using the WordPress web interface. Use your domain name or IP address to open the web interface.
For example, It is the http://192.168.43.164/wp-admin
Here, put your IP address, if you are creating it locally.
If you are getting this below page then you have successfully installed the WordPress. Now you have to fill all the information and then click to Install WordPress.
You will get a confirmation page like below,
To continue, hit the Log in button at the bottom, then fill your administrator account information, After logged into the account you can update or upload your website. That’s it.
In this tutorial, we learn how to install WordPress on CentOS 8. I hope, you understand but if you have any questions, you can ask in the comment section.
Also, read news about wordpress from wordpress website