Andy Hawthorne

I write and I code.

Install a LAMP Setup for Ubuntu 11.10

Setting up a local development environment in Ubuntu 11.10 is useful. It allows you to develop web applications in your own sand-boxed environment. Below I explain one way to get a working set up.

You can use the lamp-server package that Ubuntu has available to get the main components installed. From the command line type:

sudo apt-get install lamp-server^

Enter your password, and then you’ll be presented with a screen that looks something like this:



Type a ‘Y’ for yes here, and wait while the required files are downloaded.

You will be prompted to enter a password for MySQL:



Enter a password of your choosing, and then the installation will continue. Once it completes, open your browser and got to http://localhost:

You’ll be presented with the default Apache welcome page. So far so good. Next, we’ll install phpmyadmin so that we can work easily with MySQL. Back on the command line, enter this:

sudo apt-get install phpmyadmin

As the installation runs through, you’ll be prompted to select the web server that you want to use with phpmyadmin. We are using Apache, so use your space bar to select that option, then hit OK:

Next, you will asked to set up dbconfig-common:

Say ‘Yes’ to this. You will then be prompted for your MySQL password a couple of times, then the process will complete. You should now be able to go to
http://localhost/phpmyadmin, log in, and see the main interface:

Now it’s time to configure Apache a little bit. First, we’ll make sure that we can use pretty url’s in our PHP web apps by turning on mod_rewrite:

sudo a2enmod rewrite

You will then need to re-start Apache:

sudo service apache2 reload

Now we’ll create a virtual host. This will allow us to create a www folder in our home directory, and also create locally resolving names such as mysite.dev.

Back on the command line, make sure you are in your home folder:

cd ~/

Then make the www directory:

mkdir www

Next, we’ll go through the process of copying the default Apache site config, adding our own virtual host details to the copied file, enabling the new site, updating the hosts file, and finally restarting Apache:

  1. Back on the command line do:
    cd /etc/apache2/sites-available
  2. Then we’ll copy the default file:
    sudo cp default yoursitename.dev

    Obviously replace ‘yoursitename’ with whatever name you want to use.

  3. Then, we’ll open the config file using Gedit:
    sudo gedit yoursitename.dev

    Delete the contents, and replace them with this:

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        serverName yoursitename.dev
    
        DocumentRoot /home/your user name/www
        <Directory />
            Options FollowSymLinks
            AllowOverride All
        </Directory>
        <Directory /home/your user name/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
        </Directory>
    </VirtualHost>
    

    Save and close the file.

  4. Next, we’ll need to enable the site:
    sudo a2ensite yoursitename.dev
  5. Then, add the sites to out hosts file:
    sudo gedit /etc/hosts

    Add the following line:

    127.0.0.1 yoursitename.dev

    Save and close the file.

  6. Finally, we’ll restart Apache:
    sudo service apache2 reload

    now, you should be able to got to http://yoursitename.dev in your web browser:

To make sure that everything works, create a file called info.php in your www folder and add:

<?php
phpinfo();
?>

Save and close the file, then navigate to the file in your browser (http://yoursitename.dev/info.php):

Success! Now you can repeat the process to create a virtual host for each project you are working on.

Tags: ,

3 Responses to “Install a LAMP Setup for Ubuntu 11.10”

  • Tom Lopez says:

    This is the best, most thorough, and easiest to follow step by step. When I help others I refer them to work that you have done. I used your written word to teach my son when I had him setup his first server. Thank you for the work you have done and making this bit of life a lot easier to understand.

    Thanks,
    Tom Lopez.

  • [...] Pro for local development. For Windows users, there is WAMP, and for Ubuntu Linux I have a guide here that shows you how to set up Apache,PHP and [...]

  • Elgandoz says:

    Thank you for your great guide! Anyway, I had to do this to get phpmyadmin working:

    sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
    sudo /etc/init.d/apache2 reload

    …because it was giving me a 404 on http://localhost/phpmyadmin.


Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Most Valued Blogger - DZone

 

February 2012
M T W T F S S
« Jan    
 12345
6789101112
13141516171819
20212223242526
272829  

Random Quote

When asked, “How do you write?” I invariably answer, “one word at a time.” — Stephen King

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Categories

Follow Me