LAMP stack on Ubuntu 20.04 – Cheat Sheet

Introduction

A “LAMP” stack is a group of open source software that is typically installed together in order to enable a server to host dynamic websites and web apps written in PHP. This term is an acronym which represents the Linux operating system, with the Apache web server. The site data is stored in a MySQL database, and dynamic content is processed by PHP.

Step 1 — Installing Apache and Updating the Firewall

In this guide, you’ll set up a LAMP stack on an Ubuntu 20.04 server.

sudo apt update
sudo apt install apache2
sudo ufw app list
sudo ufw app list
sudo ufw allow in "Apache"
sudo ufw status
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

Step 2 — Installing MySQL

sudo apt install mysql-server
sudo mysql_secure_installation
sudo mysql
exit

Step 3 — Installing PHP

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

Step 4 — Creating a Virtual Host for your Website

sudo mkdir /var/www/your_domain
sudo chown -R $USER:$USER /var/www/your_domain
sudo nano /etc/apache2/sites-available/your_domain.conf
<VirtualHost *:80>
    ServerName your_domain
    ServerAlias www.your_domain 
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/your_domain
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
sudo a2ensite your_domain
sudo a2dissite 000-default
sudo apache2ctl configtest
sudo systemctl reload apache2
sudo nano /etc/apache2/mods-enabled/dir.conf
<IfModule mod_dir.c>
        DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
sudo systemctl reload apache2
nano /var/www/your_domain/info.php
<?php
phpinfo();
http://server_domain_or_IP/info.php

Leave a Reply

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