Getting Apache started on Vista when port 80 is blocked

May 26th, 2009

Running Microsofts Internet Information Services (IIS) and a SQL Server on the same development box as WAMP can sometimes cause port conflicts resulting in Apache not starting. Suppose - hypothetically speaking - you’ve recently decided to spend some time setting up IIS server and an MS SQL server on a Vista box (Windows Vista Home Premium in my case).  Then later you switch gears and after setting up IIS and MS SQL server you decide to do some Apache and PHP development only to find that Apache is blocked on port 80.

When the apache server fails to start the first thing to do is test port 80 to see what if anything is blocking port 80. You can test port 80 from within WAMP by left Clicking the WAMP icon in the task bar and select Apache->Service->Test Port 80

If you get a message like this:

Your port 80 is actually used by:
Server: Microsoft-IIS/7.0

Then Microsoft’s Internet Information Server (IIS) is the culprit.

To get right you’ll need to shutdown the IIS server. To shutdown IIS start by opening the windows control panel and select add remove programs.  You’ll notice a menu on the left of the add remove programs dialogue window with an option “Turn Windows features on or off.”  Click this link and wait a minute or two for the windows features dialogue window to open, be patient it may take awhile for the dialog to load.
Find “Internet Information Services” and disable the IIS server by unckecking corresponding selection box.

Click ok and wait several minutes while windows accepts the change. You may need to restart your computer although I found I did not have to.

If when you test port 80 using WAMP (possibly after following the instructions above) you see the following message:

Your port 80 is actually used by
Server: Microsoft-HTTPAPI/2.0

Then SQL Server Reporting Service is blocking apache and need to be stoped.
To shut down sql server click on the start button -> All Programs -> MS SQL server -> configuration tools -> SQL Server Configuration Manager.  Click on SQL Server Reporting Services (MSSQLSERVER) to highlight it and then click the stop button at the top of the dialog window.

A blog post I found helpful in figuring all this out can be found here: microsoft httpapi/2.0 disabling apache.

With that done you should be able to restart all services in WAMP and go to town.

XAMPP Virtual Hosts on a MAC

February 24th, 2009

I recently retooled a Zend development environment on a mac laptop running OS X. I had been using the free version of MAMP for awhile but found the free version too limited.  MAMP is useful for getting  Apache, PHP, and MySQL stack up and working together quickly on a mac.  One thing lacking in MAMP though is an actual http.conf file like you probably deal with on a production server.

XAMP is another free AMP stack which includes an editable httpd.conf file making configuring Apache to test SSL connections much more standardized if not straight forward.  Instead of dealing with a GUI one deals with the Apache configuration files directly.  While it’s nice to be able to customize XAMPs Apache installation getting the configuration right can take some time.  If your really uncomfortable meddling with Apache configuration files you should consider just purchasing a licensed version of MAMP which does most of the stuff through a graphical interface.  Of course once you go into production you’ll probably going to have to deal with Apache’s httpd.conf file anyway so you might as well front load the pain now and be better prepared when things actually do go into production.

So without further ado I now present the first post on the new acwolf blog: how to configure XAMP virtual hosts on a mac.

Step One, Download and configure XAMP

First download XAMP for mac.

Once you have XAMP running on you mac you’re ready to begin configuring virtual hosts.  Using Mac Finder go to Applications > xampp > etc and open the httpd.conf file. Near the bottom of the file look for the following lines:

# Virtual hosts
#Include /Applications/xampp/etc/extra/httpd-vhosts.conf

