SEARCH

How-To Geek

How to Turn Your Home Ubuntu PC Into a LAMP Web Server

banner

Got a Linux PC you want to put to work? Maybe you’re not comfortable with the command-line only version of Ubuntu Server Edition. Here’s how to keep the standard Ubuntu desktop and add web-serving capabilities to it.

Whether you’re not comfortable with a command-line only system, you’re using your Ubuntu desktop for other things, or you just need it installed for a few particular apps, you can add Apache, MySQL, and PHP to any standard desktop installation of Ubuntu very quickly and easily.

The Simple Command

Let’s start installation with the use of a very clever command:

sudo apt-get install lamp-server^

It will NOT work without the caret at the end. Once you’ve got that entered, you’ll see that it auto-selects all of the necessary packages and will ask you to confirm the “large” amount of data to be downloaded.

02 confirm

Just sit back and let it do its thing until you get a blue screen pop up.

03 mysql root password

Enter a password for the MySQL root account, which is what you’ll need to create other users and manage databases, then hit Enter to continue. You’ll be prompted to re-enter your password, so do that and hit Enter again.

That’s it for installation!

Testing Apache and PHP

Let’s test Apache to see if it’s serving properly. Open up a browser and direct it the following URL:

http://localhost/

You should see something like this appear if everything installed correctly:

05 testing apache

Next up, we’ll test to see if PHP is working. In terminal, enter the following command to create a new document:

sudo nano /var/www/testing.php

Then, copy the following code:

<?php phpinfo(); ?>

Right-click in your terminal and hit paste.

07 phpinfo

08 nano write-out

Hit CTRL+O to “write-out” or save the file, and then hit CTRL+X to quit.

Next, restart Apache with the following command:

sudo service apache2 restart

And load up the following page in your web browser:

http://localhost/testing.php

And you should see something like this:

10 php success

Checking MySQL Bind Address

MySQL has a bind address that should match your system’s. To check your system’s bind address, we can use a quick command:

cat /etc/hosts | grep localhost

That’s a “pipe” or a “stem” in the middle, which is shared with the \ key. You’ll get a couple of results, one of which will show you an IP address.

11 find localhost bind address

You can see from the screenshot above that my bind address is 127.0.0.1.

Next, let’s open up the MySQL config file to see what’s listed there.

sudo nano /etc/mysql/my.cnf

Scroll down until you see a line beginning with “bind-address” like below.

12 my.cnf bind address good

As you can see, the bind-address is the same, so we’re good. If yours is different, just change it so it matches what you found above.

Installing phpMyAdmin

If you’re not familiar with MySQL and its commands, then you may have some trouble managing databases and tables. phpMyAdmin helps you tackle that by providing a PHP interface for MySQL administration. It’s easy to install and can really come in handy, so let’s get to it.

sudo apt-get install phpmyadmin

If this command doesn’t work, you may need to enable additional repositories.

14 installing phpmyadmin

You’ll get another blue screen come up asking you to choose which web server to configure. Make sure the red block is next to “apache2” and be SURE to hit the Space bar. This will mark it with an asterisk, and then you can hit Enter.

15 select apache2 for phpmyadmin

You’ll be asked if phpmyadmin should configure a default database for its own use. Choose Yes.

16 yes to default db

Next, you’ll be asked to enter the password of the admin account used to create this database and user. Since we haven’t created any other MySQL users, enter your MySQL root password.

17 enter mysql root password

Lastly, you’ll create a password to use with phpmyadmin, and you’ll have to confirm it again.

18 password for phpmyadmin

Once you’re done, restart Apache.

You can log in to phpMyAdmin by going to the following URL:

http://localhost/phpmyadmin/

20 phpmyadmin success

Use “root” as the username and then enter the root MySQL password.

21 login success


There’s more than a few important passwords here, and you’ll be tempted to use the same password as your root account. If you choose to do this, be sure that it’s a very secure password, something with mixed character classes and a good length. Remember, you are giving others access to your computer by installing this software, so take proper precautions.

If this is your first time playing with a web server, you may be wondering where the files you want to host go. They’re in /var/www/ be default, and will need elevated privileges to access that directory. One idea is to mount a separate partition to that point to be used solely for serving web stuff. Check out our other article, What is the Linux fstab and How Does It Work?, to get some more information for that.

And, now that you have your own web server, why not learn How To Archive, Search, and View Your Tweet Statistics with ThinkUp?

Yatri Trivedi is a monk-like geek. When he's not overdosing on meditation and geek news of all kinds, he's hacking and tweaking something, often while mumbling in 4 or 5 other languages.

  • Published 02/4/11

