How to install WordPress with Apache on CentOS 7

WordPress is by far the most popular open source blogging platform and CMS platform. WordPress is powered by more than a quarter of the world’s websites.

WordPress is based on PHP and MySQL and has a lot of features that can be extended with free and premium plugins and themes. WordPress allows you to easily create your own e-commerce website, portfolio or blog.

In this tutorial, we’ll show you how to install WordPress on CentOS 7. It’s a fairly easy process that takes about ten minutes to complete. At the time of writing this article, the latest version of WordPress is version 5.0.2.

We will be using a LAMP package with Apache as a web server, an SSL certificate, the latest PHP 7.2, and MySQL/MariaDB as a database server.


Make sure you meet the following prerequisites before proceeding with this tutorial:

  • You have a domain pointing to your server’s public IP. As an example we will use it
  • Log in as a user with sudo privileges.
  • Apache is installed and configured by following these instructions.
  • PHP 7.2 or 7.3 installed following these instructions.
  • You have an SSL certificate installed for the domain. If you don’t already have one, you can install Let’s Encrypt’s free SSL certificate by following these instructions.

Create MySQL databases

WordPress uses a MySQL database to store all of its data. We will start by creating a MySQL database, a MySQL user account, and granting access to the database.

If you haven’t installed MySQL or MariaDB on your CentOS server, you can do so by following one of the guides below:

  • Install MySQL on CentOS 7
  • Install MariaDB on CentOS 7
See also  An Introduction to Uname Commands on Linux

Log into the MySQL shell by typing the following command:

sudo mysql

From within the MySQL shell, run the following SQL statement to create the database:

CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

Next, create a MySQL user account and grant database access rights:

GRANT ALL ON wordpress.* TO 'userwordpressdb'@'localhost' IDENTIFIED BY 'ganti-dengan-password';

Finally, exit the mysql console by typing:



Before downloading the WordPress archive, first create a directory containing all the WordPress files:

sudo mkdir -p /var/www/

The next step is to download the latest version of WordPress from the WordPress download page using the following wget command:

cd /tmp

Once the download is complete, extract the archive and move the extracted files to the root directory of the domain document:

tar xf latest.tar.gzsudo mv /tmp/wordpress/* /var/www/

Set the correct permissions so that the web server can have full access to the site’s files and directories with the following chown command:

sudo chown -R www-data: /var/www/

Apache configuration

Now, you should have Apache with SSL Certificate installed on your system, if not, please check the prerequisites for this tutorial.

The next step is to edit the Apache virtual host configuration for the WordPress domain:

sudo nano /etc/httpd/conf.d/

The following redirects to configure Apache http to me https And the www to issue non-www From your domain and enable HTTP2. Don’t forget to replace with your WordPress domain and set the correct path to the SSL certificate file.

sudo nano /etc/httpd/conf.d/
<VirtualHost *:80>

  Redirect permanent /

<VirtualHost *:443>

  Protocols h2 http:/1.1
# Pengaturan WWW ke NON-WWW
  <If "%{HTTP_HOST} == ''">
    Redirect permanent /

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

  ErrorLog ${APACHE_LOG_DIR}/
  CustomLog ${APACHE_LOG_DIR}/ combined

  # Pengaturan SSL
  SSLEngine On
  SSLCertificateFile /etc/letsencrypt/live/
  SSLCertificateKeyFile /etc/letsencrypt/live/
  SSLCertificateChainFile /etc/letsencrypt/live/

  <Directory /var/www/>
      Options FollowSymLinks
      AllowOverride All
      Require all granted


The above configuration will tell Apache to redirect http to me https And the www to me non-www.

For the new configuration to take effect, restart the Apache service by typing:

sudo systemctl restart httpd

Finish installing WordPress

Now that you’ve downloaded WordPress and the server configuration is complete, it’s time to complete the installation of WordPress via the web interface.

See also  tmux Tutorial

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

Install WordPress CentOS

Select the language you want to use and click the Continue button.

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

Install CentOS WordPress informationOn the next screen, the installer will ask you to enter your database connection details. Enter the MySQL user data and the database you created earlier. and click send after it ends.

Install WordPress

Start your WordPress installation with just one click Run the install.

Install WordPress centOS Run the installation

In the next step, you will need to enter a name for your WordPress site and choose a username. For security purposes, do not use the words “admin” or “administrator” or any words found in the dictionary attack.

The installer will automatically generate a strong password for you. Don’t forget to save this password. You can also set your own password.

Enter your email address and choose whether to prevent search engines from indexing the site (not recommended).

Welcome to install WordPress

click Install WordPress Once the installation is complete, you will be taken to a page telling you that WordPress is installed.

To get to the WordPress login page, click on the button Log in.

Full WordPress installation

Enter your username and password.

WordPress login forms

You will be redirected to the WordPress admin dashboard.

WordPress dashboard

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


Congratulations, you have successfully installed WordPress with Apache on your CentOS 7 server.

Source link