Simple Ubuntu Server: Part 10 – Setting up the LAMP Stack

In Part 10, I will cover setting up the LAMP (Linux, Apache, MySQL, PHP) stack in the server version of Ubuntu 12.04.2 LTS. The LAMP stack are the core components that make up a general purpose web server.

You can use tasksel to install the LAMP stack, but be fore-warned, DO NOT UNCHECK ANY BOXES. There is a bug (which may or may not be fixed/changed by the time you read this) that can cause your system to be unusable if you do so. Basically what happens if you uncheck one of the boxes is that upon hitting <Ok>, the system forcefully removes all the dependencies of that package all the way until there is nothing left. Not good!

Before I get into how to use tasksel, there is an alternate way to install the LAMP stack (which is arguably much better/safer). To use the alternate method, use the following command (where the caret means that you saying you want to install a package normally installed with tasksel):

sudo apt-get update
sudo apt-get install lamp-server^

If you want still want to use tasksel, I’ll show you how. Just remember not to uncheck anything. You will need to install it if it is not already installed:

sudo apt-get update
sudo apt-get install tasksel

Then run it:

sudo tasksel

or simply install the LAMP stack directly with running it as in the above command:

sudo tasksel install lamp-server

I ran tasksel to show you the process if you choose to do so (sudo tasksel then selected LAMP server from the options). In order to navigate, use the arrow keys to move up/down, space to select (remember not to deselect!), then tab to switch to <Ok>, and hit enter when you are finished.

tasksel package configuration

tasksel package configuration

tasksel will then download and install the required packages.

tasksel install screen

tasksel install screen

Part way through the install, you will be prompted to enter a password for the MySQL root user. Go ahead and do so now:

MySQL root user password

MySQL root user password

and then verify the password you just entered:

MySQL password verification

MySQL password verification

When installation has completed tasksel will quit without so much as a notification.

tasksel installation complete

tasksel installation complete

To check that PHP is working, create the file info.php:

sudo vi /var/www/info.php

type in the below text, then save and exit:

<?php phpinfo(); ?>

Next, restart Apache2:

sudo service apache2 restart

at which point you’ll probably get an error that looks quite similar to this:

Apache2 error

Apache2 error

That error is expected right now because the httpd.conf file isn’t configured. Just leave it for now (it’s just a warning, not an error) and we’ll come back to it at the end. Instead, you should open a web browser and browse to the following location (note you’ll need to change your IP address from what I have shown if you use the IP address method, or browse from the server machine itself if you use the localhost method):

http://192.168.1.105/info.php
-or-
http://localhost/info.php

If it is working properly, you will be greeted with a page that looks like this:

info.php page

info.php page

Next up, you’ll need get the package phpmyadmin to manage your server databases:

sudo apt-get install phpmyadmin

You should be prompted for which web server you want to use (I’m using Apache2 here, but you can use either. lighttpd is *arguably* a better choice especially in terms of RAM usage when serving many simultanious connections, but none-the-less…)

Configure which web server

Configure which web server

The database configuration prompt is next. Select <Yes> by hitting enter when it is highlighted.

Database configuration

Database configuration

Followed by another set of admin passwords and their verifications:

Admin password

Admin password

MySQL password

MySQL password

Password verification

Password verification

When finished, you should be able to access the configuration page for phpmyadmin in the same method as the info.php page.

http://192.168.1.105/phpmyadmin
-or-
http://localhost/phpmyadmin

Which will bring you to the login page (note that the default username is root and the password is the one you entered above):

phpMyAdmin login page

phpMyAdmin login page

phpMyAdmin home page

phpMyAdmin home page

Finally, check that Apache2 is working by going to the index.html page:

http://192.168.1.105/index.html
-or-
http://localhost/index.html

where you should be greeted with a page that looks like this:

Apache2 index.html page

Apache2 index.html page

At this point, everything should be working and you’re ready to roll.

To get rid of the error message that occurs when you restart apache2, you will need to edit it’s configuration file:

sudo vi /etc/apache2/httpd.conf

and add the line (note that at this point the file is empty):

ServerName localhost

and restart:

sudo service apache2 restart

And you’re good to go!

Tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.

Protected by WP Anti Spam