How to install Apache, MySQL and PHP (LAMP) in ...

Devolio

Search

Twitter

    Tuesday, May 20. 2008

    How to install Apache, MySQL and PHP (LAMP) in Ubuntu 8.04

    Just like our Ubuntu 7.10 LAMP how to, this guide will cover the installation of Apache, MySQL and PHP on Ubuntu 8.04. I assume you're already running Ubuntu 8.04 for this guide. If you're still running 7.10, you can use this guide.
    Let's go ahead and open up a terminal (Applications->Accessories->Terminal) and if you want to save some time, Firefox or your favorite browser as well.

    Installing Apache


    Time to get started. In our terminal window...
    sudo apt-get install apache2

    Testing Apache


    Once that's finished installing, we can start up Apache to test it by typing...
    sudo /etc/init.d/apache2 start

    Now open up your browser (or if you're a time saver,) and point it to...
    http://localhost

    If you're cleanly installing Apache, you'll see the default installed folder index, or you'll see your normal server pages if you've updated.

    Installing PHP


    Now that Apache is installed, PHP is next...
    sudo apt-get install php5

    Once PHP has finished installing, if we restart Apache...
    sudo /etc/init.d/apache2 restart

    Testing PHP


    To test PHP, we'll make a new PHP document with any editor you want...
    sudo gedit /var/www/phpinfo.php

    And paste the following code into the file to run PHP's phpinfo() function, which will show us a myriad of information about PHP...
    <?php phpinfo(); ?>

    Now we can save the file, and browse to...
    http://localhost/phpinfo.php

    To see all of the information about your PHP installation. For security reasons, you should remove this page when you're done with it. If you want to do that quickly...
    sudo rm -rf /var/www/phpinfo.php

    Assuming you named the file phpinfo.php.

    Installing MySQL


    To install MySQL, in our terminal window...
    sudo apt-get install mysql-server

    If this is a clean installation of MySQL, it will prompt you to set your root password. Make sure that you type it correctly, as it will only ask you once. If you've upgraded, or installed MySQL before, it may not prompt you for a password.

    Testing MySQL


    Once MySQL is finished installing, we can test MySQL by connecting to it, using...
    mysql -uroot -pyourpassword

    After filling in your own password after -p, you'll see a MySQL prompt.
    That's it, you're done! You can type 'exit' to get out of MySQL.

    Installing phpMyAdmin


    if you want to install phpMyAdmin to administrate your MySQL, you can type...
    sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin

    Again, like MySQL, if this is a clean installation, it will ask you to choose a webserver to configure automatically. If you have had phpMyAdmin installed before, it won't prompt you to choose. You can use the space bar to select apache2 and then enter. Once that's finished, we need to restart one more time...


    The End


    Now, to pull up your phpMyAdmin panel, you can point your browser at...
    http://localhost/phpmyadmin

    To log in and use PMA.

    Useful Commands and Default Locations


    To Save yourself some time, you can make launchers for Apache or MySQL start, stop, and restart if you feel the need.

    Apache


    sudo /etc/init.d/apache2 start
    sudo /etc/init.d/apache2 stop
    sudo /etc/init.d/apache2 restart

    MySQL


    sudo /etc/init.d/mysql start
    sudo /etc/init.d/mysql stop
    sudo /etc/init.d/mysql restart

    Locations


    /var/www/ -- Document Root
    http://localhost/phpmyadmin -- phpMyAdmin
    /usr/share -- phpMyAdmin local location

    Trackbacks

    No Trackbacks

    Comments
    Display comments as (Linear | Threaded)

    #1 - Anonymous 2008-05-30 16:37 - (Reply)

    how about SSL as well that would make this article super awesome. Thanks for the great directions!!!

    #2 - amin 2008-06-02 20:08 - (Reply)

    thanx man:)

    #3 - Robert James said:
    2008-08-01 14:37 - (Reply)

    Thanks, very useful document.

    #4 - UrsusArctosHorribilis 2008-08-29 23:34 - (Reply)

    Thanks. This got me started in no time at all. Greatly appreciated.

    #5 - Anonymous 2008-09-11 00:56 - (Reply)

    thanks. pretty direct.

    #6 - ismail kuyu 2008-09-11 05:52 - (Reply)

    really useful. thx

    #7 - ismail kuyu 2008-09-15 02:39 - (Reply)

    but i have a problem, when i point to browser, instead of opening the page, it asks whether to save or open with mozilla??? how will i overcome it?

    #7.1 - Joey said:
    2008-09-15 06:06 - (Reply)

    Ismail,

    Are you sure you've restarted apache? (sudo /etc/init.d/apache2 restart) That can happen if the PHP module hasn't been loaded yet.

    Let me know if that fixes your problem.


    Add Comment

    Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
    Standard emoticons like :-) and ;-) are converted to images.
    E-Mail addresses will not be displayed and will only be used for E-Mail notifications