The pound symbol (#) denotes a comment.  Since we want to setup virtual hosts go ahead and uncomment the second line by removing the pound symbol like so

# Virtual hosts
Include /Applications/xampp/etc/extra/httpd-vhosts.conf

With the above line uncommented Apache will now look to the httpd-vhosts.conf file for instructions on how to configure virtual hosts.   Go to Applications > xampp > etc > extra and open httpd-vhosts.conf to begin configuring virtual hosts for XAMP.  An imported (and practically undocumented) fist step is to include localhost has the default named virtual host. Do this by adding the following to the httpd-vhosts.conf:

<VirtualHost *:80>
ServerName localhost
DocumentRoot “/Applications/xampp/htdocs”
<Directory “/Applications/xampp/htdocs”>
Options Indexes FollowSymLinks Includes execCGI
AllowOverride None
Order Allow,Deny
Allow From All
</Directory>
</VirtualHost>

With that in place you are now ready to add your other virtual hosts, in my case I’m developing a Zend application called zendapplication.  It’s located in a folder called myZendApps in the User > Documents folder.

<VirtualHost *:80>
ServerName zendapplication.dev
ServerAlias wwww.zendapplication.dev
DocumentRoot “/Users/aaronwolf/Documents/myZendApps/zendapplication/public”
<Directory “/Users/aaronwolf/Documents/myZendApps/zendapplication/public”>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog “logs/zendapplication-error_log”
CustomLog “logs/zendapplication-access_log” common
</VirtualHost>

For all the details and options involved with setting up a virtual host refer to the apache documentation.  The two critical configuration options here are ServerName and Document root.  ServerName denotes what domain this particular virtual hosts responds to.  DocumentRoot tells Apache where the files associated with this particular domain live.  Since Zend Framework applications (like Rails applications) only make the public directory accessible to the web I have the document root pointing to the public directory of my Zend application.

So far we,

  1. Created a localhost vertual host pointing to XAMPs default root folder (/Applications/xampp/htdocs).
  2. Created a virtual host for a zend application located in Users > aaronwolf >Documents > myZendApps > zendapplication >public.
  3. Assinded a server name (the local domain name) of our choosing to the new virtual host.

Note: I used the .dev extension for my server name.  It’s best not to use .com or .net domain names when configuring local applications, you’ll see why once you…

Configure the hosts file

The next step is to configure your host file.  A hosts file works like a DNS server associating domain names with IP address except domain names configured in your local hosts file only effect your local development machine.

In the example presented here we have configured Apache to respond to requests for zendapplication.dev now we want to be able to type zendapplication.dev in to a browser and play with our application.  Since zendapplication.dev only exists on our local development machine (not the internet) we’ll need to configure our local host file to send requests for the zendapplication.dev domain to our development computers IP address (127.0.0.1) to be handled by Apache server.  Sounds complicated but to get it done is very simple.

Fist you’ll need to open your hosts file.  On a mac you can find the hosts file in the /etc directory (you’ll need root permission to edit the file).

Open a concole window and type:

sudo nano /etc/hosts

Add the following line to the bottom of your hosts file (be sure to sperate the IP number and the domain name with a tab).

127.0.0.1        zendapplication.dev

Now when you type zendapplication.dev in to the address bar of you local browser you’ll should see…

You don’t have permission to access /xampp/index.php on this server.

Nice!  Turns out there’s one more bit of configuration to be done (at least if you’re storing you applications under the User > Documents directory on a mac like I am).  You’ll need to tell the Apache process to run with your user permissions (something that should never be done on a production machine).  Back to Application > xamp > etc, open httpd.conf and look for the following block:

<IfModule !mpm_netware_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User nobody
Group admin
</IfModule>

Notice by default Apache is set up to run as user “nobody” which lacks permissions to access files in your Documents directory.  To fix this simply change nobody to the username you uses when logging into your machine, so in my case…

User aaronwolf
Group admin

That should about do it.  Type zendapplication.dev into your browser and go to town.

If you notice your application’s indexpage redirects to /xampp/index.php you’ll just clear your browsers chache.

Hopfully that will save someone a few hours…

Welcome to Aaron Wolf’s new blog

February 14th, 2009

Hello,

Welcome to the Aaron Wolfs new website.  I just finished installing wordpress…looking forawrd to updating my new site soon.