Hot on HuffPost Tech:

See More Stories
Free Switched iPhone app - try it now!
AOL Tech

Flipping the Linux switch: Linux web tools, Pt. 2 - Using LAMP for testing

small apache2 install graphicThere was a toss up this week about whether it would be better to dig right in to the Linux HTML editors, or to wax poetic about setting up LAMP so that those choosing to go the content management system (CMS) route could test any changes they made with such editors on their local machines.

We ultimately decided to tackle setting up a LAMP testing ground. This will certainly not be necessary for every single person out there who just wants to put up a web site. If your site is not using PHP-driven content that interacts with or requires a database backend, and you just plan on designing static web pages, there is absolutely no need to do any of this.

If you are perfectly content to upload your site and integrate any supporting elements (once again, things like databases) live and on the web and make changes there, where it is possible that everyone can see your style sheet testing or things may be temporarily broken, you don't need to do this either.

Some people, though, really like to get things on their CMS tweaked to near perfection before releasing their content on the world. Other people need to know exactly what a dynamic site is going to look and act like before it goes live. The combination of Linux, Apache, MySQL and PHP (LAMP) makes this possible.
Installing LAMP is pretty easy, and when you consider what it actually does (it is a web server, after all) and how versatile and powerful it is, it's really sort of impressive how quick the whole process is. The first part of this post is the actual LAMP install (this particular install was done on an Ubuntu Hardy Heron machine, but it is essentially the same process on other distributions. We will point out any areas that might be slightly different on other distros). The second part of this post will cover, very briefly, any additional steps and tools that might be necessary to set up your test CMS.

Installing LAMP

Synaptic Apache2

The first step is to install Apache 2. Simply fire up your package manager (Synaptic, Adept, YaST, etc.) and do a search for -- you guessed it -- the Apache 2 package. You'll notice above there are a few choices in Ubuntu. The first optuion is fine, and any necessary dependencies will be bundled in. If you are using another distribution with multiple Apache packages, usually your best bet will be to go with one that is described as a meta package.

Synaptic install Apache2 stuff php5

Next we install PHP. In our case, we could simply scroll down after selecting our Apache 2 package in Synaptic, and choose the libapache2-mod-php5 package. Through the wonder and glory of package management in Linux, this let us know it was going to install all our dependencies for us and make sure that PHP would play nicely with Apache.

Install mysql

Onward to installing MySQL. Once again, the meta package rule applies here. In Ubuntu, mysql-server and mysql-server-5.0 are the same version, same core package. The first (mysql-server) is the meta package, and is the better choice in this case. It's more of a one-size-fits-all solution, but at this point, we're going pretend all testing LAMP servers have the same height, weight, and body shape.

Apache2 mysql connection mod auth install

We're almost there. Now we just have to add a package called libapache2-mod-auth-mysql. Remember that libapache2 module for PHP we added earlier? This is pretty much the same thing, except for MySQL. Because we chose the meta package, we got a more inclusive install of MySQL, but it doesn't necessarily make the link between Apache and MySQL. So we select this package and force the issue.

Then we hit the "Apply" button, and away we go.

Apache 2 apply changes, plz

You'll most likely notice that your distribution, upon installing, will prompt you to give your root MySQL user a password. Do it, and make sure it is different than your root user password. It's a good habit to maintain, and your testing CMS might take offense if there's not a password to your MySQL account.

MySQL password is... HA! Got cha!

If your distribution or mysql doesn't give you this sort of nudge, you are so not off the hook. You'll need to type, in a terminal:


When the mysql> prompt shows its bad self, you'll then enter:

SET PASSWORD FOR 'root'@'localhost'=PASSWORD('enteryourpassword');

Fear not, we will also show a little friendlier way of manipulating MySQL databases in a bit. At this point, though, we can safely consider our LAMP installation complete.

Finally, though, we get to kick the tires on our new testing LAMP server. By default, your server is not able to be seen by the outside world. You are not publicly serving web pages from your home computer. Trust us, you want it this way. Many distros will start an installed version of Apache or MySQL on boot. You can disable this in your system settings, should you just feel better that way.

