Installing a simple LAMP server on Ubuntu

If you do a lot of web stuff, it is nice to have a web server installed on a computer on your local network. It is a nice way to be able to test and develop websites.

I thought I would share the guide that I wrote one of my friends who wanted to install a simple web server with Apache, MySQL, and PHP on their Ubuntu Desktop. If you have Ubuntu installed, this guide should get you through setting up a simple LAMP. I also detail installing a simple firewall; phpMyAdmin, a web-based database utility; and mod_rewrite, a utility needed for WordPress and many other Content Management Systems.

Note: For code in this font, type the command into a Terminal window.

Install the web server

sudo tasksel

Select “LAMP Server” with the spacebar.
If you want to be able to SSH in, you can also select “OpenSSH Server”.

Your web server should be installed.  That was easy, huh.

Install the ufw firewall

Ufw is a very simple yet customizable firewall, perfect for a web development server.

sudo apt-get install ufw

You can configure this how you like once it is installed. If you do not need any ports other than http (80) and ssh (22) running what I run on my box (below) should work. Let me know if you need another configuration, and I can probably point you toward a guide.

This will essentially make your firewall deny anything that is not explicitly allowed:
sudo ufw default reject

This will allow anyone in the world to access your pages over http:
sudo ufw allow to any port 80

This will allow you to ssh into your server from your IP only:
sudo ufw allow from YOUR IP to any port 22

Install phpMyAdmin

This will allow you to edit your databases in a web-based environment at http://your-hostname/phpmyadmin.

sudo apt-get install phpmyadmin

To make it work properly, you will probably have to must add this line:
Include /etc/phpmyadmin/apache.conf

to the very bottom of the file here:
/etc/apache2/apache2.conf

Enable mod_rewrite

This is needed for WordPress to function properly the way it writes its urls.

First, you will need to activate it:
sudo a2enmod rewrite

Then, go to: /etc/apache2/sites-available/default

and look for AllowOverride. It needs to be changed “AllowOverride All” in each place that it appears in that file (4 times).

Keep the machine up to date

sudo apt-get update and sudo apt-get upgrade

You will want to run these commands frequently to make sure that your software is kept up to date.

Restart the machine. Your web server should be setup!!

Test the server

Visit the server. It should be available at http://yourhostname/.

Web files are stored in /var/www/ by default.

Go to http://yourhostname/phpmyadmin and make sure you can log in. If it is working, php and MySQL should be working.

Congratulations!  You just installed a web server on your computer, perfect for development work!

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>