You can get a LAMP (Linux, Apache, MySQL, PHP) server up and running in just 30 minutes. That’s right. It is very easy to do. This instructional post will show you how to get LAMP started, including how to enable the mod_rewrite Apache module so servers can make use of friendly URL directives in .htaccess files. This post will focus on starting LAMP on a Debian core Linux distribution (namely Ubuntu). Ready for some command-line?
Step 1: Update Your Software Repositories
Make sure all your software repository locations are up to date. To do this, execute the command below in a terminal window. Please take note that this command uses software called apt-get, which is the default program for installing software on Ubuntu. If you plan to use another operating system, such as SUSE Linux, the commands you’ll type into a terminal window will be different. You may even consider looking into a software installation program with a GUI, such as Yast, that will help you install the necessary software for your LAMP server.
$ sudo apt-get update
Once finished, you’ll be ready to install the latest version of Apache.
Step 2: Install Apache
Install Apache (version 2) with the command below. After the installation is complete, open a web browser and visit http://localhost/. You should see, in bold letters, the message “It Worked!”
$ sudo apt-get install apache2
Step 3: Install PHP
During the install of PHP, Apache will automatically restart. If you are still using PHP4, it is time to upgrade, dude.
$ sudo apt-install php5
Step 4: Install MySQL Server
Enter a root mysql user password when prompted (can be left blank for development servers). You can test your MySQL server install by typing $ mysql -u root -p into the terminal. It you reach the “mysql>” prompt, your MySQL server is runing.
$ sudo apt-install mysql-server
Step 5: Restart Apache
$ sudo /etc/init.d/apache2 restart
This Penguin is Flying!
OK, you should now have a working LAMP server, the foundation for PHP development. But there are still a few loose ends you’ll want to take care of, one of which is enabling the mod_rewrite Apache module. This module is the driving force behind friendly URLs (called permalinks in WordPress). To enable the use of .htaccess files follow these command-line instructions:
Login as the root user on the system.
$ sudo su root
Naviagate to /etc/apache2/mods-available directory on the server.
$ cd /etc/apache2/mods-available
Move the rewrite.load file from the mods-available directory to /etc/apache2/mods-enabled.
$ mv rewrite.load /etc/apache2/mods-enabled
Restart Apache.
$ sudo /etc/init.d/apache2 restart
Also, depending on your server configuration, you may need to change the owner of the default Apache web directory in order to create files for your web site. Instructions for that are:
Navigate to /var and change the owner of the “www” directory.
$ cd /var
$ sudo chown user -R www
Security
Now that you have a server up and running, and you have mod_rewrite enabled, you need to consider the security of your server before you put it into production. Pete Freitag has put together a great list of ways to keep your Apache server from getting compromised. Most of the changes he talks about involve editing the main Apache configuration file called http.conf. In Ubuntu, this file is usually located in the directory /etc/apache2. My advice is to, at the very least, make sure you turn off directory browsing in Apache by adding an “Options” directive inside a “Directory” tag in the http.conf configuration file. Set Options to either “None” or “-Indexes.”
2 replies on “Flick of the Switch: Turning on the LAMP in Just 30 Minutes”
The MySQL password should probably not be left blank even for development servers. In ubuntu, is the MySQL daemon able to be read from the internets, or is it firewalled and closed? If not, I can run mysql -u root -h [your development sevrer] and get full access. You can trust me. But not that Anonymous guy.
Nice brief intro!
The following:
$ sudo su root
$ cd /etc/apache2/mods-available
$ mv rewrite.load /etc/apache2/mods-enabled
can and should be replaced by:
$ sudo a2enmod rewrite
This is a) simpler and b) keeps rewrite.load where the package manager expects it, which helps during upgrades and security updates.