Step-by-Step Guide Configuring Apache Server + SSL for WordPress on Ubuntu 22.04

Step-by-Step Guide: Configuring Apache Server + SSL for WordPress on Ubuntu 22.04+

Guiding you through the process of installing the Apache web server and configuring it for hosting a WordPress website on Ubuntu 22.04. Apache is a highly popular and robust web server that is widely used for hosting websites. Its stability, flexibility, and extensive community support make it an excellent choice for hosting your WordPress site. Let’s dive into the technical steps required to set it up.

Step 1: Updating the System:

Before we begin, it is essential to update the system packages to ensure we have the latest versions. Open a terminal and execute the following commands:

sudo apt update
sudo apt upgrade

Step 2: Installing Apache:

Once the system is up to date, we can proceed with the installation of Apache. Execute the following command in the terminal:

sudo apt install apache2

During the installation process, you might be prompted to enter your password. Provide the necessary information to continue.

Step 3: Configuring Apache for WordPress:

After installing Apache, certain configurations need to be made to ensure it works seamlessly with WordPress.

a) Adjusting Firewall Settings:

By default, Ubuntu 22.04 comes with a firewall called UFW (Uncomplicated Firewall). We need to allow HTTP and HTTPS traffic so that our Apache server can be accessed by visitors. Execute the following commands:

sudo ufw allow 'Apache'
sudo ufw enable
b) Enabling the Required Apache Modules:

Certain Apache modules are necessary for WordPress to function correctly. Enable them by executing the following commands:

sudo a2enmod rewrite
sudo a2enmod headers
sudo a2enmod ssl
sudo systemctl restart apache2
c) Adjusting Apache Configuration:

Next, we need to make a few changes in the Apache configuration files. Open the default configuration file using a text editor:

sudo nano /etc/apache2/sites-available/000-default.conf

Within the <VirtualHost> block, add the following lines just before the closing </VirtualHost> tag:

<Directory /var/www/html/>
    AllowOverride All

Save and close the file.

Step 4: Installing PHP and Required Extensions:

WordPress relies on PHP to function. Therefore, we need to install it along with the necessary extensions. Execute the following command:

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

Step 5: Securing Apache with SSL/TLS:

To secure your website and encrypt data transmission, we can enable SSL/TLS. Let’s use Let’s Encrypt, a free and trusted certificate authority, to obtain an SSL certificate. Execute the following commands to install Certbot and obtain a certificate:

sudo apt install certbot python3-certbot-apache
sudo certbot --apache

Follow the on-screen instructions to generate and install the SSL certificate.

Step 6: Installing and Configuring MySQL:

WordPress requires a database to store its content. Install MySQL using the following command:

sudo apt install mysql-server

During the installation, you will be prompted to set a root password. Choose a strong password and remember it.

Step 7: Creating a MySQL Database and User:

Log in to the MySQL server using the root account you created:

sudo mysql -u root -p

Once inside the MySQL shell, create a new database and user for WordPress:

CREATE DATABASE wp_database;
GRANT ALL ON wp_database.* TO 'wp_user'@'localhost' IDENTIFIED BY 'your_password';

Make sure to replace ‘wp_database’, ‘wp_user’, and ‘your_password’ with your preferred values.

Step 8: Installing WordPress:

Now, it’s time to install WordPress. Download the latest version using the following commands:

cd /var/www/html
sudo wget
sudo tar -xzvf latest.tar.gz
sudo mv wordpress/* .
sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/

Step 9: Completing the Installation via Web Browser:

Open your preferred web browser and navigate to http://your_domain_or_IP. Follow the on-screen instructions to complete the WordPress installation, providing the necessary information such as database credentials.

Congratulations! You have successfully installed and configured Apache on Ubuntu 22.04 for hosting a WordPress website. By following this step-by-step guide, you have ensured that your website is secure, optimized, and ready to go. Now you can focus on creating engaging content and building a successful online presence with your WordPress site.

Leave a Comment

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

Scroll to Top