Comments (22)

  1. Groff

    Spelling mishap in the last part ” you may be wondering where the files you want to host go. They’re in /var/www/ be default,” Probably should say “by default” :D

  2. cgbolton1

    It’s so funny that this gets posted on How-to-geek today. I had to setup my Ubuntu 10.10 laptop this way earlier in the week so I could test some new PHP pages. In addition I wanted to work on integration of WordPress into an existing web site so installing XAMPP for Linux (LAMPP) was my solution. It works great and does not impact the overall performance of my Core 2 Duo 1.8Ghz Dell Latitude D630 laptop. If you are a web developer and you need to work on the go, then I highly recommend setting this up!

  3. vlasnn

    when I’ve tried to install it, I have to solve a little problem, the folder www, didn’t gave me the rights to write files or read them, then with chmod and chonw i sort the rigths of my user out, but each time that i copy a folder from win to ubuntu i have to do the same again.

    Is any way to avoid it? Thanks

  4. muhsan

    @vlasnn
    yes you can solve this problem by :
    1- go to terminal and write ” sudo nautilus ” with out quotation mark ,than type you password
    2- go to “/var ” path .
    3- right click in www folder , select properties.
    4- go to permission tab.
    5- change the owner to your username , and folder access to “create and delete files” also change file access to “read and write” .
    screen shut : http://i.imgur.com/Habyj.png
    6- click ok and finish :)

  5. pitman

    @cgbolton1: All HTG users are monitored, thus its no wonder they know what you want to do.

  6. Jonneh

    Bit of a newbie to servers here. I’ve got some small html files hosted in the /var/www folder to test this out (everything went ok with the install). How do you access this from other computers? just point a browser to the IP address of the linux box? Will this work with a virtual ubuntu OS in virtualbox?

  7. Jack

    Hi, Im having trouble with the “sudo apt-get install lamp-server^” command… I get the response of;

    E: Unable to locate package lamp-server^
    E: Couldn’t find task ‘lamp-server’
    E: Couldn’t find any package by regex ‘lamp-server^’

    Any ideas?

  8. RedTalon

    @Jack
    Try the same command, but leave off the caret. The caret is only required on older versions.

    sudo apt-get install lamp-server

    If that doesn’t work make sure you have tasksel installed by using this command.

    sudo apt-get install tasksel

    Then issue this command to install the LAMP Server.

    sudo tasksel install lamp-server

  9. RedTalon

    Nice article Yatri. Very Informative. Now, how about an article on getting your website to work from your home server when a vistor goes to “my_domain_name.com” from their browser. I know the steps involved but have never been able to get this to work successfully.

  10. tjX

    Great. Next: WAMP server?

  11. brunorios

    it’s possible to choose which version of php i’ll install? i need an earlier version of php… thanks

  12. Dutch70

    I second what RedTalon said. How bout an article on getting it to work. So you can create a web page and someone else can view it from say… across town, or the state.

  13. Tommy Bengtsson

    I can´t open phpmyadmin
    but Ihave creating a config file
    This I could read in the terminal
    Creating config file /etc/phpmyadmin/config-db.php with new version
    granting access to database phpmyadmin for phpmyadmin@localhost: success.
    verifying access for phpmyadmin@localhost: success.
    I couldn`t open phpmyadmin
    creating database phpmyadmin: success.
    verifying database phpmyadmin exists: success.
    populating database via sql… done.
    dbconfig-common: flushing administrative password
    Handle release for libc-bin …
    ldconfig deferred processing now taking place
    As you can see everything was success
    After that I restart apache and I got this answers:
    sudo service 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
    … waiting apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName

    I have ubuntu classic in 11.04

    I hope you can help me
    Tommy

  14. RuBiVn

    Hello.

    i have a problem. i did step by step in tutorial.but i can’t found http://localhost/phpmyadmin .
    http://farm3.anhso.net/upload/20110508/17/o/anhso-171502_Screenshot-1.jpg

    Thank.

  15. Phoenix

    It works! Thank you for this site

  16. deleon

    how do i acsses this from another computer

  17. Phil

    Great post! Thanks a million.

  18. Ben

    @RuBiVn and @Tommy Bengtsson

    You may need to add a line at the end your /etc/apache2/apache2.conf file. See below:

    Include /etc/phpmyadmin/apache.conf

    The info on this can be found at https://help.ubuntu.com/community/phpMyAdmin

  19. Kaustubh

    Thank u for ur info ,
    My problem is that alll the installation is complete but when i put http://localhost/phpmyadmin/ it says 404 not found please help me … :)

  20. Abhijit

    Thanx!!! Keep up the great work!!!

  21. as

    ewtywe

  22. Kari

    Thanks for the article, this is going to come in so handy next week…

Get Free Articles in Your Inbox!

Join 134,000 newsletter readers

Email:

Go check your email!