This educational post will walk you through all the steps to getting a LAMP server running in short order, and with minimal expense. The single actual cost required for this project is a piece of hardware, a desktop, laptop, or server with minimal requirements, and an hour or two of your time, or less.
Minimum hardware requirements
You would actually be amazed as to how light a hardware system you will need in setting up a straightforward LAMP installation. The hardware requirements needed to install and run a marginal, low usage, and possibly static content-only website with limited images and little to no multimedia would call for a machine with 128MB of ram on an 800MHz CPU, and with a 1GB hard drive or less. A system such as the one described above would be a perfect system for learning purposes or as a sandbox to play around in as you learn the LAMP stack. You might find a system like this one sitting in the junk room at your office, at a garage sale, at an online auction site, or for free on the curb. The point here is that while the LAMP stack is a very robust web server, its principal operations do not require a lot of hardware resources in which to run. The hardware requirements become a larger consideration as you start to build the requirements of your web applications and the type of content you will serve to your web users. If you plan on providing services such as video streaming, file storage, news feeds, Flash, and have 50,000 page views a day, or will provide high-load demand resources — then the hardware needs to scale accordingly.
Operating system: Ubuntu
First, we will install Ubuntu as the Debian-based Linux operating system and it comes in two flavors, either 32 bit or 64 bit versions. The steps to getting started with installing the operating system are:
- Download the Ubuntu Server Edition and burn or save the ISO file to a CD or USB drive.
- Boot the system from the CD-ROM or USB drive.
- Select your language.
- Select "basic server install".
- Enter the appropriate options for language, keyboard layout, network configuration, hostname and time zone.
- Choose from several options to configure the hard drive layout; read more in the detailed documentation. Your Ubuntu server is now installed!
- Update your software repositories using the command line interface to execute the command: $ sudo apt-get update
- This command is the default program (apt-get) for installing software on Ubuntu.
- If you are not inclined to working from the command line then you can install Webmin which is a web-based GUI for system administration on UNIX based systems, including the Ubuntu system. For this implementation you will need to download the Debian package which is suitable for Debian, Ubuntu or other derived Linux operating systems. This is a good resource from the Ubuntu Geek, on How to Install GUI on Ubuntu Server.
Next, we will install the Apache Web Server which is actually fairly easy with Ubuntu, because it comes as an additional package option during the installation, or it can be added later. In this case, here is the command line code for installing Apache 2 to your Ubuntu Server:
$ sudo apt-get install apache2Once the installation is complete, you can open up a web browser and visit http://localhost/ or just put in the host IP address and you should see the following message in header text: "It Works!", as shown in Figure D.
Check for more details on configuring your Apache 2 server.
Next, install MySQL; from the command line, enter:
$ sudo apt-get install mysql-server
During the MySQL installation process you will be prompted to enter a password for the MySQL root user; as a rule of thumb it is best to create a password.
To check that your MySQL database is running you can enter the following on the command line:
$ sudo netstat -tap | grep mysql
You should now see the following line or something similar:
tcp 0 0 localhost:mysql *:* LISTEN 2556/mysqld
$ sudo apt-get install php5
Apache 2 will automatically restart once PHP5 is installed. By default, the Apache 2 Web Server is configured to run PHP5 scripts, and the PHP5 module is enabled in Apache 2 automatically when you install the module. Apache is a modular server, therefore only the most basic functionality is included in the core server. Extended features are available through modules which can be loaded into Apache. Next, you will want to verify if the files php5.conf and php5.load found in the /etc/apache2/mods-enabled/ directory do exist by changing the directory and viewing the files listed, from the command line terminal enter the following;
$ cd /etc/apache2/mods-enabled/
If they do not exist in the directory, you can enable the module using a2enmod command:
$ sudo a2enmod php5
Once you have install PHP5 related packages and have enabled the PHP5 Apache2 module, you should restart the Apache2 Web server to run the PHP5 scripts. You can run the following command at the Ubuntu terminal prompt to restart your web server:
$ sudo /etc/init.d/apache2 restart
Now that the core LAMP operating system and software is running there are just a few more things that need to happen.Apache mod_rewrite module
First we need to enable the rewrite module in Apache2 so that user-friendly URLs can be rewritten on the fly allowing runtime modification of the URL structure. Typically, this allows .htaccess files and commands to implement friendly URLs, and is found in many WordPress or other CMS type applications. For more details and optional information on .htaccess files, check out the Ultimate Htaccess guide available from AskApache.
Now, enable the module from the Ubuntu terminal command line:
$ sudo a2enmod rewrite
Next, from the Ubuntu terminal command line, change your directory to the following:
$ cd /etc/apache2/sites-available/default
When you open the file you will see a section that looks similar to:
Options Indexes FollowSymLinks MultiViews
allow from all
# Uncomment this directive is you want to see apache2's
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/
</Directory>Next, modify the line containing AllowOverride None to read AllowOverride All. This will instruct the Apache 2 server that it's okay to allow .htaccess files to over-ride previous directives. You must now restart the Apache 2 server before this change will have an effect with the following terminal line command:
$ sudo /etc/init.d/apache2 restart
Pete Freitag has this great list of 20 ways to secure your Apache Configuration, including ensuring your server has the latest security patches, hiding the Apache server version and other sensitive information from public view, ensuring that files outside of the web root are not being served, turning off directory browsing, turning off server side includes, among other great tips.
Ryan has performed in a broad range of technology support roles for electric-generation utilities, including nuclear power plants, and for the telecommunications industry. He has worked in web development for the restaurant industry and the Federal government.