Installing LAMP stack on Ubuntu
Wed Mar 29, 2017 · 338 words

LAMP is short for Linux, Apache, MySQL, PHP. This tutorial shows how you can install LAMP stack (Apache2, PHP and MySQL) on an Ubuntu 16.04 server.

Apache

To install Apache you must install the Metapackage apache2. This can be done by searching for and installing in the Software Centre, or by running the following command.

sudo apt-get install apache2

MySQL

To install MySQL you must install the Metapackage mysql-server. This can be done by searching for and installing in the Software Centre, or by running the following command.

sudo apt-get install mysql-server

PHP

To install PHP you must install the Metapackages php5 and libapache2-mod-php5. This can be done by searching for and installing in the Software Centre, or by running the following command. Install PHP 5:

sudo apt-get update
sudo apt-get install php5 libapache2-mod-php5
Or Install PHP 7:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php 
sudo apt-get update 
sudo apt-get install -y php7.1 
# Optional modules 
sudo apt-get -y install php7.1-mcrypt php7.1-curl php7.1-cli php7.1-mysql php7.1-gd libapache2-mod-php7.1 
# check installed version 
php -v

Restart Server

Your server should restart Apache automatically after the installation of both MySQL and PHP. If it doesn’t, execute this command.

sudo service apache2 restart

Check Apache

Open a web browser and navigate to http://localhost. You should see a message saying It works!

Check PHP

You can check your PHP installation by executing any PHP file from within /var/www/. Alternatively you can execute the following command, which will make PHP run the code without the need for creating a file.

php -r 'echo "\n\nYour PHP installation is working fine.\n\n\n";'
Or:
php -v

Congratulations, you have just Installed a LAMP Server!

I hope that some of this is useful to a few of you. There is always an room for improvements. Leave a note in the comments if you have any cool tricks for the LAMP installation. I’m always on the lookout for fun hacks.

I have wrote another article on How to install PhpMyAdmin on centOS. Checkout related articles section to find more relevant content.


back · posts · who is yuvi? · contact · home