August 8, 2007 · Server · Email This Post

Sponsored Link
For this article, I'll assume that you already have Ubuntu installed. It's one of the easiest distro's out there to install, ranking right up there with Fedora and Suse. After installation is complete, and you log in for the first time, you'll most likely be prompted to install updates. Install these updates and reboot before continuing. Typically, you don't need to reboot after an update, but just in case you updated your kernel, go ahead and do it.

Now, let's get to it.

Open a terminal window and run the following commands:

sudo apt-get install apache2 mysql-server php5 libapache2-mod-php5 php5-xsl php5-gd php-pear libapache2-mod-auth-mysql php5-mysql

sudo sed -i ‘s/; extension=mysql.so/extension=mysql\.so/g' /etc/php5/apache2/php.ini

#That's a series of 3 spaces after ‘s/;

sudo /etc/init.d/apache2 restart

Reboot and you're done!

What do those commands do? Well, the first one installs all of the packages needed. The second one uses sed to remove the semicolon (which denotes a comment) from the php config file, thus allowing php to work with mysql. The third one simply restarts apache.

In the above commands, there should only be 3 lines. Your display settings may cause the commands to span more than 3 lines. If so, just copy and paste line by line. Each command begins with sudo.

Sponsored Link

Incoming search terms:

Related posts

20 Comments to “Install the LAMP stack with 3 commands!”

  1. Mark Preston says:

    James:

    Why don’t the three (3) spaces show in the line on this page?

    sudo sed -i ’s/; extension=mysql.so/extension=mysql\.so/g’ /etc/php5/apache2/php.ini

    using my cursor, I can move only ONE space between -i ‘s/; extension . . .

    Please clariy.

    [Reply]

  2. Zorro says:

    Non-breaking Space
    The most common character entity in HTML is the non-breaking space.

    Normally HTML will truncate spaces in your text. If you write 10 spaces in your text HTML will remove 9 of them. To add spaces to your text, use the   character entity.

    the text below will give you an example (paste it in a test.html file and try it out):

         these are 4 spaces by using ‘    ’

    [Reply]

  3. Zorro says:

    @Mark,

    Non-breaking Space
    The most common character entity in HTML is the non-breaking space.

    Normally HTML will truncate spaces in your text. If you write 10 spaces in your text HTML will remove 9 of them. To add spaces to your text, use the   character entity.

    the text below will give you an example (paste it in a test.html file and try it out):

         these are 4 spaces by using ‘    ’

    Z:-)

    [Reply]

  4. i5513 says:

    ‘\.’ should be used into regular expresion on sed.

    Better:
    sudo sed -i ’s/; extension=mysql\.so/extension=mysql.so/g’ /etc/php5/apache2/php.ini

    [Reply]

  5. smoovb says:

    smoovb@s3rv3r:~$ sudo sed -i ’s/; extension=mysql\.so/extension=mysql.so/g’ /etc/php5/apache2/php.ini
    sed: -e expression #1, char 1: unknown command: `
    bash: /etc/php5/apache2/php.ini: Permission denied

    I get this error when I try to use the second command. In addition, I tried the command with 3 spaces after “’s/;” and receive the same results.

    Any suggestions?

    [Reply]

  6. James House says:

    I don’t know why the sed command isn’t working for you.
    Try this instead… it’s just a few more steps.
    sudo nano /etc/php5/apache2/php.ini

    Type CTRL-W to search. Search for extension=mysql.so
    Remove the leading semicolon.
    CTRL-X to exit, save the changes.
    Then, sudo /etc/init.d/apache2 restart
    to restart Apache.

    [Reply]

  7. Thomas says:

    Why does the user have to reboot? If the services are up, there’s no point in doing this…you must be too used to Windows.

    [Reply]

  8. James House says:

    Yeah, you caught me. That must be it. :-)

    [Reply]

  9. Jo-Erlend Schinstad says:

    You can use tasksel for that. If you’ve ever done an installation from the server cd or dvd, then you’ll have noticed it. It’s the part that lets for choose LAMP, DNS, etc. Install and run it, and you’ll get some choices, like LAMP, DNS, Edubuntu server, etc.

    [Reply]

  10. Fabio says:

    I think in Apache 2 you don’t need the second command, it seems to work without that substitution.

    [Reply]

  11. Lucas says:

    Hey, nice easy work. Thanks heaps.

    It might not have worked for @Smoovb if he did a copy/paste – ie if your browser converted the regular single quote (‘) to an angled one, then the shell won’t like it.

    [Reply]

  12. noob1 says:

    Got this error for some reason:

    sudo /etc/init.d/apache2 restart
    * Restarting web server apache2 apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
    apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName

    Can someone explain what went wrong?

    [Reply]

  13. hemanth says:

    * Restarting web server apache2 apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
    apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName

    [Reply]

  14. admin says:

    @Hemanth

    open /etc/apache2/apache2.conf

    sudo gedit /etc/apache2/apache2.conf

    find the following line

    ServerName

    change

    ServerName

    save and exit the file

    restart apache webserver

    sudo /etc/init.d/apache2 restart

    [Reply]

  15. hemanth says:

    I did that but if i try to login to mysql , i am getting this

    #2002 – The server is not responding (or the local MySQL server’s socket is not correctly configured)

    [Reply]

  16. admin says:

    @Hemanth

    This is mysql server error

    First you need to check mysql server is running or not

    try to start using the following command

    sudo /etc/init.d/mysql start

    Check the log messages

    cat /var/log/messages | grep mysql

    [Reply]

  17. aminul says:

    guys, i am super nobie in ubuntu. i have no idea why it comes:
    root@aminul-laptop:/home/aminul# sudo apt-get install apache2 mysql-server php5 libapache2-mod-php5 php5-xsl php5-gd php-pear libapache2-mod-auth-mysql php5-mysql
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Couldn’t find package apache2
    root@aminul-laptop:/home/aminul#

    please note that, i am not confident my ubuntu is installed properly. i don’t have much knowledge of ubuntu.

    how to resolve the issue and enjoy lamp ?

    [Reply]

  18. Jared says:

    For anyone who’s interested, this also works on the latest karmic. Note the second command should have regular quotes, as opposed to the backquotes listed

    [Reply]

  19. Travis DePrato says:

    @Aminul

    sudo gedit /etc/apt/sources.list

    Make sure you have:

    deb http://us.archive.ubuntu.com/ubuntu/ OS main restricted
    deb http://us.archive.ubuntu.com/ubuntu/ OS universe
    deb http://us.archive.ubuntu.com/ubuntu/ OS multiverse

    #Sources – Optional
    deb-src http://us.archive.ubuntu.com/ubuntu/ OS main restricted
    deb-src http://us.archive.ubuntu.com/ubuntu/ OS universe
    deb-src http://us.archive.ubuntu.com/ubuntu/ OS multiverse

    Substitute OS with your version.

    Eg: hardy, karmic, intrepid

    [Reply]

  20. Will The Computer Guy says:

    I’ve tried many ways to get a working LAMP stack on my local Ubuntu box for a while. However, I don’t want Apache and MySQL running all the time. My home Ubuntu box isn’t that powerful. I found that XAMPP from ApacheFriends.org is a very easy way to have a local LAMP development environment.

    http://www.apachefriends.org/en/xampp-linux.html

    You can install it in your home directory so you don’t have to worry about global permissions. I don’t work for ApacheFriends.org, but am just an extremely satisified user. It works really well on Linux or Windows.

    [Reply]

Leave a Reply