Any web developer, designer, or webmaster can benefit from having a local web server. Even if that developer has no interest in securing and maintaining the server his or her websites live on, a local server can act as a convenient mirror for testing updates, trying new designs, and other general sand-boxing activities.
Web developers whose hosts utilize the popular LAMP platform (Linux + Apache + MySQL + PHP) are frequently hit with a dilemma. Since understanding Linux is not a prerequisite for website administrators, many of them lack the knowledge necessary for setting up a LAMP server from scratch (or at least they may think so). But thanks to the improved package management on Linux distributions like Debian, installing a functional web server is not nearly the chore it was just a couple years ago.
A note on security and other concerns
You may be wondering why I used the qualifier “local” to describe the web server we are about to set up. This is because our LAMP server will not be ready for prime-time, so to speak. For running a public server, you'll need a lot more than a tutorial to get you up to speed.
In this case, we'll be setting up a local server where security, stability, and backups are not nearly as important. So if you plan to set this up on your only computer or in your router's DMZ, consider yourself warned.
Where will we set this up?
So does this web server need to be set up on a secondary computer or can we set it up anywhere? Obviously, this will depend on your situation.
If you are on your Windows laptop, of course this won't work. There are actually easier options available if you want to do that. But if you are already using a Linux system, it's just as easy to set this up on that system.
For this demonstration, we'll be installing this LAMP server on a co-located server of mine. This will usually require a few extra security tweaks but will depend on your distro, as some won't allow any servers to listen to remote connections by default.
The basic Linux setup
Setting this all up assumes you have a running version of Linux already installed. I won't walk you through that part.
If you don't have one and have an old box you'd like to use, I'd suggest using Debian as we are about to. But if you are new to Linux, you might want to try using a hard disk installation of Knoppix as the procedure will be identical.
Of course, you aren't limited to Linux exclusively. All elements of LAMP (sans the Linux part) have been ported to most operating systems.
Setting up Apache
For the actual “web server” portion of our web server (i.e. the service sharing the web pages) we'll be using Apache 2. In addition to being free and open source, Apache is by far the most used web server software on the Web.
Either dropping to a shell or connecting remotely, we'll start by checking for updates to the Debian package lists. If you've done this recently or just did a fresh Internet-based installation, this won't be necessary. This will require root access.
lineman@soundwave:~$ su Password: soundwave:/home/lineman# apt-get update Get:1 http://security.debian.org stable/updates/main Packages [174kB] Hit http://apt-mirror.sourceforge.net apt-mirror/ Packages Ign http://apt-mirror.sourceforge.net apt-mirror/ Release Get:2 http://security.debian.org stable/updates/main Release [110B] Hit ftp://mirrors.kernel.org stable/main Packages Hit ftp://mirrors.kernel.org stable/main Release Hit ftp://mirrors.kernel.org stable/main Sources Hit ftp://mirrors.kernel.org stable/main Release Fetched 174kB in 3s (48.4kB/s) Reading Package Lists... Done
Now that we've updated out package lists, we'll tell Linux to go grab Apache. To fully install Apache, we'll need more than one package. Thanks to Debian's APT, we'll be able to download and install all those dependencies with minimal work.
soundwave:/home/lineman# apt-get install apache2 Reading Package Lists... Done Building Dependency Tree... Done The following extra packages will be installed: apache2-common apache2-mpm-worker apache2-utils Suggested packages: apache2-doc lynx www-browser The following NEW packages will be installed: apache2 apache2-common apache2-mpm-worker apache2-utils 0 upgraded, 4 newly installed, 0 to remove and 5 not upgraded. Need to get 1097kB/1131kB of archives. After unpacking 4018kB of additional disk space will be used. Do you want to continue? [Y/n] y
Although it isn't a requirement, APT suggested installing the Apache documentation. So we'll go ahead and install that just in case. It suggested Lynx too but we probably won't be needing that.
soundwave:/home/lineman# apt-get install apache2-doc Reading Package Lists... Done Building Dependency Tree... Done The following NEW packages will be installed: apache2-doc 0 upgraded, 1 newly installed, 0 to remove and 5 not upgraded. Need to get 0B/3861kB of archives.
Now we'll do a quick check to verify Apache is running.
soundwave:/home/lineman# /etc/init.d/apache2 start Starting web server: Apache2httpd (pid 11205) already running
So it looks like Apache is running, but let's not take that scripts
word for it. I mean, we're setting up a web server so why not use a
web browser? To do this, just plug the IP address of your server into
the address box of your favorite browser. This should forward you to
http://servername/apache2-default/ where you'll find a
page congratulating you on your successful Apache installation.

