close up shot of a typewriterCMS Ubuntu wordpress 

Setting Up WordPress on Ubuntu with Apache2, MySQL, and SSL

Ubuntu is a great hosting environment choice if you want to build a strong and secure WordPress website. In this tutorial, we’ll show you how to install WordPress, Apache, MySQL, and SSL encryption on a server running Ubuntu. You’ll have a fully operational WordPress site with HTTPS enabled by the end of this lesson.

Step 1: Install Apache Server

To start, let’s install the Apache web server on your Ubuntu server:

sudo apt update
sudo apt install apache2

Apache will serve as the web server for your WordPress site.

Step 2: Install PHP and MySQL Connector

WordPress is built on PHP, and it requires a MySQL database. Install PHP and the PHP MySQL connector with the following commands:

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

Step 3: Install MySQL Server

MySQL is the database management system that WordPress will use to store your website’s data. Install MySQL Server:

sudo apt install mysql-server

Step 4: Login to MySQL Server

Once MySQL is installed, log in to the MySQL server as the root user:

sudo mysql -u root

Check out below article to install PHPMyAdmin for MySQL if needed

How to Install Phpmyadmin in ubuntu.

Step 5: Change the Authentication Plugin and Password

For improved security, change the authentication plugin for the root user to mysql_native_password and set a strong password:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'YourStrongPassword';

Replace 'YourStrongPassword' with your desired password.

Step 6: Create a New Database User

Now, create a new MySQL user for WordPress and set a strong password:

CREATE USER 'wp_user'@localhost IDENTIFIED BY 'YourStrongPassword';

Step 7: Create a Database for WordPress

Create a new database that WordPress will use:

CREATE DATABASE wordpressDB;

Step 8: Grant Privileges

Grant all privileges on the ‘wp’ database to the ‘wp_user’ you created earlier:

GRANT ALL PRIVILEGES ON wordpressDB.* TO 'wp_user'@localhost;

Step 9: Download WordPress

Navigate to the /tmp directory and download the latest version of WordPress:

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

Step 10: Unzip WordPress

Unzip the downloaded WordPress archive.

tar -xvf latest.tar.gz

Step 11: Move WordPress Files

Move the WordPress files to the Apache document root:

sudo mv wordpress/ /var/www/html

Step 12: Restart Apache

To apply the changes, restart the Apache web server:

sudo systemctl restart apache2

Alternatively, you can use sudo systemctl reload apache2 to reload the configuration.

Also Read:  How to enable permalinks in WordPress - Ubuntu Apache2

Follow the link below to configure the Apache site, which will help in configuring your IP address to the domain. This will also assist in configuring WordPress permalinks.
https://getcodify.com/how-to-enable-permalinks-in-wordpress-ubuntu-apache2/

Step 13: Install Certbot

Let’s secure your website with SSL encryption. Install Certbot to simplify the process:

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

Step 14: Request and Install SSL Certificate

Use Certbot to request and install an SSL certificate for your site:

sudo certbot --apache

Follow the prompts to configure SSL for your domain. Once the process is complete, your WordPress site will be accessible via HTTPS, ensuring data encryption and security.

In some hostings, by default, Http/Https might not be enabled. To allow traffic on ports 80 (HTTP) and 443 (HTTPS) through the Ubuntu firewall (UFW), follow these additional steps:

Step 15: Enable UFW for Ports 80 and 443

Ubuntu comes with the Uncomplicated Firewall (UFW) tool, which simplifies the process of managing your server’s firewall rules.

15.1: Check UFW Status

First, check the status of UFW to ensure it’s installed and inactive:

sudo ufw status

#If UFW is not installed, you can install it with:

sudo apt install ufw

15.2: Allow HTTP (Port 80/443)

To enable incoming HTTP traffic on port 80, run the following command:

#port 80
sudo ufw allow 80/tcp

#port 443
sudo ufw allow 443/tcp

15.3: Enable UFW

Enable UFW to activate the firewall with the new rules:

#Enable UFW
sudo ufw enable

#Check status
sudo ufw status

You should see the rules for ports 80 and 443 as “ALLOW.” Your server is now configured to allow incoming web traffic on these ports while maintaining a basic level of security.

Related posts