Installing Apache, MySQL, and PHP on Ubuntu 16.04/18.04

When we install LAMP Stack on Linux machines especially on Ubuntu 16.04/18.04, you have to read many blogs/articles to get the required information. To get rid of this hurdle, I’ve written this article to explain each and everything at one place to install the LAMP stack on Linux Machine.

Note: In order to run commands to install LAMP stack you need root access of server.

Step 1: Update your package manager

    
     console.log( 'Code is Poetry' );
    
   

Step2: Install Apache Web server

Install Apache Web server
    
     $ sudo apt-get install apache2

    
   
Run below commands to manage web server

Start the Apache server:

    
     $ sudo service apache2 start

    
   

Stop the Apache server:

    
     $ sudo service apache2 stop

    
   

Restart the Apache server:

    
     $ sudo service apache2 restart

    
   

To check status of the Apache server:

    
     $ sudo service apache2 status
Sample Output
● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: active (running) since Tue 2018-04-23 14:28:43 EDT; 45s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 13581 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
  Process: 13605 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS)
    Tasks: 6 (limit: 512)
   CGroup: /system.slice/apache2.service
           ├─13623 /usr/sbin/apache2 -k start
           ├─13626 /usr/sbin/apache2 -k start
           ├─13627 /usr/sbin/apache2 -k start
           ├─13628 /usr/sbin/apache2 -k start
           ├─13629 /usr/sbin/apache2 -k start
           └─13630 /usr/sbin/apache2 -k start
    
   
You can do a spot check right away to verify that everything went as planned by visiting your server’s public IP address in your web browser
    
     http://localhost
http://127.0.0.1
http://your_server_ip
    
   
Small Apache

Step3: Installing Mysql

My Sql
    
     $ sudo apt-get install mysql-server

    
   

Testing your MySQL installation:
Run below command to check MySQL is successfully configured

    
     $ sudo mysql -u root -p

    
   
Run below commands to manage your MySQL server

Start the MySQL server:

    
     $ sudo mysql -u root -p

    
   

Stop the MySQL server:

    
     $ sudo service mysql stop

    
   

Restart the MySQL server:

    
     $ sudo service mysql restart

    
   

To check status of the MySQL server:

    
     $ sudo service mysql status

    
   

Step4: Installing PHP

Php
To install the latest version of PHP run below command on your terminal
    
     $ sudo apt-get install php

    
   

Install common PHP modules like bcmath, bz2, intl, gd, mbstring, zip.
Run following commands to install

    
     $ sudo apt-get install php-bcmath
$ sudo apt-get install php-bz2
$ sudo apt-get install php-intl
$ sudo apt-get install php-gd
$ sudo apt-get install php-mbstring
$ sudo apt-get install php-zip
    
   
To check the PHP version through console, please run below command
    
     $ php -v

    
   

Conclusion

This article will help people to install LAMP stack on Linux machine especially Ubuntu 16.04/18.04 without spending too much time reading many blogs/articles.

If you have suggestions or any question please mention in comment.

Related articles