If you'd like to start by editing this sample page, it's easy
enough to do. The default Apache files are stored in
/var/www/apache2-default on your server.
To edit the English version of the page, we'll just have to use
Nano (or another text editor) to edit
/var/www/apache2-default/index.html.en.
soundwave:/home/lineman# nano /var/www/apache2-default/index.html.en

If you'd like to play with a few of Apache's settings, the main
configuration file is /etc/apache2/apache2.conf. Since
by default Debian will allow external connections to Apache, you may
want to limit connections to your localhost or local network only.
If you'd like to make web folders for individual accounts, all
that is needed to make a directory in the user's home directory
called /public_html. For example, if your username is
“lineman,” you'll need to mkdir
/home/lineman/public_html. Files stored in that directory will
then be viewable in your web browser at the address
http://servername/~lineman/.
At this point, if all you want to work on and host are static pages, you are done. But for those who want to do more interesting things using the LAMP platform, we'll move on.
Setting up MySQL
There are plenty of Apache-friendly database servers available, but MySQL is certainly a popular option. Again, this one is free and open source.
We'll start by installing MySQL in a manner similar to the way we installed Apache.
The following extra packages will be installed: libdbd-mysql-perl libmysqlclient12 mysql-client mysql-common Suggested packages: mysql-doc The following NEW packages will be installed: libdbd-mysql-perl libmysqlclient12 mysql-client mysql-common mysql-server 0 upgraded, 5 newly installed, 0 to remove and 5 not upgraded. Need to get 4523kB of archives. After unpacking 10.5MB of additional disk space will be used. Do you want to continue? [Y/n] y
Once MySQL begins to install, we'll get a brief warning screen. This is mainly to fill us in a little on how passwords will work. By default, the root user MySQL has no password (something you will want to change for a public server).

