Atlantic.Net Blog

Install LAMP Server with Let’s Encrypt Free SSL on Ubuntu 18.04

Hitesh Jethva
by Atlantic.Net (273 posts) under VPS Hosting

LAMP is a free and open-source web development platform used to host dynamic and high-performance websites. It consists of four open-source components: Linux, Apache, MySQL/MariaDB, and PHP. LAMP uses Linux as the operating system, Apache for webserver, MySQL/MariaDB as a database and PHP as the scripting language.

In this tutorial, we will explain how to install LAMP and secure it with Let’s Encrypt free SSL on Ubuntu 18.04.


  • A fresh Ubuntu 18.04 VPS on the Atlantic.Net Cloud Platform.
  • A valid domain name pointed to your server IP address. In this tutorial, we will use as the domain.

Step 1 – Create an Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing Ubuntu 18.04 as the operating system, with at least 2GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged into your Ubuntu 18.04 server, run the following command to update your base system with the latest available packages.

apt-get update -y

Step 2 – Installing Apache Web Server

First, install Apache webserver with the following command:

apt-get install apache2 -y

Once the installation has been completed, start the Apache service and enable it to start after system reboot with the following command:

systemctl start apache2
systemctl enable apache2

Next, verify the Apache webserver with the following command:

systemctl status apache2

Apache web server is now running and listening on port 80. Open your web browser and type the URL http://your-server-ip. You should see the Apache default page in the following screen:

That means the Apache webserver is working as expected.

Step 3 – Installing MariaDB Database Server

MariaDB is the most popular fork of the MySQL relational database management system. You can install it by running the following command:

apt-get install mariadb-server mariadb-client -y

Once installed, start the MariaDB service and enable it to start after system reboot with the following command:

systemctl start mariadb
systemctl enable mariadb

By default, MariaDB is not secured, so you will need to secure it first. You can secure it by running the mysql_secure_installation script:


This script will set the root password, remove anonymous users, disallow root login remotely, and remove test database and access to it, as shown below:

Enter current password for root (enter for none): Press the Enter key
Set root password? [Y/n]: Y
New password: Enter password
Re-enter new password: Repeat password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]:  Y
Reload privilege tables now? [Y/n]:  Y

Step 4 – Installing PHP

By default, PHP is available in the Ubuntu 18.04 default repository. You can install PHP and other libraries with the following command:

apt-get install php php-cli php-mysql php-curl php-zip libapache2-mod-php -y

Once all the packages are installed, open your php.ini file and tweak some required settings:

nano /etc/php/7.2/apache2/php.ini

Change the following lines. The below values are great settings for a LAMP environment:

memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago

Save and close the file. Then, restart the Apache webserver to apply the configuration.

systemctl restart apache2

Next, create a info.php in your Apache document root directory to test PHP with Apache:

nano /var/www/html/info.php

Add the following line:

<?php phpinfo( ); ?>

Save and close the file. Then, open your web browser and visit the URL http://your-server-ip/info.php. You should see the default PHP test page depicted in the following screen.

After testing, it is recommended to remove the info.php file for security reasons.

rm -rf /var/www/html/info.php

Step 5 – Creating a Virtual Host

First, create an index.html file for your domain

mkdir /var/www/html/
nano /var/www/html/

Add the following lines:

<h1>Welcome to Website</h1>
<p>This is my LAMP server</p>

Save and close the file. Then, change the ownership of the directory and give necessary permissions:

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

Next, you will need to create an Apache virtual host configuration file for your domain,

nano /etc/apache2/sites-available/

Add the following lines:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/html/
    DirectoryIndex index.html
    ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
    CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined

Save and close the file when you are finished.

Here’s a brief explanation of each parameter in the above file:

  • ServerAdmin: Specify an email address of server admin.
  • ServerName: Domain name that is associated with your server IP address.
  • DocumentRoot: Specify the location of the content for the website.
  • DirectoryIndex: Specify a default page to display when a directory is accessed.
  • ErrorLog: Location of the error log file.
  • CustomLog: Location of the access log file.

Next, enable the virtual host and restart the Apache web service to apply the configuration:

systemctl restart apache2

To test your website, open your web browser and type the URL You will be redirected to the following page:

Step 6 – Securing Your Website with Let’s Encrypt

At this point your website is working well, but it’s not secured. You will need to secure it with Let’s Encrypt free SSL.

First, you will need to install a Certbot client on your server. Certbot is an easy to use client that can be used to download a certificate from Let’s Encrypt and configure Apache webserver to use this certificate.

By default, the latest version of Certbot is not available in the Ubuntu 18.04 default repository. You will need to add the Certbot repository to APT.

apt-get install software-properties-common apt-transport-https ca-certificates -y
add-apt-repository ppa:certbot/certbot

Once the repository is added, update the repository and install Certbot with the following command:

apt-get update -y
apt-get install certbot python-certbot-apache -y

Next, run the following command to install Let’s Encrypt free SSL for website

certbot --apache -d

You will be prompted to provide your email and agree to the terms of service, as shown below:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at You must
agree in order to register with the ACME server at
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/
Deploying Certificate to VirtualHost /etc/apache2/sites-available/
Enabling available site: /etc/apache2/sites-available/

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Next, select option 2 and hit enter to download the Let’s Encrypt certificate and configure the Apache webserver to use this certificate. Once the installation process has been completed, you should see the following output:

Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/ to ssl vhost in /etc/apache2/sites-available/

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled

You should test your configuration at:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

 - Congratulations! Your certificate and chain have been saved at:
   Your key file has been saved at:
   Your cert will expire on 2019-10-22. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:
   Donating to EFF:          

Now, open your web browser and access your website securely with the URL


In the above tutorial, we learned how to install LAMP server on Ubuntu 18.04 VPS. We also learned how to secure a LAMP server with Let’s Encrypt free SSL. You can now easily install a LAMP server and secure it with Let’s Encrypt free SSL on Ubuntu 18.04 using our VPS Hosting services.

Get A Free To Use Cloud VPS

Free Tier Includes:
G3.2GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year

Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year

New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4


London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom