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

Devolio

Search

Twitter

    Monday, January 7. 2008

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

    This guide covers the installation of Apache, MySQL, and PHP on Ubuntu 7.10 (More commonly referred to as LAMP, or Linux Apache MySQL PHP). Optionally, you can also install phpMyAdmin as a front end for MySQL. We assume that you already have Ubuntu 7.10 running on the machine as well. That said, let's get right into it.
    The first thing we're going to do is open up a terminal (Applications->Accessories->Terminal).

    Installing Apache

    Now we can get started installing. This will take a few minutes, so grab a beer (or your favorite beverage,) and off we go. To install Apache, type or paste this into your terminal:

    sudo apt-get install apache2


    Testing Apache

    Once apache2 is done installing, you can go ahead and test it by using:

    sudo /etc/init.d/apache2 start


    If you get a message that it's already running, you're good to go. Now, open up your browser and navigate to:

    http://localhost


    You should see a page just like this. As long as you do, we're ready to install PHP.



    Installing PHP

    Again, to install PHP, type or paste this into your terminal:

    sudo apt-get install php5 libapache2-mod-php5


    Once it's finished installing, restart apache, using:

    sudo /etc/init.d/apache2 restart


    Testing PHP

    Now, let's make sure that PHP is working properly. To do this, we're going to run phpinfo(). You can, of course, swap out gedit with your editor of choice.

    sudo gedit /var/www/phpinfo.php


    Type or paste the following into the document, and save it. (remove the space before the '?php')

    < ?php phpinfo(); ?>


    Now we can test PHP by browsing to:

    http://localhost/phpinfo.php


    You should see all of the info about your PHP installation listed on the page, like so. For security reasons, you should remove this page when you're sure that PHP works.


    Installing MySQL

    Now we can conquer MySQL

    sudo apt-get install mysql-server


    As MySQL is installing, it will ask you to configure your root password. Make sure that you type it correctly, as it will only ask you once.


    Testing MySQL

    After that is finished, you can test MySQL by running this, where zzzz is your password

    mysql -uroot -pzzzz


    If it brings you to a MySQL prompt, you're done! You can type exit to get out of MySQL.


    Installing phpMyAdmin

    Now, if you want to install phpMyAdmin to have a front end for MySQL, you can use the following

    sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin


    It will ask you to choose a webserver to configure automatically, you can use the space bar to select Apache2. And after that's finished, restart one last time.

    sudo /etc/init.d/apache2 restart


    Finished!

    Now you have your own LAMP (Linux Apache MySQL PHP) server, with phpMyAdmin.



    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


    Share

    Save This Page
    StumbleUpon Toolbar Stumble It!

    Digg it

    Trackbacks

    No Trackbacks

    Comments
    Display comments as (Linear | Threaded)

    #1 - stormwild said:
    2008-01-20 04:30 - (Reply)

    This is a very helpful tutorial. It's easy to follow, clear and well written. I was able to install apache2, php5 and mysql successfully on Ubuntu 7.10 (Desktop). However when I came to the part where I needed to install phpmyadmin, I wasn't sure how to select the apache2 in the list of installation locations. I tried to press Shift + 8 to get the asterisk but I ended up pressing the enter key without seeing the asterisk beside the apache2 selection. The installation seemed to proceed properly, however restarting apache2 and going to http://localhost/phpmyadmin causes a 404 Not Found error.

    I was wondering how I could select apache2 for the phpmyadmin installation?

    I was thinking of removing and then reinstalling phpmyadmin however I am not sure what command to use.

    I was hoping if I could get your advice on this.

    Regards,

    stormwild

    #1.1 - Joey said:
    2008-01-20 04:50 - (Reply)

    Hey stormwild,

    You can reinstall phpmyadmin by using the following command:

    sudo apt-get install --reinstall phpmyadmin

    And during the install, you can press the space bar to select, and then enter. Let me know if all goes well.

    #1.1.1 - stormwild said:
    2008-01-20 08:15 - (Reply)

    Hi Joey,

    Thanks for that quick response.

    I missed your instruction on pressing the spacebar that first time.

    After trying to reinstall I could not get the menu to select apache2 to appear.

    I wondered where phpmyadmin was installed and found it in /usr/share. I moved it over to /var/www and got it to work now.

    I'm still unfamiliar with where things are stored in Linux (Ubuntu) or how the apt-get command works. It seems to work like a type of command line universal 'windows' update.

    It seems that for third-party programs which are not in the repository these need to be downloaded, unpacked and installed using make.

    Your tutorial is a great help. I had already downloaded the server version of Ubuntu and was planning to do a reinstall of the operating system when I happened to find your tutorial. What a great timesaver!

    #1.1.1.1 - Joey said:
    2008-01-20 12:30 - (Reply)

    Hey stormwild,

    I'm glad to hear you got it working. You're indeed correct, apt-get is much like a universal Windows update that can also install/build packages.

    The problem you have with the repository (not being able to get some binary packages,) can be alleviated by going to System - > Administration -> Synaptic Package Manager. Once in Synaptic, Settings -> Repositories will let you change all of the settings for building and downloading packages.

    I'm glad my tutorial helped you out :-) If you have any ideas for more useful articles, feel free to let me know, I'd love to hear what you're curious to learn.

    #1.2 - Felix 2008-01-27 08:33 - (Reply)

    Great that helped me!

    Found phpmyadmin in usr/share too after reeding your report!

    #2 - Mitzico 2008-01-23 21:17 - (Reply)

    i am very glad to see you tutorial in LAMP. hope to see more tutorials next time i visit your site.

    thanks and god speed.
    mitzico

    #3 - Alan Wilson said:
    2008-01-24 21:12 - (Reply)

    This helped a bunch thank you!

    #4 - Azmi from Malaysia 2008-02-03 16:40 - (Reply)

    I'm new to LINUX after about 12 years attached to MS Windows. This tutorial very simple yet works. My first attempt to LINUX is Ubuntu 7.10, so this greats time saving to me. Hope you will release more simple tutorial. Thanks.

    #5 - Dave 2008-02-11 12:24 - (Reply)

    FINALLY a tutorial that gets phpmyadmin to work. Ive read a dozen tutorials and this is the only one that works. Please include the "usr/share" info in the tutorial.

    #5.1 - Joey said:
    2008-02-11 23:33 - (Reply)

    Hey Dave,

    I've added the location into the article, thank you for the confirmation on the /usr/share issue.

    #6 - Pratik C 2008-02-20 08:51 - (Reply)

    A perfect tutorial indeed..installing LAMP was a piece of cake..earlier I was using lampp but thought of doing these things on my own...

    #7 - Salvador 2008-02-22 20:24 - (Reply)

    Thanks a lot, Very Clear and now running like a rabbit! kill the Windows turtle :-)
    Greets to all!

    #8 - Solomon Chege 2008-03-03 04:59 - (Reply)

    Yes. A well written tutorial. Clear and to the point, complete with illustrations. I have installed all these before on Ubuntu Dapper, But I still found the tutorial good today when I installed a new server Ubuntu 7.

    Please notify readers that for really new Ubuntu 7 installation, it needs "sudo aptitude update" before anything else.

    Solomon

    #9 - E I Rutter 2008-03-13 15:50 - (Reply)

    Easy to follow; first class.

    But, how do I get phpmyadmin to start - the one pice of information that was missing.

    Upto now I have been using a WinXP XAMPP, with phpmyadmin, configuration and the NuSphere IDE for php development.

    What IDE would you recommend for a Ubuntu Desktop LAMP configuration.

    Many Thanks,

    Ivan

    #9.1 - Joey said:
    2008-03-13 19:27 - (Reply)

    Hey Ivan,

    Thanks.

    phpMyAdmin will 'start' as soon as Apache and MySQL are started. Once they're started up you should be able to browse it just like you would any other directory on your server. I'll make this a little more clear in the article, sorry for the confusion.

    #10 - ayong 2008-03-30 23:59 - (Reply)

    good tutorial, thanks...

    #10.1 - Scoobie 2008-04-27 20:50 - (Reply)

    Hey there,
    Thanks for a great tutorial, easy to follow and explains things clearly. Apache is giving me a few problems though, when I restarted I got this:
    apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

    And now Apache wont start, any idea what broke?
    Cheers

    Scoobie

    #10.1.1 - stormwild said:
    2008-05-01 09:32 - (Reply)

    Hi Scoobie,

    Did a quick google search for the error and found a link to the Apache wiki:

    http://wiki.apache.org/httpd/CouldNotDetermineServerName

    I'm still learning more about Apache so I'm not sure if it will solve the problem you're having.

    There's also an Ubuntu forum post which discusses the same or similar problem.

    http://ubuntuforums.org/showthread.php?p=2874560

    Anyway, hope it helps.

    Regards,

    stormwild

    #11 - Sascha 2008-05-08 17:34 - (Reply)

    Great tutorial! Runs perfect! Thanks a lot...

    #12 - Anonymous 2008-05-24 19:10 - (Reply)

    Thanks a lot! Very useful to me!

    #13 - Vijay 2008-07-05 22:55 - (Reply)

    Awsome tutorial - simple and it works.
    Thanks.

    #14 - Pakde Pakdoz said:
    2008-07-25 14:42 - (Reply)

    Hi, to get PHPmyAdmin working, I make configuration on apache2.conf:

    sudo nano /etc/apache2/apache2.conf

    Scroll right to the bottom of the file that opens, and add:

    # Enable PHPMyAdmin
    Include /etc/phpmyadmin/apache.conf

    Now save, exit, and type:

    sudo /etc/init.d/apache2 restart

    #15 - Tore said:
    2008-08-29 15:05 - (Reply)

    Wow! Thanks for a great guide. Everything worked and it was quick and easy. Almost to good to be true :-)
    Hugs and kisses from Sweden! /Tore

    #16 - saxan 2008-10-19 13:38 - (Reply)

    thank u so much for this wonderful help..
    i still cant believe i did it so easy and found everything fine..
    thanks so much for the comments too..
    looking forward to see more from u..


    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