Before moving on, we'll make sure the MySQL service is running.
soundwave:/home/lineman# /etc/init.d/mysql start Starting MySQL database server: mysqld...already running.
If you'd like to change some of MySQL's settings from their default
values, take a look at the files located in /etc/mysql.
As with Apache, APT suggests we install the MySQL documentation. Just to be safe, we'll go ahead and do that.
soundwave:/home/lineman# apt-get install mysql-doc Reading Package Lists... Done Building Dependency Tree... Done Package mysql-doc is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source E: Package mysql-doc has no installation candidate
Unfortunately, this package has been removed from Debian. So if we want the documentation, we'll have to grab the documents directly from MySQL.com.
If you are already comfortable using MySQL from the command line, you can probably skip the section on phpMyAdmin further down. But if you aren't, phpMyAdmin will make your life much easier.
Setting up PHP
While HTML is a useful markup language, it lacks the sophisticated scripting ability that the modern Web user expects. This is where scripting languages like JavaScript, ASP, and PHP are needed. In particular, server-side scripts like those used in PHP and ASP provide a framework for building security-minded Web interfaces.
It is with good reason that most Linux-based hosts use PHP over ASP (and not because LAMA just doesn't sound all that desirable). PHP is a completely free and open source operating system. Cost aside, there are security considerations here. PHP has certainly not had a spotless record of security, but flaws are found much more quickly and are fixed almost immediately.
Now if you really want to use ASP, Apache can be made to support it. However, support is limited.
Most of us, though, are using PHP (hence the popularity of LAMP) so we'll go ahead and set it up. Again, this starts on the command line.
soundwave:/home/lineman# apt-get install php4 Reading Package Lists... Done Building Dependency Tree... Done The following extra packages will be installed: apache-common libapache-mod-php4 Suggested packages: apache apache-ssl apache-perl php4-pear The following NEW packages will be installed: apache-common libapache-mod-php4 php4 0 upgraded, 3 newly installed, 0 to remove and 5 not upgraded. Need to get 2460kB of archives. After unpacking 6357kB of additional disk space will be used. Do you want to continue? [Y/n] y
Since we will be using both PHP and MySQL on our server, we'll go ahead and install the PHP's MySQL module to help them play together better. We'll also install PHP's Pear extensions since so many packages will require it.
soundwave:/home/lineman# apt-get install php4-mysql php4-pear Reading Package Lists... Done Building Dependency Tree... Done The following extra packages will be installed: php4-cli Suggested packages: php4-dev The following NEW packages will be installed: php4-cli php4-mysql php4-pear 0 upgraded, 3 newly installed, 0 to remove and 5 not upgraded. Need to get 1860kB/1882kB of archives. After unpacking 5095kB of additional disk space will be used. Do you want to continue? [Y/n] y
There are a few other packages we'll need to install to get Apache working with PHP.
soundwave:/home/lineman# apt-get install libapache2-mod-php4 php4-cgi Reading Package Lists... Done Building Dependency Tree... Done The following extra packages will be installed: apache2-mpm-prefork The following packages will be REMOVED: apache2-mpm-worker The following NEW packages will be installed: apache2-mpm-prefork libapache2-mod-php4 php4-cgi 0 upgraded, 3 newly installed, 1 to remove and 5 not upgraded. Need to get 5024kB of archives. After unpacking 9441kB of additional disk space will be used. Do you want to continue? [Y/n] y
All the necessary packages are installed, but we aren't quite done
yet. Using your favorite text editor, we'll need to make some changes
to /etc/apache2/apache2.conf. First, locate the line
"#AddType application/x-httpd-php .php" and
un-comment the line by removing the # from the
beginning. Next, we'll need to add the line below.
LoadModule php4_module /usr/lib/apache2/modules/libphp4.so
To get those changes to take effect, we'll have to restart Apache. If we don't, web browsers will be downloading our full PHP files rather than Apache processing them first.
soundwave:/home/lineman# /etc/init.d/apache2 restart
To show that PHP is working, we'll make a small PHP file and stick it
in our web folder. Within the directory /home/lineman/public_html,
I'm going to add a file called index.php with the
following contents:
<?php phpinfo(); ?>
This will generate a PHP page at http://servername/~lineman/
that will tell us a lot about our PHP installation.

Setting
up phpMyAdmin
Don't listen to the people who'll tell you that you are cheating if you don't run MySQL from the command line. Not only is that method more difficult, but you risk doing more damage if you make a mistake.
phpMyAdmin is a web interface designed specifically for administering MySQL. While there are times that MySQL is best used directly (like when you are moving a 50 MB database to a new co-located server), phpMyAdmin is commonly used to handle day-to-day database issues.
The installation of phpMyAdmin is fairly straightforward.
soundwave:/home/lineman# apt-get install phpmyadmin Reading Package Lists... Done Building Dependency Tree... Done Suggested packages: php4-gd php5-gd The following NEW packages will be installed: phpmyadmin 0 upgraded, 1 newly installed, 0 to remove and 5 not upgraded. Need to get 2768kB of archives.
Once the installation begins, we'll be presented with a question about which web servers to reconfigure. Since we used Apache2, be sure to check that. When prompted, go ahead and have Apache2 restarted.

To
test out phpMyAdmin, we'll first point our web browser to
http://servername/phpmyadmin/. We will connect using the
username "root" and a blank password. Once we do,
phpMyAdmin will greet us with stern warning about our blank password.
Clicking on "Change password" will allow us to set one and
get rid of that warning.

Conclusion
There you have it – your very own web server to tweak and test on without fear of downtime for your own or your clients' websites! But I have to warn you about one thing; once you've learned all the things you can do on your own server that your shared host isn't letting you have access to, you'll almost certainly be shelling out extra cash every month for your own dedicated server.

Tech Articles
Rollie Hawk is a consultant, web publisher, online personality, magazine writer, web developer, network administrator, teacher, husband and father residing in southern Illinois. He graduated in 2002 from Southern Illinois University, earning his BS majoring in math with a minor in chemistry.