Introduction
WordPress is a free and open-source content management system (CMS) with a plugin architecture and customizable themes. The PHP-based platform is usually paired with a MySQL or MariaDB database and was originally designed for publishing blogs. It is available for free and considered easy to install, configure, and uses. This article explains how to install WordPress on CentOS.
Prerequisites
- A root or non-root user with
sudo
privileges. - A LAMP stack includes the Linux operating system, the Apache web server, MySQL, and the PHP programming language.
If the LAMP stack is not installed, then just follow the below steps to install LAMP on Ubuntu.
Install Apache
- Run the below command on the terminal to install httpd Apache package.
sudo yum install httpd
- Once the installation is complete, start the Apache server with the below command.
sudo systemctl start httpd
sudo systemctl enable httpd
Install MySQL
On the CentOS server, MySQL is substituted by MariaDB. MariaDB uses the same commands and database queries with almost no difference from MySQL.
- To install MariaDB on CentOs, run the following command.
sudo yum install mariadb-server
- Next, enable and start the database server.
sudo systemctl start mariadb
sudo systemctl enable mariadb.service
Install PHP
Note: By default CentOS 7 officially have a PHP 5.4 package that has reached the end of its life. for the latest version of PHP on the CentOS 7 System follow the below commands.
-
install and enable EPEL and Remi repository on CentOS 7 system.
# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm # yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
-
Next, install yum-utils.
yum install yum-utils
-
Configure and enable the latest versions of PHP.
yum-config-manager --enable remi-php72
- Run the below command on the terminal to install PHP and its dependencies.
sudo yum install php php-mysql php-gd
- Restart the Apache web server to enable the PHP module.
sudo systemctl restart httpd.service
Install WordPress
After fully configuring the LAMP. now the system is ready to install and configure WordPress follow the below instruction to download and install WordPress.
-
- Install wget package using the yum command.
sudo yum install wget
- Run the below command on the terminal to download
WordPress
packages.wget http://wordpress.org/latest.tar.gz
- Run the following command to Uncompress the tarball which will generate a folder called.
wordpress
.sudo tar -xzvf latest.tar.gz
- Now, move the extracted file contents to /var/www/html.
sudo rsync -avP ~/wordpress/ /var/www/html/
- Next, create a
wp-config.php
file by copying thewp-config-sample.php
file.sudo cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php
-
Run commands to change file permissions of the
wordpress
folder.
sudo chown -R apache.apache /var/www/html/*
chmod 755 -R /var/www/html/* -
Create WordPress Database.
WordPress uses MySQL to manage and store site and user information so need to create a database and user for WordPress.
-
Login into MySQL shell using the below command.
mysql -u root
-
Create a database for a WordPress installation.
CREATE DATABASE wordpress;
-
Create a new database user and assign it a password.
CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';
-
Now, grant the user full rights to the new WordPress database.
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password';
-
Flush the privileges
FLUSH PRIVILEGES:
-
Exit from MySQL
exit
-
-
After creating the database and user for WordPress configure the database details in the wpconfig.php file. Run the below command to open the
wp-config.php
file and update the DB_NAME, DB_USER, DB_PASSWORD fields as show in below image.
vi /var/www/html/wp-config.php
- Restart the Apache server.
sudo systemctl restart httpd
-
Open your browser and go to the server’s URL and replace "server-ip" with your system IP in the below URL.
http://<server-ip>/wp-admin
- Follow the on-screen instructions to create a WordPress user.
- Once the WordPress installation is complete, click on login to access your site’s administrative login page.
- Authenticate with the user credentials and start accessing WordPress.
- Install wget package using the yum command.