Installing and configuring LAMP on Ubuntu - Part 2

Welcome back! In Part 1 of this tutorial, I looked at installing the tools you need to get your own web server up and running on Ubuntu.

We now have a working web server, but there are a few neat things you can do and we need to put some content on our default website too!. First of all, if you hadn't already worked it out, you can browse to your website by pointing your browser at http://localhost/.

By default, you won't see much on the homepage of your site.

Changing your homepage and adding content

Your website information is stored in /var/www - that is where you need to place the files for your website. Out of the box, you won't have write permission to this folder, so first of all we need to change that by changing the ownership of the folder to your user.

At a terminal, do the following (replacing yourusername with your login name):

$ sudo chown -R yourusername /var/www

Now, you can open up a file manager (from Places > Home Folder) and then navigate to /var/www. Simply place your HTML or PHP files in this folder and they will work as your website.

Testing that PHP is working

To make sure that your PHP installation is configured properly, you may want to run a quick test. Create a blank text file, call it phpinfo.php, and put this in the file. If you now save that file and view it in your browser, you should see a page looking something like this:

phpinfo

This means that your PHP installation is working properly.

Installing PHPMyAdmin

One of the easiest ways to manage your new MySQL database server is to use the graphical tool PHPMyAdmin. Now you can grab the source code and drop it inside a folder in /var/www, but there's actually an even easier way.

Simply go to your terminal again and enter the following command:

$ sudo apt-get install phpmyadmin

Now just point your browser at http://localhost/phpmyadmin/. Simple as that.

Installing web applications (WordPress)

One thing you might want to do with your server is install a web application onto it. In this example, I'm going to briefly show you how to install WordPress, one of the most popular blogging software tools (which we use here at FOSSwire). These steps can be adapted for most applications though. We can use the old apt-get trick here, but I'm not going to, as you might want to know the traditional way to install an application.

First of all, let's create a MySQL database for our WordPress installation. Head over to your new PHPMyAdmin installation, login with the username root and your MySQL root password that you set in Part 1.

Type wordpress in the create database box and click Create. When that finishes, click the SQL tab and type in the following:

GRANT ALL ON wordpress.* to wordpress@localhost IDENTIFIED BY 'newwordpresspassword';

Replacing the password with a new password that WordPress will use to connect to its database (make it a separate password from the root user's). Now download the .tar.gz WordPress package from wordpress.org (I'm using version 2.2 for this tutorial).

Once you've downloaded the package, right-click it and choose Extract Here to extract the archive. Now move the contents of the wordpress folder to the desired folder (I want my WordPress installation to be in a subdirectory called /blog on my web server, so I'm copying the files to /var/www/blog).

Open up the wp-config-sample.php file in your WordPress directory and change the following lines:

[php]define('DB_NAME', 'wordpress'); // The name of the database
define('DB_USER', 'wordpress'); // Your MySQL username
define('DB_PASSWORD', 'yourwordpressdatabasepassword'); // ...and password
define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value[/php]

Substituting in your password, obviously. Save that file, then rename it to wp-config.php.

