• About Tanya
  • Privacy Policy
  • Contact
  • Setting up a LAMP environment on a local server

    We will be installing and hence setting up the LAMP server stack on our system’s local server. The LAMP server stack constitutes specific open source technologies that are used to set up a server. These technologies are:
    – L for Linux as the operating system
    – A for Apache as the Web server
    – M for MySQL as the relational database management system
    – P for PHP (At times, Python/Perl) as the object-oriented scripting language

    Hence, we also can understand why the Microsoft Windows equivalent of this stack is WAMP and the MacOS equivalent is the MAMP.

    Why do we even need it when reading an HTML file is so easy?

    Try this

    Point a directory to the local host. For this, first, enter the desired directory and then type the following in the terminal.

    python -m http.server 8000

    This command points the current directory to the local host on port 8000.
    Do this for a directory containing an HTML file. Try opening it from http://localhost:8000/
    Now, change the extension to *.php and try reading it again.

    What really happened

    Setting up a server in a directory containing an index.html file surely reads it processed with the HTML script. But, try changing the extension to something else like .php or .py. You would either get your HTML script as it is without any processing or a request to save it as a file. Using the LAMP stack helps us read such files.

    Using content-management systems(CMS) like WordPress and Joomla! is all about reading code in PHP. Let alone HTML wouldn’t serve the purpose at all.

    Installing requirements of the LAMP server stack

    L for Linux

    I worked on the Ubuntu 16.04 LTS which completed my Linux OS requirements. You shall now open the terminal window (Ctrl+Alt+T) to install the rest of our software requirements.

    A for Apache

    We need the Metapackage Apache2

    $ apt-get install apache2

    Check Apache

    Open the local host on the browser by typing the URL as http://localhost/
    You shall see an Apache message displayed stating “It works!”

    Apache server would automatically restart after the installation of Apache. In case it doesn’t run the command:

    /etc/init.d/apache2 restart

    M for MySQL

    apt-get install mysql-server mysql-client

    P for PHP

    We need to install the php5 and thelibapache2 Metapackages, and the <phpMyAdmin package for a GUI interface to access the MySQL databases with an interface.

    $ apt-get install php5 libapache2-mod-php5

    Check PHP installation

    You can check this by executing any PHP file from /var/www/ directory or simply executing the following command in the terminal window.

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

    Installing phpMyAdmin

    $ apt-get install phpMyAdmin

    Another window for the installing configuration of phpMyAdmin will appear.
    РIt will ask for server selection, choose apache2
    – Also, choose “yes” for dbconfig-common to set up the database.
    – There will be a prompt to create a password for the phpMyAdmin and then confirm it for the root user.

    The phpMyAdmin Apache configuration file is added to the /etc/apache2/conf-enabled/ directory to be read automatically.

    mcrypt module

    We need to explicitly enable the mcrypt module which is used in PHP for data encryption and decryption.

    phpenmod mcrypt

    Press TAB after PHP to see the most preferrable and available option as it may exist in your system with another name such as php5enmod.

    Checking the phpMyAdmin installation

    Open the browser and type the URL as http://localhost/phpmyadmin
    It should display a login form where you can enter the user details you just used to create the root user.


    In case the URL doesn’t work and displays a 404 error, you must do the following. Type the following in the terminal window.

    $ gksudo gedit /etc/apache2/apache2.conf

    Now, include the following line at the bottom of the file, save and quit.
    Include /etc/phpmyadmin/apache.conf
    Now, try accessing the URL. It should work.

    Congratulations, for setting up the LAMP environment on your local server!

    The files can be accessed on the local server once saved in the /var/www/ directory of the system.

    Leave a Reply

    %d bloggers like this: