How to Install WordPress with Apache on CentOS 7

Updated 

4 min read

WordPress is the most popular open source blogging and CMS platform worldwide, powering a quarter of all websites on the Internet today. It is based on PHP and MySQL and packs a ton of features that can be extended with free and premium plugins and themes. WordPress is the simplest way to create your online store, website, or blog.

In this tutorial, we will explain how to install WordPress on CentOS 7. At the time of writing this article, the latest version of WordPress is version 5.0.3.

We'll be using a LAMP stack with Apache as a web server, SSL certificate, the latest PHP 7.2 and MySQL/MariaDB as a database server.

Prerequisites

Ensure the following prerequisites are met before continuing with this tutorial:

Creating MySQL Database

WordPress stores its data and configuration in a MySQL database. If you already don't have MySQL or MariaDB installed on your CentOS server you can install by following one of the guides below:

Login to the MySQL shell by executing the following command:

mysql -u root -p

From within the MySQL shell, run the following SQL statement to create a new database named wordpress:

CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

Next, create a MySQL user account named wordpressuser and grant the necessary permissions to the user by running the following command:

GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'change-with-strong-password';

Once done, exit the mysql console by typing:

EXIT;

Downloading Wordpress

The following command will download the latest version of WordPress from the WordPress download page with wget and extract the archive to the domain's document root directory:

wget -q -O - "http://wordpress.org/latest.tar.gz" | sudo tar -xzf - -C /var/www/html --transform s/wordpress/example.com/

Set the correct permissions so that the web server can have full access to the site's files and directories:

sudo chown -R apache: /var/www/html/example.com

Configuring Apache

By now, you should already have Apache with SSL certificate installed on your system, if not check the prerequisites for this tutorial.

Open your text editor and edit the domain's Apache virtual hosts configuration:

sudo nano /etc/httpd/conf.d/example.com.conf

Don’t forget to replace example.com with your Wordpress domain and set the correct path to the SSL certificate files.

/etc/httpd/conf.d/example.com.conf
<VirtualHost *:80>
  ServerName example.com
  ServerAlias www.example.com

  Redirect permanent / https://example.com/
</VirtualHost>

<VirtualHost *:443>
  ServerName example.com
  ServerAlias www.example.com

  <If "%{HTTP_HOST} == 'www.example.com'">
    Redirect permanent / https://example.com/
  </If>

  DirectoryIndex index.html index.php
  DocumentRoot /var/www/html/example.com

  ErrorLog /var/log/httpd/example.com-error.log
  CustomLog /var/log/httpd/example.com-access.log combined

  SSLEngine On
  SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
  SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem

  <Directory /var/www/html/example.com>
      Options FollowSymLinks
      AllowOverride All
      Require all granted
  </Directory>

</VirtualHost>

The configuration will tell Apache to redirects http to https and www to non-www version of your domain.

Restart the Apache service for the changes to take effect:

sudo systemctl restart httpd

Completing the WordPress Installation

Now that Wordpress is downloaded and the Apache server is configured, you can finish the installation through the web interface.

Open your browser, type your domain and a screen similar to the following will appear:

Select the language you would like to use and click on the Continue button.

Next, you will see the following information page, click on the Let's go! button.

On the next screen, the setup wizard will ask you to enter your database connection details. Enter the MySQL user and database details you previously created.

Start the WordPress installation by clicking on the Run the Installation button.

In the next step, you'll need to enter a name for your WordPress site and choose a username (for security purposes do not use “admin” ).

The installer will automatically generate a strong password for you. Do not forget to save this password. You can also set the password by yourself.

Enter your email address and select whether you want to discourage search engines from indexing the site (not recommended).

Click Install WordPress and once the installation is completed you will be taken to a page informing you that WordPress has been installed.

To access your WordPress login page click on the Log in button.

Enter your username and password.

You will be redirected to the WordPress administration dashboard.

From here you can start customizing your WordPress installation by installing new themes and plugins.

Conclusion

Congratulations, you have successfully installed WordPress with Apache on your CentOS 7 server. First Steps With WordPress is a good starting place to learn more about how to get started with WordPress.

If you have questions feel free to leave a comment below.