Detailed guide on setting up Apache, MySQL, and PHP for mydomain.com, secured with Let’s Encrypt SSL on a Linux VPS, with configurations for HTTP (port 80) and HTTPS ( port 443).

Prerequisites:

  • An EDIS Global Linux VPS (Ubuntu 20.04 recommended)
  • SSH root access to the VPS
  • A registered domain name pointing to your VPS’ IP address

Update your VPS

sudo apt update && sudo apt upgrade -y

Install Apache Web Server

sudo apt install apache2 -y

Configure Apache for mydomain.com Create a virtual host configuration for your domain:

sudo nano /etc/apache2/sites-available/mydomain.com.conf

Add the following:

<VirtualHost *:80>
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    DocumentRoot /var/wwpw/mydomain.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Save and exit the editor.

Enable the configuration and restart Apache:

sudo a2ensite mydomain.com.conf
sudo systemctl restart apache2

Install MySQL Database Server

sudo apt install mysql-server -y

Secure MySQL Installation Run the security script:

sudo mysql_secure_installation

Install PHP

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

Install Certbot for SSL

sudo apt install certbot python3-certbot-apache -y

Obtain Let’s Encrypt SSL Certificate for mydomain.com

sudo certbot --apache -d mydomain.com -d www.mydomain.com

Certbot will automatically configure the Apache virtual host for SSL (port 443).

Confirm Port 443 Configuration

Your configuration should have been updated to include a <VirtualHost _:443> block for SSL. Confirm by:

cat /etc/apache2/sites-available/mydomain.com-le-ssl.conf

Automatic Certificate Renewal

sudo systemctl enable certbot.timer
sudo systemctl start certbot.timer

Test renewal:

sudo certbot renew --dry-run

Finalize Configuration & Restart Apache

sudo systemctl restart apache2

Your domain mydomain.com is now configured on Apache with MySQL and PHP, utilizing ports 80 (HTTP) and 443 (HTTPS/SSL) with a secure SSL certificate from Let’s Encrypt.