Filed under: Developer, Internet, Features, Linux, Open Source, How-Tos
Flipping the Linux switch: Linux web tools, Pt. 2 - Using LAMP for testing
There 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




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


mysql
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.


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:

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.


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.


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:

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.)

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!



Reader Comments (Page 1 of 1)
Mouse said 11:35AM on 6-13-2008
What permissions do I need to give to the directory for it to play nice in Ubuntu with just a regular user?
Reply
Kristin Shoemaker said 12:27PM on 6-13-2008
Hi Mouse,
I'm figuring that it would work just fine to take the directory /var/www and, as a super user, change the ownership to the regular user. It would be preferable to the alternative of chmod'ing your directory to a more open read/write/execute setting (777),
dan said 12:46PM on 6-13-2008
wow.
Instead of installing the lamp components individually, how about just going to a terminal window and typing:
"sudo apt-get install lamp-server^"
This will install all of the components you need in one shot.
dan
Reply
Kristin Shoemaker said 12:54PM on 6-13-2008
Interesting... Actually, I'd never done it that way (nor heard of it being done in that manner) and didn't even think to look for a complete LAMP package. Certainly would save a bit of time and effort with Ubuntu. Thanks!
Not so sure every distribution has full LAMP packaging such as this, however, and in that event it is useful to know what packages and modules are required for a working install.
Thanks again!
dantrevino said 10:50AM on 6-16-2008
Kristin,
this does apply only to Ubuntu. The server team has tried to make things easier, especially where there is a lot of common need.
Ubuntu Server - LAMP for human beings.
dan
Gan-San said 1:40PM on 6-13-2008
http://www.webmin.com - Great tool for managing LAMP servers.
Reply
AKX said 3:19PM on 6-13-2008
I'm not exactly sure why you would be installing the libapache2-mod-auth-mysql package unless you are going to do "pure" HTTP authentication against MySQL, either...
Reply
Kristin Shoemaker said 3:32PM on 6-13-2008
I am not 100% sure it's necessary for every instance one would use LAMP... but it was most definitely required for my database connection between WordPress and MySQL, and phpMyAdmin. I imagine it's probably required for a healthy number of applications in the CMS category that operate similarly. Since I figured a good many of people reading were thinking of setting up local environment to test a CMS of some variety, I'd be remiss to leave it out, even in the event someone had a CMS/database interaction that didn't require it.
Elaine said 10:18AM on 6-15-2008
Thanks for the very clear tutorial. I had been planning on doing this for a while for my Ubuntu box, so I could test some changes I wanted to make to a theme for my Wordpress blog, and your howto made it very painless.
Reply
svet said 1:52PM on 6-15-2008
Instead of of making separate installations of Apache, PHP and MySQL you could install taskel and choose LAMP server at the screen.
Reply