Install Linux, Apache, MySQL, PHP (LAMP) on Ubuntu
LAMP stands for Linux, Apache, MySQL and PHP. Most of the websites used LAMP stack and it’s very easy to setup. In this lesson, I’m going to install LAMP on Ubuntu server. I’m testing on Ubuntu 20.04 (LTS).
Table of Contents
Install Apache Web Server
Install Apache using Ubuntu’s package manager, apt:
# update
apt update && upgrade -y
# installing apache
sudo apt install apache2 -yAdd rules to ufw Firewall to allow incoming HTTP and HTTPS traffic:
# application list
sudo ufw app list
# apache full info
sudo ufw app info "Apache Full"
# allow 80 & 443 ports
sudo ufw allow in "Apache Full"Now visit http://your_server_ip and you’ll see the apache default page.
Install MySQL
Run this command to install MySQL:
sudo apt install mysql-server -yAfter installation, check the status of the MySQL server:
sudo systemctl status mysqlLet’s secure our MySQL server. Enter this command:
sudo mysql_secure_installationYou’ll be asked some questions. The questions and answers are:
1. Would you like to setup VALIDATE PASSWORD component?
Ans: y and then set your password.
2. Remove anonymous users?
Ans: y
3. Disallow root login remotely?
Ans: y (if you need, enter N)
4. Remove test database and access to it?
Ans: y
5. Reload privilege tables now?
Ans: yNow you can login to mysql server using sudo mysql command and create database, user etc.
Install PHP
To install default PHP version, run this command:
sudo apt install php libapache2-mod-phpTo install latest version of PHP run this command:
sudo apt install software-properties-common -y
# add Ondrej PHP repository
sudo add-apt-repository ppa:ondrej/apache2Install PHP 7.4 and some of the most common PHP modules:
sudo apt install php7.4 php7.4-common php7.4-opcache php7.4-cli php7.4-gd php7.4-curl php7.4-mysql -yCheck PHP version:
php -vOnce the packages are installed restart the Apache service:
sudo systemctl restart apache2Add Virtual Host
Create the directory for example.com as follows:
sudo mkdir /var/www/exammple.comSet permissions:
sudo chmod -R 755 /var/www/example.comCreate a simple index page:
nano /var/www/example.com/index.htmland paste this code in index.html:
<html>
<head>
<title>Welcome to Example.com</title>
</head>
<body>
<h1>Welcome to Example.com</h1>
</body>
</html>Then save and close the file. Now we need to create a virtual host file:
sudo nano /etc/apache2/sites-available/example.com.confPaste this config:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
</VirtualHost>Let’s enable the file with the a2ensite tool:
sudo a2ensite example.com.confDisable the default site:
sudo a2dissite 000-default.confCheck configuration:
sudo apache2ctl configtestIf Syntax OK, then restart apache:
sudo systemctl restart apache2 Now you can test this by navigating to http://example.com.
That’s it. Thanks for reading. ?
Md Obydullah
Software Engineer | Ethical Hacker & Cybersecurity...
Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.