How to: Setup a LAMP Server on Ubuntu 16.04 (Linux, Apache2, MySQL and PHP 7)

created by BasicSysAdmin

Tags: Linux, Ubuntu, Ubuntu 16.04

Aug 28, 2016


This tutorial will cover the steps required to setup your own LAMP server (Linux, Apache, MySQL and PHP 7) on Ubuntu 16.04

In order to follow this tutorial, you will need the following

  • Ubuntu 16.04

  • Sudo Permissions

  • Update Package list

    Before installing any new packages, it is always good idea to update your package list. You can do this by typing:
    sudo apt-get update

    Installing Packages

    Next, you can install Apache2, MySQL and php 7 using this command:
    sudo apt-get install apache2 mysql-server php libapache2-mod-php

    After you have done this, you will eventually receive the following screen asking you if you would like to continue, just press y and then the enter key.

    You will then be prompted to select a password for your mysql root user. Enter this and then confirm it.

    And thats it. You should now have your own web server. You can confirm this is working correctly by going to your ipaddress. You should see a page like this.

    Checking on PHP 7

    To checkout the version of PHP you are using, you can use this command:
    php -v

    You should see something like this:

    If you would like to see more about info about what is enabled in php, use this command to create a phpinfo file - Make sure to delete this if you plan to move this into production.
    sudo echo -e "<?php echo phpinfo(); ?>" | sudo tee -a /var/www/html/phpinfo.php

    This will create a file called phpinfo.php within the root of your web directory. You can view this by going to http://[your ip here]/phpinfo.php
    You can remove this using this command
    sudo rm /var/www/html/phpinfo.php

    Other Useful Guides

  • Install PHPMyAdmin
  • Setup Public Key Authentication to securely login