Login/Register

How to: Setup a LAMP Server on Debian 8.5 Jessie (Linux, Apache2, MySQL and PHP 7)

created by BasicSysAdmin

Tags: Debian, Debian 8.5, Debian Jessie, Web Server

Sep 26, 2016

Introduction

This tutorial will cover the steps required to setup your own Web Server/LAMP server (Linux, Apache, MySQL and PHP 7) on Debian 8.5 Jessie
https://youtu.be/ljnAPxp4KS0

Prerequisites

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

  • Debian 8.5

  • Sudo Permissions


  • Add dotdeb Repository

    Before we are able to install php and any other package, we are going to need to add the dotdeb repository to our sources so that we are able to install the php7 package.
    sudo nano /etc/apt/sources.list

    Once you have this open, paste the following at the bottom of the file

    #repository for installing php7
    deb http://packages.dotdeb.org jessie all

    After this, you should save the file with Ctrl + O and then exit with Ctrl + x. You then need to setup the public key.

    wget https://www.dotdeb.org/dotdeb.gpg
    sudo apt-key add dotdeb.gpg

    Finally, you should update your package list.

    sudo apt-get update;

    Open Port 80 in IPTables

    Before we install anything, its a good idea to make sure port 80 is open in iptables.

    iptables -A INPUT -p tcp --dport 80 -j ACCEPT
    iptables -A INPUT -p udp --dport 80 -j ACCEPT

    Installing Packages

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

    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

    Enable MySQLi Extension

    You may find you have MySQLi does not works with php, you may need to make sure the extension is enabled. To do this, you will need to edit the php.ini file.

    sudo nano /etc/php/7.0/apache2/php.ini

    You will need to find the line where it says the line below - You can use Ctrl + W to search

    ;enable extension=php_mysqli.dll

    When you find this line, remove the ';', save and exit. After this, you should then restart apache.
    sudo service apache2 restart

    Other Useful Guides

  • Install PHPMyAdmin
  • Setup Public Key Authentication to securely login