Now browse to your new blog URL (in my case http://localhost/blog). From there, follow WordPress's easy install interface to set up your blog!

Finishing up

So we now know that our PHP is working properly, we have PHPMyAdmin set up and running and we've managed to install WordPress manually from the download on the site. Your LAMP installation is now officially up and running.

Of course, there's plenty more you can do and loads of PHP and MySQL based applications you can now download, install and give a try. If you're the developing type, you now have everything you need to start developing your PHP and MySQL based applications!

Avatar for peter Peter Upfold - http://peter.upfold.org.uk/

Peter Upfold is a technology enthusiast from the UK. Peter’s interest in Linux stems back to 2003, when curiosity got the better of him and he began using SUSE 9.0. Now he runs Linux Mint 9 on the desktop, runs a CentOS-based web server from home for his personal website and dabbles in all sorts of technology things across the Windows, Mac and open source worlds.

Home » Articles »

Discussion: Installing and configuring LAMP on Ubuntu - Part 2

  1. # Posted on 01 June 2007 at 11:02 AM

    [...] Posts Installing and configuring LAMP on Ubuntu - Part 2Welcome back! In Part 1 of this tutorial, I looked at installing the tools you need to get your own [...]



  2. Derek (guest)

    # Posted on 01 June 2007 at 03:11 PM

    I get the error " Your PHP installation appears to be missing the MySQL which is required for WordPress.".

    I did exactly as described above (god im such a loser:) What am i doing wrong? Im new to all things LAMP so would really like to get it going. I did retry things a couple of times. Seemed to go all ok I suppose till I create a new mysql database wordpress. Wordpress (0) creates ok and then I paste the code into the sql tab replacing the password with one ive made up... any ideas? thx D



  3. Peter (guest)

    # Posted on 01 June 2007 at 11:28 PM

    Did you follow <a href="http://fosswire.com/2007/05/29/installing-and-configuring-lamp-on-ubuntu-part-1/" rel="nofollow">Part 1</a> of this tutorial to get the initial software installed?

    If not, you might not have installed the MySQL database properly, so try this command:

    <blockquote class="terminal">$ sudo apt-get install mysql-server php5-mysql</blockquote>

    Alternatively, you may be able to get WordPress installed using the package manager (the easier way, but we showed the universal way in this tutorial):

    <blockquote class="terminal">$ sudo apt-get install wordpress</blockquote>

    That command should pull down the MySQL database server as a dependency and should configure stuff for you.

    Let us know in the comments how you get on!



  4. Derek (guest)

    # Posted on 03 June 2007 at 12:51 PM

    Hi. Well i redone everything and went 'by the book as they say...Everything seemed to work fine now...Dont know where i went wrong. This time i simply copied and pasted the apt-get commands for apache and mysql etc... roll on part 3 ;-) Thanks Derek



  5. Josh (guest)

    # Posted on 04 June 2007 at 12:37 AM

    This tutorial is what I have been looking for... amazing. Simple and to the point. I have been trying to set up a local mirror for my website, and couldnt seem to get LAMP to work... now I have it running great. Thanks for the info... =)



  6. Dan (guest)

    # Posted on 12 June 2007 at 08:56 PM

    I followed the tutorial word for word and nothing seems to be matching what I'm seeing in print. I am Using Ubuntu Feisty, as well, so I'm confused. First, my Apache2 ended up in /usr/local/apache2... not /var/www.

    Second, whenever I try to open a .php document in my newly created Apache setup, it tells me that I am trying to download a file of type .php... do I want to open it with GEDIT or save it to disk. What??? I want to view the web site... not save it as a file.

    What did I do wrong? It's probably something very simple...

    Thanks!



  7. hanifa (guest)

    # Posted on 15 June 2007 at 12:29 AM

    Great website... Most of the other websites i have seen , usually are talking about the Ubuntu Server edition... With this tutorial, I was able to set up the LAMP structure within 10 minutes...Kudos to U, guys



  8. Isal (guest)

    # Posted on 17 June 2007 at 09:20 PM

    Great Tutorial. I like it. Now I have clear guiance how to set up LAM server in Ubuntu. Thanks



  9. Christophe (guest)

    # Posted on 14 July 2007 at 06:26 PM

    Great tutorial indeed, However how do I use php as command line ? (I think i'll need it later to run cron jobs, php scripts ..)

    Should I install php5-cli to get PHP's interpreter in my shell ?

    Thanks!



  10. Tengku Asmadi (guest)

    # Posted on 28 July 2007 at 08:21 PM

    Thanks!

    It works! This is the easier and simple tutorial to get my LAMP and Worpress running. I never use Linux before but your article does help me a lot...

    God bless you.



  11. JohnMcC (guest)

    # Posted on 10 September 2007 at 09:56 PM

    Works like a charm. Thanks.

    If only all tutorials were as up to date and work as they are supposed to.



  12. Kris Stevens (guest)

    # Posted on 23 September 2007 at 07:50 AM

    Thank you so much for posting this wonderfully informative tutorial. I have just (in the last few days) moved over to Kubuntu from Windows Vista. I was previously running a WAMP server on my XP system but it was a nightmare trying to support it on Vista.

    I was advised to give Ubuntu a try, but found I preferred Kubuntu layout more. I was also advised to get the LAMP setup on the Ubuntu system. Now after a few days of tinkering with various pieces of software and even trying some Windows software using Wine and CrossOver, I decided to take the plunge and transfer my web server to the new system.

    I went on Google looking for the various bits I needed and was about to start setting them up - THEN I came across your tutorial.

    Bearing in mind I have never even seen a Linux system before this week never mind used one - I have manage to get the LAMP server up and running and configured in about 3 hours - It took me 2 days to sort out the WAMP version.

    Thanks again for such helpful advise.

    Kris Stevens West Yorkshire, UK



  13. Guesh (guest)

    # Posted on 21 November 2007 at 06:09 AM

    $sudo chown -R myusername /var/www

    I run this command, but couldn't be the owner of. I couldn't put any files to /var/www. When i see at the permisions only the root can read, write, and excute.

    This tutorial is superb. By the way, my ubuntu is ubuntu-6.10 somthing( i don't know if it has another name)



  14. Peter (guest)

    # Posted on 04 May 2008 at 07:43 PM

    hi Peter, my name is Peter too and I want only say to you,your lamp-tutorial is semantic-good or rhetorik-good,its simple good and understandable (my wordcreation !!) good times and thank you Peter



  15. Kris (guest)

    # Posted on 11 May 2008 at 05:05 AM

    Thanks for the Great Howto



  16. Darko Bunic (guest)

    # Posted on 30 July 2008 at 08:21 AM

    You are right, LAMP installation is easy to perform, but it will be good to take a little bit more care about increasing server security. In post installation configuration, minimize list of running services - turn off all needless services, rise up firewall (you can easily find firewall configuration for you need), forbid ssh root access, quiet you LAMP (hide apache / PHP version) ... all this tips can be useful, and if you want to read more: www.redips.net/linux/lamp-setup/



Home » Articles » Installing and configuring LAMP on Ubuntu - Part 2