> ## Documentation Index
> Fetch the complete documentation index at: https://docs.edisglobal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Installing Apache, MySQL, PHP, and SSL on Linux VPS

> Set up Apache, MySQL, and PHP for a custom domain on a Linux VPS, secured with a Let's Encrypt SSL certificate using Certbot on ports 80 and 443.

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).&#x20;

**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**

```shell theme={"system"}
sudo apt update && sudo apt upgrade -y
```

**Install Apache Web Server**

```shell theme={"system"}
sudo apt install apache2 -y
```

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

```shell theme={"system"}
sudo nano /etc/apache2/sites-available/mydomain.com.conf
```

Add the following:

```powershell theme={"system"}
<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:

```shell theme={"system"}
sudo a2ensite mydomain.com.conf
sudo systemctl restart apache2
```

**Install MySQL Database Server**

```shell theme={"system"}
sudo apt install mysql-server -y
```

**Secure MySQL Installation**
Run the security script:

```shell theme={"system"}
sudo mysql_secure_installation
```

**Install PHP**

```shell theme={"system"}
sudo apt install php libapache2-mod-php php-mysql -y
```

**Install Certbot for SSL**

```shell theme={"system"}
sudo apt install certbot python3-certbot-apache -y
```

**Obtain Let's Encrypt SSL Certificate for mydomain.com**

```shell theme={"system"}
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:

```shell theme={"system"}
cat /etc/apache2/sites-available/mydomain.com-le-ssl.conf
```

**Automatic Certificate Renewal**

```shell theme={"system"}
sudo systemctl enable certbot.timer
sudo systemctl start certbot.timer
```

Test renewal:

```shell theme={"system"}
sudo certbot renew --dry-run
```

**Finalize Configuration & Restart Apache**

```shell theme={"system"}
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.
