Pages

Banner 468

Sunday 27 March 2011

Server-Side Languages 1

0 comments
 
To date, most of my blogs have dealt with topics related to the client-side aspect of web development.  We looked at some basic HTML, how to style our pages using cascading style sheets (CSS) and how to add dynamic content using javascript.  It's now time to divert our attention to the server-side, specifically server-side scripting using PHP.

Server-Side?

Before tackling server-side scripting let's take a step back and have a high level look at how the web works.  Whenever you navigate to a new web page, your browser is effectively sending an HTTP request to a web-server over port 80.  The server then responds by sending the requested web-page or an error message (if the page was not found for instance) which the browser then displays.  This is known as the client-server model where the client is your browser and the web server is, you guessed it, the server.  Server-side scripting is a technique where the server executes some code (scripts) while processing a request to generate dynamic content  which is then sent back to the browser.

There are many server-side languages such as ASP, PERL and PHP and others.  The choice on which to use largely depends on your what you're trying to achieve and what would be best suited to your current environment.  There are other aspects to consider such as platform in/dependence, interoperability with other systems (e.g. databases) and security.  Having said that, any detailed comparisons between technologies goes beyond the scope of this blog which will instead focus on PHP.  

At this stage I would like to emphasize that I have just started learning PHP (my professional background lies in ASP and ASP.Net) and that the purpose of my next couple of posts is to share this learning experience.  This first post will mainly focus on how I went about setting up my development environment.

Setting-Up

First thing I did was to visit www.apachefriends.org to download the XAMPP installer.  XAMPP is a distribution of the popular Apache web-server that also includes MySQL, PHP and Perl.  This will spare me the headache of manually configuring Apache with MySql and PHP.

Given that I wanted to simulate the client-server model on my machine I installed XAMPP on a virtual machine which will act as my web-server.  This is where I hit my first hiccup.  The virtual machine I'm using as a web server is running MS Windows Server 2008 with User Account Control (UAC) turned on for security.  The XAMPP installer promptly suggests that, given the security constraints imposed by UAC, I should either disable UAC or install XAMPP to a location other than the "Program Files" folder.  Naturally I opted for the latter as I was not particularly inclined to disable UAC so I installed XAMPP to "C:\XAMPP" on my virtual disk.

First Contact

Once the installation was complete, I went ahead and started the XAMPP control panel and I immediately ran into another problem.  The control panel reported that it should only be run from the XAMPP root directory (Status Check Failure [3] error), which in my case is "c:\XAMPP\" which is exactly where it was being executed from!  I cleared the error message and attempted to start the Apache service from the contol panel with no success.  I noticed that the control panel was attempting to start Apache on port 80 and it suddenly dawned on me that I had to change the port number since I had IIS (this is a windows server after all) listening on port 80.  To change the port number bound to Apache:

  • Open c:\xampp\apache\conf\httpd.conf file.
  • Find and change the "Listen 80" entry to "Listen 8080" (8080 is the port I chose) 

I once again attempted to start apache but it still would not work.  At this point I referred to the Apache Friends forum to see if the problem was related to the "Status Check Failure [3]" error  I was getting when starting the XAMPP control panel.  Strangely enough, the solution I found was to uninstall XAMPP, and "re-install" it by downloading and extracting the "ZIP archive" version to the same root directory as before (c:\xampp).  Once again I changed the port number and started the XAMPP control panel.  This time no error was reported and Apache started successfully.

Testing the installation

Following that strange solution I wanted to make sure that everything was running as expected.  I started the browser and navigated to "http://localhost:8080" which thankfully displayed the XAMPP default page.

Next I verified that all the necessary components (MySql, PHP, SSL, SSI and FTP) were working correctly by browsing to the XAMPP Status page:

XAMPP Status page showing component status
I also accessed the XAMPP Security report and realised that by default, everything is unsecured, something I will definitely tackle sometime soon.  Further checks included having a look at the PHPInfo report and making sure that the sample guest-book worked correctly, which it did.

Summing Up

All in all this was quite a different experience for me.  I have never used, let alone configured Apache before since my professional experience lies in MS Internet Information Services (formerly Internet Information Server) and ASP/ASP.Net.  Besides that strange "root directory" error and its equally strange solution, installing and configuring Apache with MySql and PHP proved to be very easy using XAMPP and I'm considering setting up another virtual web server, this time using Linux to compare the installation process and results.  I'm especially curious what the default security settings would be on Linux.

In my next post, I will be customising the XAMPP default web page and attempt to access the web server from my host machine.


Leave a Reply