Open Source

Quickly Install a LAMP server on Ubuntu

Many times Jack Wallen has been asked for help putting together a LAMP server. With that in mind, Jack highlights the quick and easy steps to installing a LAMP server on a running Ubuntu machine.

I can't tell you how many times I have been asked what is the fastest, easiest way to install a LAMP (Linux Apache, MySQL, PHP) server on Ubuntu. Well, I guess it's time I just post it here for everyone to enjoy.

I am going to assume that this server does not have any of the components pre-installed. I am also going to assume you have sudo permission for the server. So starting with a blank slate we will first install Apache. To install Apache you will need to issue (from a terminal) the command:

sudo apt-get install apache2

Once this is installed you want to make sure Apache is up and running, so fire up your browser and point it to http://localhost (or you can use the servers' IP address). If you get the message "It Works!" you are good to go.

With Apache installed, let's move on. The next step should be installing PHP. To get php installed so that it will have everything it needs to integrate with Apache issue the command:

sudo apt-get install php5 libapache2-mod-php5

Before Apache can see that php is installed you will have to restart Apache like so:

sudo /etc/init.d/apache2 restart

Time to test to make sure php is working. Create a file within /var/www/testphp.php with the following contents:

< ?php phpinfo(); ?>

save that file in /var/www/ and then point your browser to that file. If all is well you will see the text, "Test PHP Page." If you see that, you can move to to...

The next step: MySQL.

To install the necessary tools, issue the command sudo apt-get install mysql-server. Once the system is installed it gets just a bit tricky. You have to first set a password for mysql. To do this, run the first command in order to get to the mysql prompt and the second to set the password:

 mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('YOURPASSWORD');

Where YOURPASSWORD is the actual password you want to use for the root user.

You're done. You now have a basic LAMP installation. Of course I would suggest taking this further by installing phpmyadmin in order to make creating MySQL databases much easier. But other than that, you are ready to install applications that require the LAMP configuration.

Delivered each Tuesday, TechRepublic's free Linux and Open Source newsletter provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!

About

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website getjackd.net.

11 comments
draalinx
draalinx

For those looking for a step by step (screenshot + text) guide of how to install LAMP. I have one I wrote if I can share it here: http://draalin.com/installing-lamp-in-ubuntu/ I wrote the installation for two different methods. 1) Tasksel install 2) apt-get install I also included ways to test each part of the LAMP installation in Ubuntu so you know that it did indeed install properly! With testing: 1) Apache2 with a website 2) PHP with a simple php script 3) MySQL with logging in. If you have any questions just ask!

Tony Hopkinson
Tony Hopkinson

you use an appeals to appliance users distro to deploy a web server? That's like that IIS cut down they did for windows 95. Personal web services, wasn't it?

cmahon90
cmahon90

you need to edit your test code for php5. Left me puzzled for hours until I figured it out. It should be: Your code reads: < ?php when it should be

pgit
pgit

From a lot of experience (though with Mandriva) it is a good idea to install and get apache working first, before installing the others. Never figured out why, but every failed install I've experienced I'd installed everything all at once, or loaded MySQL and/or PHP first...

raymondday
raymondday

Install Ubuntu you can pick LAMP that = Linux Apache, MySQL, PHP that start of all them letters. That's what so good about Ubuntu it will ask if you want a LAMP server. If you did not pick that can install them later with some command shown here.

bearsaxman
bearsaxman

It would be considerably easier, since you're using apt-get, to run the following: sudo apt-get install lamp-server^

tswatling
tswatling

Type (in terminal): sudo tasksel Select LAMP server and press enter. It will ask you for a MySQL root password. That's it.

seanferd
seanferd

I'm surprised the one angle bracket even shows up, but you may have used an entity for that?

llauren
llauren

Yeah but how much of a blog post would you get with that? ;) Another really quick way to install LAMP with a really fresh install is to use the Ubuntu Server distribution and checking in that you want LAMP when you install. Ah the ease of Linux! ~rL

raymondday
raymondday

I typed "tasksel" in a terminal and it came back with a list and just do the up and down arrows and space bar to pick what ones to install. Looked like this: Package configuration ?????????????????????????? Software selection ?????????????????????????? ? You can choose to install one or more of the following predefined ? ? collections of software. ? ? ? ? Choose software to install: ? ? ? ? [ ] Basic Ubuntu server ? ? ? [ ] DNS server ?? ? ? [ ] Edubuntu server ? ? ? [*] LAMP server ? ? ? [ ] Mail server ? ? ? [*] OpenSSH server ? ? ? [ ] PostgreSQL database ? ? ? [ ] Print server ? ? ? [*] Samba file server ? ? ? ? ? ? ? ? ? ? ??????????????????????????????????????????????????????????????????????? Press the down arrow and it goes down the list showing more. Press the tab so it goes to the OK and press Enter on it to exit and it does nothing if you did not make a * with the space bar on any thing. Stuff like this is why Ubuntu is a good Linux and why I use it. -Raymond Day

jlwallen
jlwallen

that was going to be my next blog. well, that and a few extras. but thanks for mentioning it. i sort of knew someone would point it out. now i will say i have had some issues with that install method hanging a lot. but when it doesn't hang, it is a very simple means of installing LAMP.

Editor's Picks