Friday, April 13, 2012

Install LAMP in Ubuntu 12.04 Precise(Apache, MySQL, PHP)

This is a short guide to installing a basic LAMP(Linux, Apache, MySQL, PHP) development environment on Ubuntu 12.04 Precise Pangolin.

First install lamp:
Open a terminal and run the following:

sudo apt-get install lamp-server^

After the lamp server installation you will need write permissions to the /var/www directory.  Follow these steps to configure permissions.

Add your user to the www-data group

sudo usermod -a -G www-data <your user name>

now add the /var/www folder to the www-data group

sudo chgrp -R www-data /var/www

now give write permissions to the www-data group

sudo chmod -R g+w /var/www

now log out and log back in to see the changes reflected in nautilus.

Some extra things to install
The following are not essential but they are things I almost always need as part of a LAMP install so I have included instructions on installing them.

Curl:

sudo apt-get install php5-curl

Mod rewrite:

sudo a2enmod rewrite

GD2 Graphics Lib:

sudo apt-get install php5-gd


And that's it, how easy was that?  Ubuntu rocks!

23 comments:

  1. before doing all these steps, how can I tell if any of the components of LAMP are already installed in my system? I believe I already installed PHP using the GUI, and I don't remember if I did the same with apache. I wonder if I can install tomcat and struts in Ubuntu? Anyhow, thanks for this post!

    ReplyDelete
    Replies
    1. at the terminal run:

      php -version

      apache2 -version

      mysql --version

      If they are installed version information will be printed, if they are not it will say something about command not found.

      Alternatively you can just run the installation commands and it will tell you if it is already installed, if they are the installation will just continue to the next step and will skip installing that component.

      Delete
  2. Such a nice post - Thanks a lot!

    ReplyDelete
  3. Hey i am new to ubuntu. I recently installed ubuntu 12.04 and installed LAMP but while allowing permission to file system "sudo chgrp -R www-data /var/www" isn't working, any idea? please help.

    ReplyDelete
    Replies
    1. what error message are you getting?

      Delete
  4. where to change the dir for www? for example, i want that my server goes to /home/my/public_html/

    ReplyDelete
    Replies
    1. update the config file for the site, assuming you are running one site and it is the default edit:

      sudo gedit /etc/apache2/sites-enabled/000-default

      otherwise create a new site file with the appropriate paths

      Delete
  5. Replies
    1. Don't use it, i just use the command line client for mysql, i'm sure google will tell you

      Delete
  6. if you must http://www.webrichsoftware.com/?p=16 has the steps for the phpmyadmin addin

    ReplyDelete
  7. When I give the Command "sudo apt-get install lamp-server^" then an error message given,that is:

    E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
    E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

    How I overcome this problem ?? Plz tell me..

    ReplyDelete
    Replies
    1. You have something else running that is using the package manager, either synaptic, Ubuntu Software Centre or Update Manager. Just close whatever is already working with your packages, if you don't know what it is just reboot. The second line of error message is essentially telling you this.

      Or failing that just google it, there are literally tens of thousands of pages discussing this error.

      here is a link: http://justfuckinggoogleit.com/

      Delete
  8. Are you sure GD is as simple as installing php5-gd? I ask as on my server although 'php5 -i | grep gd' from the command line reports it's there phpinfo() from apache shows no trace of it and I'm getting a vibe from Googling about that there may be an issue with the security of the GD library which may have led the package maintainers to restrict access to it from Apache. Really bad news if so.

    ReplyDelete
  9. Heh, just removed and re-installed the package and it burst into life. Go figure.

    ReplyDelete
  10. Nice post! clear and concise... Time saver
    Many thanks!

    ReplyDelete
  11. Hi James
    Thank you very much for a clear concise guide.
    Much appreciated.

    ReplyDelete
  12. Hi,

    Thanks for pointing out all steps clearly. I am getting a problem though, whenever I copy paste files under www folder I have to run file permission and usergroup commands again or it just throw error that file is not accessible. Is there any workaround to do this automatically?

    Thanks!

    ReplyDelete
  13. I have a question the php project prepared for Ubuntu should be able to run on windows platform.

    php developer india

    ReplyDelete
  14. Since, Lamp Development platform is made up of components, which come from open source

    ReplyDelete
  15. Fantastic post, simple and easy! Thanks. Don't suppose you have another such post on how to set up subdomains (for development) on the apache server?

    ReplyDelete
  16. Thank you for the clear, concise post. Top work!

    ReplyDelete
  17. Nice post, really informative thanks for sharing this.

    Web Development Company

    ReplyDelete