Install & Setup Apache, MySQL, PHP (LAMP) Stack on Ubuntu 20.04

Install Apache, MySQL, PHP (LAMP) Stack on Ubuntu 20.04

1. Install Apache


sudo apt update && sudo apt install apache2

2. Configure Firewall


sudo ufw allow OpenSSH

sudo ufw allow in "Apache Full"

sudo ufw enable

sudo ufw status

3. Test Apache


sudo service apache2 status

4. Install MySQL


sudo apt update && sudo apt install mysql-server

sudo service mysql status

5. MySQL Security


sudo mysql_secure_installation

-> ENTER | Y | Y | Y | Y

sudo mysqladmin -p -u root version

6. Install PHP


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

php -version

7. Installing phpMyAdmin


sudo apt update && sudo apt install phpmyadmin php-mbstring

sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf

sudo a2enconf phpmyadmin.conf

sudo service apache2 reload

8. Create MySQL User


sudo mysql

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

FLUSH PRIVILEGES;

exit

9. Secure PhpMyAdmin


sudo nano /etc/apache2/conf-available/phpmyadmin.conf

Alias /your_url /usr/share/phpmyadmin

sudo service apache2 reload

10. Install ZIP/Unzip


apt-get update

apt-get install zip unzip

11. Enable .htaacess


sudo apt-get update

sudo a2enmod rewrite

systemctl restart apache2

sudo nano /etc/apache2/sites-enabled/000-default.conf

<Directory "/var/www/html">
  AllowOverride All
</Directory>

12. Configure Apache File


sudo nano /etc/apache2/apache2.conf

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
 </Directory>

 <Directory /var/www/html>
    Options -Indexes
 </Directory>

 ServerSignature Off
 ServerTokens Prod

13. install SSL Certificate


sudo apt update && sudo apt install certbot python3-certbot-apache

sudo certbot --apache

service apache2 restart

13. Permissions


sudo chown -R www-data:www-data /var/www

 

Scroll to Top