You can also start, restart, or stop these services with the command line. For now, let's see if Apache is running.

Apache start. Ooops

Once we figured out our sudo password, it became readily apparent that, yes, Apache was running. (We could have also typed status instead of start). The other two messages the terminal returns, about the qualified domain name and httpd already running are fine. Apache essentially gave us a default name (same as localhost) and is letting us know its been started, so why the freak are we asking it to start again?

Stopping Apache

We can stop Apache the same way. You've probably gathered it is necessary to have root/superuser privileges to do this with Apache. We also want to point out that this start/stop command is one of those tricksies that can vary from distro to distro. Some distributions use the /etc/init.d/apache2 command. Some distributions (such as Red Hat and Mandriva) use /sbin/service httpd start|stop commands instead.

If you should want to start and stop MySQL, as well, the commands are similar, with mysql replacing apache2 (or mysqld replacing httpd) in the above command.

For now, let's just double check Apache 2 is functional. We open our browser, and type in http://locahost and discover:

Apache works!

So there we are. Apache is installed, working, and now we've got this index.html file somewhere on our computer that has the truly profound text "It works!" in it. Where is that file?

Yeah, well, this is the other bit that varies from distribution to distribution. In Ubuntu, you'll find your Apache server document root in the var directory (a favorite of pirates everywhere. VAAAAR!) in the subdirectory www. Other distributions (such as Fedora) will have the public (but, again, public only to people using your computer) directory under /var/www/html. OpenSUSE has it creatively under /srv/www/htdocs.

There is a nice run down of where you can find all sorts of Apache locations and commands for various distributions on the Apache wiki.

Testing the CMS

This is the fun part (really)! It can vary a bit from CMS to CMS, but your sturdy LAMP setup should support them all now. We opted to use WordPress for our sample, but seriously, use what you want. Follow the instructions on the CMS's site, and you should be golden.

The one thing you might want to do (this was necessary with WordPress) is install an easy access interface to MySQL. You won't need it often, most likely, in the testing scenario, but it does make things a lot easier than messing with MySQL on the command line.

Fire up your package management program again, and install phpMyAdmin.

phpmyadmin installing

Once it installs (and it may ask you what server to associate your install with -- in our case it was Apache 2), go to your friendly browser and go to http://localhost/phpmyadmin

phpmyadmin login screen

Your user name is root, and your password will be whatever you chose for the root password on MySQL set up. (You did that, and remembered it, right?)

Once inside the belly of your MySQL install, you can create a database for your CMS to use (if it does not create one itself) by typing a database name in the Create New Database cell.

phpmyadmin inside create database

Leaving everything else the way it is is fine. We should then get confirmation that our database "eviltwin" has been created.
Database created!

MySQL will ask about tables and fields. Don't worry about those, unless you're wickedly into database design, in which case you don't need us to tell you about phpMyAdmin. Your CMS will most likely do the rest automatically, or give you good instructions on importing the file you need in phpMyAdmin.

Now is when it all pays off. Unzip your CMS, and copy it into your Apache 2 document root folder. In our case, on Ubuntu, it was /var/www and we needed to copy it as root (you may want to change permissions as necessary on that folder so you're not doing things as root when you don't mean to all over the filesystem).

Then, we simply followed our CMS provider's instructions for install. We entered our database information, and then came the moment of truth:
Wordpress install works!

Here we see that going to http://localhost/wordpress/wp-admin/install.php is successfully returning the php code and the database connection. (Note that the extra "wordpress" directory was due to the way we copied our files into the /var/www directory.)

Let's make this Kubrik theme purty next week!

So here we are, presented with a pretty plain jane sort of default CMS install. Next, we'll fire up some editors to make this install much more visually interesting!

Tags: apache, content management system, ContentManagementSystem, howtos, LAMP, linux, linux-switch, localhost, mysql, opensource, php, server, test