Set Up a Secure WordPress Site with Apache and Let’s Encrypt – Ubuntu

We’ll start by setting up Apache, one of the most reliable and widely used web servers to host your site. Next, we will install WordPress, the world’s leading content management system, known for its flexibility and ease of use. Finally, we will secure your website with Let’s Encrypt, a free, automatic and open source certificate license, to ensure that your website is secured with HTTPS encryption. By the end of this guide, you’ll have a secure and professional looking WordPress site, ready to go live and provide a secure experience for your visitors. Let’s dive in and start building your own secure WordPress website.

Apache

Install Apache

Check whether if its up and running

Check service status whether if its in active (running) state

You can also check by visiting the below URL, make sure to replace server_ip with localhost or your server ip address

You should see “Apache2 Default Page” if it works

Creating Domain

Go to your hosting provider’s website and go to your domain’s DNS records and create an A record giving a suitable Name for your domain and pointing to <server_ip>.

Setting Up Directory

Create website directory. Make sure to replace <domain_name> with your own domain name at all places.

Change owner permissions and set correct permissions

Create a test file for you to display as the web page

And add the following and save it

Setting Up Virtual Host File

Create virtual host file at /etc/apache2/sites-available/<domain_name>.conf

And add the following and save it.

Enable Site

Make sure you are in that apache virtual host file directory

Disable Default Site

Test for Configuration Errors

If there aren’t any errors you should receive the below output

Restart Apache to save the changes you made

Now you should be able to see the below output on your site at http://<domain_name>

Let’s Encrypt

Install Certbot

You’ll need to install Certbot to get SSL certificate with Let’s Encrypt

Obtain SSL Certificate

Run the below command to use apache plugin with certbot

Then you’ll be asked for an email address for renewal purposes

Enter y to agree to their Terms of Services

Next you can either select y or n to share your email with Electronic Frontier Foundation

Now you’ll see the list of domain names, select the numbers of the domain names which you need to activate HTTPS for and Enter

And then it’ll activate and issue Lets Encrypt certificate for your domains

If everything went as it should be, you must be able to access your domain with https://<domain_name>

WordPress

MySQL Configurations

First of all we’ll start by installing mysql server and client and also needed php packages

Run the below command to secure our database engine

MySQL will connect using blank password by default and select if you want the VALIDATE PASSWORD component or not

Select whether to remove anonymous users or not

Select whether to disallow root login remotely or not

Select to whether to remove test database and access of it or not

Select whether to reload privilege tables or not

And then that step would be All Done!

Now lets login to MySQL and run some queries

Create Database for wordpress

Now create a user on that database replacing your_password with your password

Next grant all privileges for that user on the database we created

Now run the following to exit

Run the below commands to download and extract the wordpress package on our website directory

Change the ownership and permission of the wordpress folder

Now your should see WordPress installation wizard on https://<domain_name>/wordpress

WordPress Installation

Select preferred language

Click Let’s Go to configure wp-login.php file

Fill the fields with relevant records you configured in MySQL earlier

You should see the below output if everything is correct, now click Run the installation to proceed to next step

Fill the relevant fields as per your requirements, remember to save the Username and Password and click Install WordPres

Proceed to the Log in page by clicking Log In

Log In with the credentials you gave earlier

You should see the following Dashboard if the credentials are correct

And yeah that sums up our tutorial, hope you followed along till the end. Explore your dashboard and enjoy!

We value your input. Share your thoughts or ask questions by leaving a comment down below.

Umar Arafath

Hey there! I'm Umar Arafath, the face behind unofficialmentor, a passionate Software Engineering undergraduate diving into the IT industry. Even though my formal title may be a student, my heart lies in the field of DevOps. I share my daily learning adventures in this blog so it'll help me remember stuff. It's a win-win end of the day, I reinforce my knowledge, and you learn something new. Please be kind enough to leave a comment! Your feedback fuels my growth. Away from the desk, catch me on the cricket field or badminton court, polishing my physique. I'm also a motorbike enthusiast, who finds riding as a healing spell for my inner peace.

Leave a Reply

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