Install LAMP Apache, MySQL, PHP and Free ssl in Ubuntu 20.04 Print

  • #LAMP, #Ubuntu 20.04, #install-php-mysql-apche-ssl
  • 2

Step 1

after installation Ubuntu 20.04

update Packages by this this command

sudo apt update
sudo apt upgrade

Step 2
Install Apache using the following command.
sudo apt install apache2

This will install apache2 and all required dependencies.

Step 3

Step Fire Wall

Now you can set up Uncomplicated Firewall (UFW) with Apache to allow public access on default web ports for HTTP and HTTPS

sudo ufw app list

Output
Available applications:
Apache
Apache Full
Apache Secure
OpenSSH


  • Apache: This profile opens port 80 (normal, unencrypted web traffic)
  • Apache Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
  • Apache Secure: This profile opens only port 443 (TLS/SSL encrypted traffic)
  • OpenSSH: This profile opens port 22 for SSH access.

If you are not going to use SSL you need to enable only the Apache profile.

Now we will enable Apache Full.

 
sudo ufw allow 'Apache Full'

With this command you can view the status of UFW.

sudo ufw status

You will see the output as follows.

Output
Status: active
To Action From
-- ------ ----
Apache Full ALLOW Anywhere
OpenSSH ALLOW Anywhere
Apache Full (v6) ALLOW Anywhere (v6)
OpenSSH (v6) ALLOW Anywhere (v6)

Step: 4

Check Apache installation
sudo systemctl status apache2


Output
● apache2.service - The Apache HTTP Server
    Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
   Drop-In: /lib/systemd/system/apache2.service.d
            └─apache2-systemd.conf
    Active: active (running) since Tue 2021-08-06 03:59:34 UTC; 5min ago
  Main PID: 10617 (apache2)
     Tasks: 55 (limit: 667)
    CGroup: /system.slice/apache2.service
            ├─10617 /usr/sbin/apache2 -k start
            ├─10619 /usr/sbin/apache2 -k start
            └─10620 /usr/sbin/apache2 -k start
  Starting The Apache HTTP Server…
  Started The Apache HTTP Server.
Step 5
Install MYSQL and secure Mysql
sudo apt install mysql-server

After installation check the status

sudo service mysql status

Output like this

  mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-08-06 07:13:18 UTC; 1min 4s ago
   Main PID: 3333 (mysqld)
     Status: "Server is operational"
      Tasks: 38 (limit: 2010)
     Memory: 322.9M
     CGroup: /system.slice/mysql.service
             └─3333 /usr/sbin/mysqld 
 

Secure MYsql

sudo mysql_secure_installation

This will ask if you want to configure the VALIDATE PASSWORD PLUGIN.

Answer Y for yes, or anything else to continue without enabling.

please also read this for password

If you answer “yes”, you’ll be asked to select a level of password validation. Keep in mind that if you enter 2 for the strongest level, you will receive errors when attempting to set any password which does not contain numbers, upper and lowercase letters, and special characters, or which is based on common dictionary words.

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary              file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1


Step 6

Install PHP

By default Ubuntu 20.04 has the latest PHP 7.4 repository added. So you can install PHP using the following command.

sudo apt install php libapache2-mod-php php7.4-mysql php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y 


Check php version

php -v


Configure PHP

Now we configure PHP for Web Applications by changing some values in php.ini file.

For PHP 7.4 with Apache the php.ini location will be in following directory.

sudo nano /etc/php/7.4/apache2/php.ini


upload_max_filesize = 32M 
post_max_size = 48M
memory_limit = 256M
max_execution_time = 600
max_input_vars = 3000
max_input_time = 1000



Configure Apache

Disable default Apache configuration.

sudo a2dissite 000-default

Create website directories.

sudo mkdir -p /var/www/html/domainname/public



Setup correct permissions.


sudo chmod -R 755 /var/www/html/domainname
sudo chown -R www-data:www-data /var/www/html/domainname

Create a new virtual host configuration.

sudo nano /etc/apache2/sites-available/domainname.conf

Paste the following configurations in the new file.

<VirtualHost *:80>
     ServerAdmin admin@domainname.com
     ServerName domainname.com
     ServerAlias www.domainname.com

     DocumentRoot /var/www/html/domainname/public

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

     ErrorLog ${APACHE_LOG_DIR}/error.log 
     CustomLog ${APACHE_LOG_DIR}/access.log combined 
 </VirtualHost>

Enable the new configuration.

sudo a2ensite domainname.conf
 

Install Let’s Encrypt SSL

 

install with this command

 

sudo apt install python3-certbot-apache'


Now we have installed Certbot by Let’s Encrypt for Ubuntu 20.04, run this command to receive your certificates.

sudo certbot --apache --agree-tos --redirect -m youremail@email.com -d domainname.com -d www.domainname.com



Select the appropriate option and hit Enter

This command will install Free SSL, configure redirection to HTTPS and restarts the Apache server.

 

Renewing SSL Certificate

Certificates provided by Let’s Encrypt are valid for 90 days only, so you need to renew them often. So, let’s test the renewal feature using the following command.

sudo certbot renew --dry-run

This command will test the certificate expiry and configures the auto-renewable feature.

 

Test IT

sudo nano /var/www/html/domainname/public/info.php

Paste the below code inside the file.

<?php phpinfo();
and save this
and then
Now go ahead and check your domain name with the info.php in the url (domainname.com/info.php).

Thanks
webanchor Technical staff
https://www.webanchor.net

 

 

 

 

 






 





 

 

 

 

 


Was this answer helpful?

« Back

Powered by WHMCompleteSolution