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.

precondition

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 example.com.
  • 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  How to install and configure MongoDB on CentOS 7

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:

EXIT;

Download

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

sudo mkdir -p /var/www/example.com

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

cd /tmp
wget https://wordpress.org/latest.tar.gz

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/example.com/

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/example.com

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/example.com.conf

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 example.com with your WordPress domain and set the correct path to the SSL certificate file.

sudo nano /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

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

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

  ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
  CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined

  # Pengaturan SSL
  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/example.com>
      Options FollowSymLinks
      AllowOverride All
      Require all granted
  </Directory>

</VirtualHost>

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  Tutorial using SFTP commands to transfer files

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.

conclusion

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

Source link

About wahyuway

Check Also

How to install and configure Anaconda on CentOS 7

How to install and configure Anaconda on CentOS 7

Anaconda is the most popular machine learning and data science tool used in large scale …

Leave a Reply