How To Install WordPress On CentOS 7 With LAMP (Tutorial)

WordPress + LAMP is the classic web hosting setup.
Sure, there are other software stack options for hosting WordPress (some of our team is partial to LEMP). But in terms of wide implementation and usage for websites across the globe, nothing compares to WordPress with LAMP.
So today we'll show you how to get serve your website to the world by installing WordPress on CentOS 7 using a LAMP stack.
Want to install WordPress but not on CentOs?
👉Click here for our WordPress + Ubunbu 18.04 tutorial
👉Click here for our WordPress + Debian 9 tutorial
WordPress + LAMP: the most popular CMS and web server
WordPress is a powerhouse—over 34% of all websites online today use it—that’s over 22 million websites.
And for sites using a CMS (content management system), it towers over the competition with 60% of the market share.
Meanwhile, Apache (a key piece of the LAMP stack) is the world’s most popular web server.
So, you can see why having the WordPress/LAMP installation in your pocket is key for any developer or anyone looking to host their own blog or website.
How to install WordPress on CentOS 7 using a LAMP stack
In this tutorial, I will show you how to install WordPress with LAMP on Centos 7.
Prerequisites for installing WordPress on CentOS 7
Before we get started, you'll need to have the following set up:
- An instance of CentOS 7
- SSH access to the server
- User with sudo privileges.
- A good internet connection
With all the prerequisites in place, let’s dive in!
Step 1: Install the Remi repository
The latest version of WordPress requires PHP 7.3 or later, so you'll need to install the Remi repository first.
To achieve this, execute the command:
$ sudo yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
By default, CentOS 7 ships with PHP 5.4 which is no longer supported by developers and isn't compatible with the latest WordPress version (WordPress 5.2.2). So you'll need to disable PHP 5.4 using the yum config manager which is provided by the yum-utils tool.
To do this, first, install yum-utils
package.
$ sudo yum install yum-utils
Next, disable PHP 5.4.
$ sudo yum-config-manager --disable remi-php54
And now enable PHP 7.3 as shown.
$ sudo yum-config-manager --enable remi-php73
To verify that you have PHP 7.3 installed in your system, run the following command.
$ php -v
Sample output:
Step 2: Install LAMP stack
Since WordPress is both a front-end and back-end system and most of the administration will be done via browser, you need to install a LAMP stack to handle all that. LAMP is an acronym for Linux, Apache, MySQL, and PHP.
For this guide, I will use MariaDB which is a fork of MYSQL and provides superior performance.
To install the LAMP stack execute the command below.
$ sudo yum install httpd mariadb mariadb-server php php-common php-mysql php-gd php-xml php-mbstring php-mcrypt
With all the components installed, let’s start the Apache webserver.
$ sudo systemctl start httpd
To enable Apache on boot, run
$ sudo systemctl enable httpd
Next, you need to start the MariaDB database server. Run the command
$ sudo systemctl start mariadb
Again, to enable it on boot, run
$ sudo systemctl enable mariadb
By default, MariaDB does not provide protection against anonymous users. Therefore, we need to manually harden the security of the MariaDB server by running the following command.
$ sudo mysql_secure_installation
Answer all the questions with the security of the database server in mind. Be sure to disallow anonymous login and remote root login, and remove the test database. Finally, flush privileges for the changes to take effect.
Step 3: Create a database for WordPress
With MariaDB installed and secured, it's time to create a database to accommodate WordPress files during & after the installation.
Log in to the database server.
$ sudo mysql -u root -p
Create a database for WordPress.
CREATE DATABASE wordpressdb;
Query OK, 1 row affected (0.00 sec)
Next, create a user that will be associated with the WordPress database
CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'StrongPassword!';
Query OK, 0 rows affected (0.00 sec)
Next, grant all permissions to the user on the database
GRANT ALL ON wordpressdb.* TO 'wordpress_user'@'localhost';
Query OK, 0 rows affected (0.00 sec)
Finally, flush the privileges to save all the changes.
FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
To exit from the database server, run
EXIT;
Bye
To apply the changes, restart the MariaDB server by running the following command.
$ sudo systemctl restart mariadb
Step 4: Download WordPress
With the WordPress database already created, proceed and download the WordPress tarball from WordPress repository as shown.
$ cd /tmp && sudo wget http://wordpress.org/latest.tar.gz
This downloads the WordPress tarball in the /tmp directory
Next, extract the WordPress tarball file a shown.
$ sudo tar -xvf latest.tar.gz
This extracts the tarball into a folder labeled wordpress. This contains all the WordPress files that will be essential as we move along.Move the ‘WordPress’ folder to the Webroot directory /var/www/html a shown
$ sudo mv wordpress /var/www/html/
At this point, you need to change permissions of the WordPress folder to user ‘Apache’ as shown
$ sudo chown -R apache:apache /var/www/html/wordpress
Also, be sure to change file permissions as shown below
$ sudo chmod -R 755 /var/www/html/wordpress
Next, you need to create the upload directory manually as shown.
$ sudo mkdir -p /var/www/html/wordpress/wp-content/uploads
We need to give the Apache webserver rite permissions to the newly created uploads folder. This will enable Apache to create directories and files.
Issue the command below to accomplish this
$ chown -R :apache /var/www/html/wordpress/wp-content/uploads
Next, navigate to the WordPress directory.
$ cd /var/www/html/wordpress/
Proceed and rename the wp-config-sample.php to wp-config.php as shown:
$ mv wp-config-sample.php wp-config.php
Open the newly renamed file using your favorite text editor. I will be using the default editor Vim.
$ sudo vim wp-config.php
Scroll and locate the database settings as shown
Fill out the database details accordingly as defined when creating the WordPress database in Step 3 above.
In our case, the details are shown.
Save and exit the text editor.
Step 5: Run WordPress installation on your web browser
At this point, you’ve finished all the server configurations for your WordPress installation.
The final step is to complete the installation via a web browser.
To do this, launch your web browser and browser your server’s IP address or domain name
http://server_IP_address
or http://YOUR-DOMAIN
The first page will prompt you to select the language.
Click on your preferred language and hit the ‘Continue’ button.
In the next step fill in the additional information required such as ‘Site Name’, ‘Username’ , ‘Password’, and ‘Email address’.
Once you’ve filled in all the required fields, click on ‘Install WordPress’
If all went well, you will be directed to a "Success" page. Click the "Login" button to head to your login page.
Fill in your credentials to log in and you'll head to the world-famous WordPress dashboard that you see here:
You did it! You just installed WordPress on CentOS 7!
It's as simple as that-- if you've made it this far then, you’ve installed WordPress with LAMP on CentOS 7.
So, now you’re ready to get to work designing your new blog or website and creating some killer content for your visitors.
If you are just getting started with WordPress, the good news is that there are TONS of free resources for learning and customization. If you were able to install LAMP on your server and execute the WordPress setup, then WordPress itself should be a piece of cake!
Blazing fast WordPress hosting for $9.99/month?
If you finished this tutorial then you obviously already have a server…
But if you’d like to slash your hosting bill while boosting your performance stats, then you should consider the Performance VPS from SSD Nodes.
The Performance VPS features NVMe storage, which is like strapping a rocket engine to your CMS. Load media-heavy webpages up to 10x faster than with standard SSD drives.
And with high-resource plans, you can easily host multiple websites and scale your growth affordably.
You can get started for as little as $9.99/month for an 8GB RAM VPS.
Like what you saw? Subscribe to our weekly newsletter.
You're subscribed!