
WordPress is an open source and free blogging application and a dynamic CMS (Content Management System) developed using MySQL and PHP. It has huge number of third party plugins and themes. WordPress currently one of the most popular blogging platform available on the internet and used by millions of people across the globe.
In this tutorial we are going to explain how to install the popular content management system – WordPress using LAMP (Linux, Apache, MySQL/MariaDB, PHP) on RHEL, CentOS Linux distributions.
Enabling Remi repository
PHP 7.x packages are available in several different repositories. We’ll use the Remi repository which provides newer versions of various software packages including PHP.
The Remi repository depends on the EPEL repository. Run the following commands to enable both EPEL and Remi repositories:
# yum -y install epel-release yum-utils # yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Yum may prompt you to import the repository GPG key. Type y and hit Enter.
In the following sections, we will be covering how to install PHP 7.x by enabling the appropriate Remi repository. If you already have PHP 5.4 installed on your system yum will update the PHP packages.
Installing PHP 7.3 on CentOS 7
PHP 7.3 is the latest stable release of PHP. Most modern PHP frameworks and applications including WordPress, Drupal, Joomla, and Laravel are fully supporting PHP 7.3.
Perform the steps below to install PHP 7.3 on CentOS 7.
Step 01. Start by enabling the PHP 7.3 Remi repository:
# yum-config-manager --enable remi-php73
Step 02. Install PHP 7.3 and some of the most common PHP modules:
# yum -y install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd
Step 03. Verify the PHP installation, by typing the following command which will print the PHP version:
# php -v
Output:
PHP 7.3.16 (cli) (built: Mar 17 2020 10:18:38) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.16, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.16, Copyright (c) 1999-2018, by Zend Technologies
Installing LAMP Stack on CentOS 7
Now we are ready to install all the required packages related to our LAMP stack using following command.
# yum -y install httpd mariadb mariadb-server php php-common php-mysql php-gd php-xml php-mbstring php-mcrypt
Now that the installation is complete, we will need to start and secure our MariaDB installation.
# systemctl start mariadb
Then we will configure MariaDB to start automatically on system boot:
# systemctl enable mariadb
Follow the instructions on the screen to answer the questions related to your MariaDB server security.
# mysql_secure_installation
Next we will do the same for Apache web server:
# systemctl start httpd # systemctl enable httpd
Creating WordPress MySQL Database
Our WordPress will require a database and a database user. To create one, simply use the following commands. Feel free to replace the database name, user and password as per your preferences:
# mysql -u root -p Enter password: ## Create database ## CREATE DATABASE wp_database; ## Creating new user ## CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'wp_password'; ## Grant privileges to database ## GRANT ALL ON wp.* TO 'wp_user'@'localhost'; ## FLUSH privileges ## FLUSH PRIVILEGES; ## Exit ## exit
Preparing WordPress Installation
Now we are ready to download the latest WordPress archive:
# cd /var/www/html/ && wget https://vi.wordpress.org/latest-vi.tar.gz
Next extract the archive in our web directory:
# tar -xvzf latest.tar.gz -C /var/www/html
Now change the ownership of that directory:
# cd /var/www/html # chmod 777 -R wp-admin/ # chmod 777 -R wp-content/ # chmod 777 -R wp-includes/
Open wp-config.php with your favorite text editor:
# vi wp-config.php
Now change the parameter of that file:
// ** Thiết lập MySQL - Bạn có thể lấy các thông tin này từ host/server ** // /** Tên database MySQL */ define('DB_NAME', 'wp'); /** Username của database */ define('DB_USER', 'wp_user'); /** Mật khẩu của database */ define('DB_PASSWORD', 'wp_password');
Open /etc/httpd/conf/httpd.conf with your favorite text editor:
# vi /etc/httpd/conf/httpd.conf
And add the following code at the bottom of the file and replace the marked text with the information related to your installation:
From: #ServerName www.example.com:80 To: ServerName your-domain:80
and
From: DirectoryIndex index.html To: DirectoryIndex index.php index.html
Save your changes and start Apache:
# systemctl start httpd # systemctl enable httpd
Installing WordPress on Website
Now we are ready to run our WordPress installation. To start the installation you can access either your server’s IP address at http://ip-address or if installing locally you can use http://localhost or if you are using a real domain, you can use the domain instead.