host-wordpress-on-apache host-wordpress-on-apache

A Beginner’s Guide to Hosting WordPress on Apache Server

If you have a Linux server you can host a WordPress site with the Apache web server. In this post, we will show you how you can host WordPress on Apache server in Linux. In this post, we will use Ubuntu.

The first step first is installing Apache on your Linux server. And I will show you the whole process step by step.

Step 1: Install Apache Server

To install Apache Server on Ubuntu, open the terminal window and type the following command:

sudo apt-get update
sudo apt-get install apache2

The first command will update your system and the 2nd one will install Apache Server.

Step 2: Install PHP

To install PHP on your server, type the following command:

sudo apt-get install php libapache2-mod-php php-mysql

This command will install PHP and the necessary modules to work with Apache Server for WordPress.

Step 3: Install MySQL

MySQL will be needed to make the Database connection. To install MySQL write this command:

sudo apt-get install mysql-server

Step 4: Install WordPress

To install WordPress in your server, you will need to download the latest version of WordPress from the official website. You can do this by typing in the following command in a terminal window:

cd /var/www/html/
sudo wget https://wordpress.org/latest.tar.gz

This command will download the latest version of WordPress to the /var/www/html/ directory. Next, you need to extract the downloaded file using the following command:

sudo tar -xzvf latest.tar.gz

This command will extract the contents of the downloaded file to a new directory called wordpress. You can rename it by this command if you wants to:

sudo mv wordpress/ serverguy

Here the wordpress/ is the wordpress directory and the serverguy is the name I want to give it, you can change it as you want.

Step 5: Configure WordPress

To configure WordPress, you need to create a new MySQL database and a user. You can do this using the following command:

sudo mysql -u root -p

This command will open the MySQL console. Once you are in the console, type in the following commands to create a new database and user:

CREATE DATABASE serverguy;
CREATE USER 'svrguyuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON serverguy.* TO 'svrguyuser'@'localhost';
FLUSH PRIVILEGES;
exit

Here the password is your password and change the database and the user name as you want. So, replace ‘password’ with a strong password of your choice.

Next, you need to rename the WordPress configuration file (wp-config-sample.php) to wp-config.php and edit it to add the database details. You can do this using the following commands:

cd /var/www/html/serverguy
sudo mv wp-config-sample.php wp-config.php
sudo nano wp-config.php

This command will open the wp-config.php file in the nano text editor, you can open it with other text editors you want such as vim. Scroll down to the section that says “MySQL settings” and add the database details as follows:

define('DB_NAME', 'serverguy');
define('DB_USER', 'svrguyuser');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');

Save and exit the file by pressing Ctrl+X, then Y, then Enter.

Step 6: Configure Apache Server

To configure Apache Server to work with WordPress, you need to create a new virtual host file. You can do this using the following command:

sudo nano /etc/apache2/sites-available/wordpress.conf

This command will create a new file called wordpress.conf in the sites-available directory, “you can change the name as you want” and open it in the nano text editor. Add the following code to the file:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/html/serverguy/
    ServerName serverguy.dev
    ServerAlias www.serverguy.dev

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

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log
</VirtualHost>

Replace serverguy.dev with your domain name and root directory /var/www/html/serverguy/ to your directories name.

Save and exit the file by pressing Ctrl+X, then Y, then Enter.

Next, enable the new virtual host and restart Apache Server using the following commands:

sudo a2ensite wordpress.conf
sudo systemctl restart apache2

Step 7: Install SSL Certificate (Optional)

To install an SSL certificate and enable HTTPS for your website, you can use Let’s Encrypt, it’s a free and open certificate authority. To install Let’s Encrypt, type in the following command in the terminal window:

sudo apt-get install certbot python3-certbot-apache

Run this command to obtain and install SSL certificate:

sudo certbot --apache

Follow the prompts which will ask by Certbot like Name, Email, etc. to obtain and install the SSL certificate. Once the certificate is installed, restart Apache Server using the following command:

sudo systemctl restart apache2

Step 8: Finish the WordPress Installation

To finish the installation, open a web browser and navigate to your domain name. You should see the WordPress installation screen. Follow the prompts to complete the installation. It will ask site name, username, password and admin email. And don’t forget to point your domain to the hosting server. Happy Hosting!

Leave a Reply

Your email address will not be published. Required fields are marked *

Contabo opens DC in Singapore