Monday, November 17, 2008

XAMPP on Linux

Linux has the best tools for LAMP (Linux, Apache, MySQL, PHP) servers, what you need to do is to get your hands "dirty" to set up these different beautiful tools to work as one. However, if you are just a developer and is used with "bundled" LAMP server where everything is set-up automatically, you would find getting your hands "dirty" is not your choice especially if there are many projects waiting to be done. Perhaps one of the famous "bundled" LAMP is XAMPP from Apache friends. In Windows, XAMPP is easily installed, just a matter of clicking the mouse as many times until the set-up is done. Starting the lamp server is quite easy and everything from that point will run smoothly (at least for the servers). The question is, can we have this done in a Linux system? The answer is YES! And perhaps many web developers just didn't realized that the comfort they experienced in Windows could also be experienced in Linux. Easy for me to say? Well, it is easy for you to do. In fact, this blog is about on dealing XAMPP for Linux. Here we go.

First things first, download the latest version of XAMPP for Linux here. For installation instructions you can read it here. Or you can simply follow the steps below, which is a slightly different version from the one found in the site:

1. Go to the directory where you downloaded the installer. For example, if it is downloaded in your Desktop the location would be /home/yourLinuxLoginName/Desktop. So, what you have to do is to start a terminal and issue a cd command to the path of the installer (i.e., cd /home/yourLinuxLoginName/Desktop).

2. Issue the command

sudo tar xvfz xampp-linux-1.6.8a.tar.gz -C /opt

The effect of this command is it will extract all the contents of the tar file to the directory /opt directory. The sudo will make the command a super user command. This is necessary because the user that has a write access to the opt directory is only the super user. In Ubuntu, the first account created during the installation is automatically added in the sudoers file. But this is not the case with Fedora, to add a user in the sudoers file follow this link.

3. Starting XAMPP is quite easy, you just have to issue the command:

sudo /opt/lampp/lampp start

Stopping is quite easy as well, just replace the start with stop.

4. Now that you have everything set-up what's next? You can now start accessing the XAMPP page by opening a browser and typing the address localhost in the address bar. If everything worked out correctly, you would see similar screen below:



5. The default XAMPP web site files are found in /opt/lampp/htdocs/xampp. You need to modify this directory so you can start working on your web sites. Some of you might want to delete the xampp web site and replace it with your own. But this tutorial will preserve that directory.
In order to have full access to the directory, issue the command:

For GNOME:
sudo nautilus /opt/lampp/htdocs/xampp

For KDE:
sudo konqueror /opt/lampp/htdocs/xampp

For XFCE:
sudo thunar /opt/lampp/htdocs/xampp

This command will open the directory in GUI mode. (Remember that only super user has all access to the /opt directory, hence we included sudo in our command.) Initially you'll see this kind of information window:



Since we need to preserve the XAMPP web site files we need to create a container for these files -- we have to create a directory and we can call it xampp-install. So, right-click the opened directory and click Create Directory and type the name xampp-install.



Transfer all the files into xampp-install directory, after doing that what will be left is only the directory we created.



This will also change the display of your browser, if it is already opened click reload or refresh and you'll see a similar window below:



Clicking on the link will let you browse again the previous website contents only with minor difference. But don't worry everything else is alright.

To add a website of your own, create a directory for that site. Say, we want to create a folder named myfirstweb. And then, put all your web site files in this directory. If you are going to refresh the browser you would see:




The directory we created appears as a link in the site. To view the site click on the link. In my example I created a simple page to display "Hello World".



Fin.

No comments: