How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04 + PHPMYADMIN


Please provide me steps for installing LAMP on digital ocean server.

Asked on October 21, 2018 in Programmer.
Add Comment
4 Answer(s)
Best answer

Step 1: Install Apache and Allow in Firewall
For our purposes, we can get started by typing these commands:

sudo apt-get update
sudo apt-get install apache2

Adjust the Firewall to Allow Web Traffic

sudo ufw app list
Available applications:
Apache Full
Apache Secure

Allow incoming traffic for this profile:

sudo ufw allow in "Apache Full" Do this for rest all above list

http://your_server_IP_address | Your apache is installed now

Step 2: Install MySQL
Now that we have our web server up and running, it is time to install MySQL.

sudo apt-get install mysql-server

Step 3: Install PHP
We’re going to include some helper packages as well, so that PHP code can run under the Apache server and talk to our MySQL database:

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

After this, we need to restart the Apache web server in order for our changes to be recognized. You can do this by typing this:

sudo systemctl restart apache2

We can also check on the status of the apache2 service using systemctl:

sudo systemctl status apache2

Step 4 : Install phpMyAdmin
To get started, we can simply install phpMyAdmin from the default Ubuntu repositories.

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

The only thing we need to do is explicitly enable the PHP mcrypt and mbstring extensions, which we can do by typing:

sudo phpenmod mcrypt
sudo phpenmod mbstring

Afterwards, you’ll need to restart Apache for your changes to be recognized:

sudo systemctl restart apache2

You can now access the web interface by visiting your server’s domain name or public IP address followed by /phpmyadmin:

Answered on October 21, 2018.
Add Comment

Consider few changes for the latest version  at step 3

How to Install PHP 7.2 on Ubuntu 16.04

PHP 7.2 is the latest stable version of PHP and has many new features, improvements, and bug fixes. You should definitely use it if you want a better, faster website/application.

Update Ubuntu

Of course, as always, first update Ubuntu:

apt-get update && apt-get upgrade

Add the PHP repository

You can use a third-party repository to install the latest version of PHP. We’ll use the repository by Ondřej Surý.

First, make sure you have the following package installed so you can add repositories:

apt-get install software-properties-common

Next, add the PHP repository from Ondřej:

add-apt-repository ppa:ondrej/php

And finally, update your package list:

apt-get update

Install PHP 7.2

After you’ve added the repository, you can install PHP 7.2 with the following command:

apt-get install php7.2

This command will install additional packages:

  • libapache2-mod-php7.2
  • libargon2-0
  • libsodium23
  • libssl1.1
  • php7.2-cli
  • php7.2-common
  • php7.2-json
  • php7.2-opcache
  • php7.2-readline

And that’s it. To check if PHP 7.2 is installed on your server, run the following command:

php -v

Install PHP 7.2 modules

You may need additional packages and modules depending on your applications. The most commonly used modules can be installed with the following command:

apt-get install php-pear php7.2-curl php7.2-dev php7.2-gd php7.2-mbstring php7.2-zip php7.2-mysql php7.2-xml

And that’s all. You can now start using PHP on your Ubuntu server.


At step 4,  as you have already install mbstring  sot just run

sudo apt-get install phpmyadmin

Further mcrypt does not found for php7.2 so need some work around to enable this

Install php7.1-mcrypt

sudo apt install php7.1-mcrypt

Create symbolic link to php7.1-mcrypt

sudo ln -s /etc/php/7.1/mods-available/mcrypt.ini /etc/php/7.2/mods-available/

Enable mcrypt extension

sudo phpenmod mcrypt


Now proceed with rest commands

Answered on January 16, 2019.
Add Comment

refer link

Answered on October 29, 2020.
Add Comment

Apache on Ubuntu 18.04 has one server block enabled by default that is configured to serve documents from the /var/www/html directory. While this works well for a single site, it can become unwieldy if you are hosting multiple sites. Instead of modifying /var/www/html, let’s create a directory structure within /var/www for a your_domain site, leaving /var/www/html in place as the default directory to be served if a client request doesn’t match any other sites.

Create the directory for your_domain as follows:

sudo mkdir /var/www/your_domain

Next, create a sample index.html page using nano or your favorite editor:

nano /var/www/your_domain/index.html

Inside, add the following sample HTML:



        <title>Welcome to Your_domain!</title>



        <h1>Success!  The your_domain virtual host is working!</h1>



Save and close the file when you are finished.

In order for Apache to serve this content, it’s necessary to create a virtual host file with the correct directives. Instead of modifying the default configuration file located at /etc/apache2/sites-available/000-default.conf directly, let’s make a new one at /etc/apache2/sites-available/your_domain.conf:

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

Paste in the following configuration block, which is similar to the default, but updated for our new directory and domain name:

<VirtualHost *:80>

    ServerAdmin webmaster@localhost

    ServerName your_domain

    ServerAlias www.your_domain

    DocumentRoot /var/www/your_domain

    ErrorLog ${APACHE_LOG_DIR}/error.log

    CustomLog ${APACHE_LOG_DIR}/access.log combined


Notice that we’ve updated the DocumentRoot to our new directory and ServerAdmin to an email that the your_domain site administrator can access. We’ve also added two directives: ServerName, which establishes the base domain that should match for this virtual host definition, and ServerAlias, which defines further names that should match as if they were the base name.

Save and close the file when you are finished.

Let’s enable the file with the a2ensite tool:

sudo a2ensite your_domain.conf


Disable the default site defined in 000-default.conf:

sudo a2dissite 000-default.conf

Restart Apache to implement your changes:
sudo systemctl restart apache2
Answered on October 29, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.