To install LAMP (Linux, Apache, MySQL, PHP) on Ubuntu 22.04, follow these steps:

 

Step 1: Update System Packages

Run the following commands to update package lists and install required dependencies:

sudo apt update && sudo apt upgrade -y

 

Step 2: Install Apache

 

sudo apt install apache2 -y

Check if Apache is running:

sudo systemctl status apache2

If not running, start and enable it:

sudo systemctl start apache2 sudo systemctl enable apache2

 

Step 3: Install MySQL (MariaDB)

 

sudo apt install mariadb-server -y

Secure MySQL installation:

sudo mysql_secure_installation

Follow the prompts to set up security settings.

 

Step 4: Install PHP

 

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

Check PHP version:

php -v

 

Step 5: Restart Apache

 

sudo systemctl restart apache2


After install LAMP, ports 80 and 443 should be accessible but If port 80 (HTTP) is accessible but port 443 (HTTPS) is not, follow these steps to troubleshoot and fix the issue:



Step 1: Check if Apache is Listening on Port 443

Run the following command to see if Apache is listening on port 443:

 

sudo ss -tlnp | grep ':443'

If there is no output, Apache is not configured to listen on port 443.


Step 2: Install SSL Module and Enable HTTPS

  1. Enable SSL module in Apache

 

sudo a2enmod ssl

 

  1. Restart Apache

 

sudo systemctl restart apache2


Step 3: Check Firewall Rules

If UFW (Uncomplicated Firewall) is enabled, allow port 443:

sudo ufw allow 443/tcp sudo ufw allow "Apache Full" sudo ufw reload

 

Then check the status:

sudo ufw status

Ensure Apache Full (which includes ports 80 & 443) is allowed.


Step 4: Check Apache Virtual Host Configuration

  1. Open the Apache SSL configuration file:

 

sudo nano /etc/apache2/sites-available/default-ssl.conf

Make sure it contains:

apache

<VirtualHost *:443>

ServerAdmin [email protected]

ServerName yourdomain.com

ServerAlias www.yourdomain.com

 

DocumentRoot /var/www/html

 

SSLEngine on

SSLCertificateFile /etc/letsencrypt/live/yourdomain.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain.com/privkey.pem </VirtualHost>

 

(Replace yourdomain.com with your actual domain and ensure SSL certificates exist.)

 

  1. Enable the SSL site:

 

sudo a2ensite default-ssl sudo systemctl restart apache2


Step 5: Install a Free SSL Certificate (If Needed)

If you don’t have an SSL certificate, install Let’s Encrypt with Certbot:

sudo apt install certbot python3-certbot-apache -y sudo certbot --apache

 

Follow the prompts to generate and install an SSL certificate.


Step 6: Test HTTPS Connection

Try accessing your website via:

 
 
arduino

 

https://yourdomain.com

or

 
 
arduino

 

https://your-server-ip

Was this answer helpful? 0 Users Found This Useful (0 Votes)