How to Install WordPress with Apache and Let’s Encrypt SSL on Debian 11

WordPress is the most popular content management system on the internet. It is free, open-source, and works well with almost any web hosting service, making it one of the easiest to install and use.

If you do not have web hosting yet, we recommend installing WordPress on your local Debian system or VPS.

Here, we will see how to install WordPress with Apache on Debian 11.

Prerequisites

Install LAMP Stack

Follow the below link to install the LAMP stack on your Debian system

Install AMP (Apache, MariaDB, and PHP) on Debian 11

Install PHP Extensions for WordPress

Use the apt command to install the PHP extensions required for a WordPress installation.

sudo apt install -y php-curl php-xml php-common php-imagick php-json php-mbstring php-mysql php-zip php-bcmath php-gd php-int

Configure PHP for WordPress

The default PHP values may not be appropriate for everyone and you may need to change them based on the requirement. So, edit the php.ini file.

sudo nano /etc/php/7.4/apache2/php.ini

Then, update the below values as per your requirement. You may start with the below values for now and increase or decrease the values at any time when required.

max_execution_time = 300

upload_max_filesize = 64M

post_max_size = 64M

Setup Apache Virtual Host

We will start with creating an Apache virtual host for a WordPress installation. You can find all Apache virtual host configuration files under /etc/apache2/sites-available directory.

Typically virtual host files contain a domain name, port number, document root, log location, fast CGI, etc.

Assume the following,

Domain name: www.itzgeek.net
Port No: 80
Document root: /var/www/html/www.itzgeek.net/

Create a virtual host configuration.

sudo nano /etc/apache2/sites-available/www.itzgeek.net.conf

Then, place the following content into the above configuration file. You will need to change ServerName as per your requirement.

<VirtualHost *:80>

   ServerName itzgeek.net
   ServerAlias www.itzgeek.net
   ServerAdmin admin@itzgeek.net
   DocumentRoot /var/www/html/www.itzgeek.net


   ErrorLog ${APACHE_LOG_DIR}/www.itzgeek.net_error.log
   CustomLog ${APACHE_LOG_DIR}/www.itzgeek.net_access.log combined


   <Directory /var/www/html/www.itzgeek.net>
      Options FollowSymlinks
      AllowOverride All
      Require all granted
   </Directory>

</VirtualHost>

Next, create a document root directory to place WordPress files.

sudo mkdir -p /var/www/html/www.itzgeek.net/

Enable the virtual host and SSL, rewrite modules.

sudo a2ensite www.itzgeek.net

sudo a2enmod rewrite ssl

Then, restart the Apache service.

sudo systemctl restart apache2

Install Let’s Encrypt SSL Certificate

Create DNS Record

Go to your domain registrar and create an A and CNAME (optional if you do not want to use www subdomain) record for your domain. Typically you will have to make two records for your WordPress website.

  1. Non-www Domain Name (Ex. itzgeek.net) >> A record point to your server IP
  2. www Domain Name (Ex. www.itzgeek.net) >> CNAME record point to itzgeek.net

For this demo, I will create two records so that my WordPress website will be accessible at www.itzgeek.net.

DNS Records

Install Certbot client

The Certbot client, which helps us generate and install the Let’s Encrypt SSL certificate, is now available as a snap package for Debian operating system. So, first, install snapd daemon on your system.

sudo apt update

sudo apt install -y snapd

Then, update snapd to the latest version.

sudo snap install core && sudo snap refresh core

Finally, install the Certbot client using the below command.

sudo snap install --classic certbot

sudo ln -s /snap/bin/certbot /usr/bin/certbot

Install SSL Certificate

Use the below command to generate and install the Let’s Encrypt SSL certificate on the Apache webserver.

sudo certbot --apache
1. Enter email address to receive notification on urgent renewal and security notices
2. Type Y and press Enter to register with the ACME server
3. Type Y or N to receive emails about EFF news, campaigns, and newsletters.
4. Certbot will automatically detect the WordPress domain and ask you permission to activate HTTPS for your WordPress website. Type 1 or appropriate numbers separated by a comma in case you have multiple websites.
Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: itzgeek.net
2: www.itzgeek.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1,2

Wait for the SSL installation to complete.

Redirect non-www HTTP requests to www HTTPS with Apache

The Certbot client will place the required rules to redirect the traffic from HTTP to the HTTPS website.

1. http://itzgeek.net >> https://itzgeek.net

2. http://www.itzgeek.net >> https://www.itzgeek.net

As you can see, the first domain is not reaching www HTTPS with rules placed by Certbot. So, you will have to add a rule manually to redirect traffic from non-www HTTP to www HTTPS domain if required, I.e., http://itzgeek.net >> https://www.itzgeek.net.

Auto-Renew SSL Certificate

The Certbot client comes with a systemd service that takes care of automated certificate renewals. So, you will not have to renew the certificates manually.

Install WordPress with Apache on Debian 11

Create WordPress Database

First, login into MariaDB/MySQL database server.

sudo mysql -u root -p

Then, create the database for WordPress installation along with the database user and password.

CREATE DATABASE wpdatabase;

CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'wppassword';

GRANT ALL PRIVILEGES ON wpdatabase.* TO 'wpuser'@'localhost';

EXIT

Download WordPress

Download the latest version of the WordPress files by using the following command.

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

Then, extract the downloaded file.

tar -zxvf latest.tar.gz

And then, move the files to your website document root directory.

sudo mv wordpress/* /var/www/html/www.itzgeek.net/

Update the ownership and a group of the WordPress directory.

sudo chown -R www-data:www-data /var/www/html/www.itzgeek.net/

Install WordPress

Open your browser and visit your WordPress website domain to perform the WordPress installation.

https://your-wordpress-website

1. Choose the Installation Language and click Continue

2. Click Let’s go!

3. Enter the WordPress database details and then click Submit

4. Click Run the installation

5. Enter the WordPress website information and then click Install WordPress

6. Click Log In to access the WordPress admin backend to manage WordPress installation. Alternatively, you can access the WordPress backend by going to https://your-wordpress-website/wp-admin

Access WordPress Website

Now, you will be able to access the site with your domain name.

https://your-wordpress-website
WordPress with Apache

Conclusion

That’s All. I hope you have learned how to install WordPress with Apache on Debian 11.

apachecmsdebian 11wordpress
Comments (0)
Add Comment