Install LAMP in Ubuntu


LAMP stands for Linux Apache MySql and PHP. Basically LAMP consists of all the applications that are required to create and run a website.

  • For hosting a website, you will need Webserver, which here is Apache.
  • To store the data, we need a database. Here it is MySql.
  • To run server side scripts we need a scripting language. Here it is PHP.

So basically, installing LAMP is installing and configuring Apache, MySql and PHP. Web-hosting companies, generally use Linux and they have LAMP installed in those servers. So if you have the html pages, you can install LAMP in Ubuntu, do some coding in PHP, configure it with MySql and host your own website for free.
Lets we will see how to setup your own LAMP server in Ubuntu.

Lets see how to install components of LAMP one by one.

  1. Apache
    apt-get install apache2
    To install Apache, open terminal and write

    Install Apache

    Install Apache

    service apache2 restart
    Once apache is installed start/restart the service.

    Restart Apache

    Restart Apache


    -Check if apache is working, by entering ‘localhost‘ in your address bar of browser.

    Check apache

    Check apache

  2. PHP

    apt-get install php5 libapache2-mod-php5 
    To install PHP, we also need to install its a package named ‘labapache-mod-php5’ with it.

    Install php

    Install php


    service apache2 restart
    After installing restart the server, restart apache service.

    Restart apache

    Restart apache

    – Now, we will test the installed PHP. So create a file in ‘/var/www‘ with any name but having the extension ‘.php’. For example, ‘testing.php

    Create a php file for testing.

    Create a php file for testing.

    –  <?php phpinfo(); ?>
    Inside the php file, copy paste this code.

    Enter php code.

    Enter php code.

    – Open your browser and enter localhost/’filename’
    here, localhost/testing.php

    Run php code.

    Run php code.

  3. MySql

    apt-get install mysql-server
    To installMySql database, install packagemysql-server

    Install mysql server

    Install mysql server

    It will ask for a root password. You can leave it blank, but its strongly recommended that you enter a root password. Remember this password.

    Enter root password.

    Enter root password.

    vim /etc/mysql/my.cnf    (Optional)
    If you want other computer in your network, to view the MySql server that you created, open my.cnf file
    and insert your IP address in ‘bind-address’

    Open my.cnf file

    Open my.cnf file

    Enter your IP address in 'bind-address'

    Enter your IP address in ‘bind-address’

    – mysql -u root -p 
    To use MySql, enter this in terminal.
    Here ‘-u’ points to the user, as in this case it is root, and ‘-p’ is used to give the root password.
    Enter the password.

    Check MySql

    Check MySql

     

  4. phpMyAdmin (Optional)
    – Earlier in LAMP, we used to install php, but recently industries are switching to phpMyAdmin because of its easy configuration and simple yet interactivve Graphical User Inter. If you wish to install phpMyAdmin, follow these steps :- apt-get install phpmyadmin libapache2-mod-auth-mysql php5-mysql

    Install phpMyAdmin

    Install phpMyAdmin

    – It will then ask you which web server are you using? Select your webserver.

    Select your web-server.

    Select your web-server.

    – Install database.
    If you don’t have a database, you can create one in phpMyAdmin and set the Database Administrator password as well as MySql application password.
    If you wish to configure the database on you own, select No.

    Configure database.

    Configure database.

    Select yes if you want to create your db

    Select yes if you want to create your db

    Enter database administrator's password.

    Enter database administrator’s password.

    Enter Mysql password.

    Enter Mysql password.

    phpmyadmin 7

    Test phpMyAdmin by going to ‘localhost/phpmyadmin’

    PhpMyAdmin login

    PhpMyAdmin login

    phpMyAdmin

    phpMyAdmin

Leave a Reply