PHP: Configuring Apache and PHP for Multiple Ports
Often when working with the web, you need to work with more than one site at the same time. The combination of PHP and Apache can be configured to run a different web site on different server ports. The steps to do this are outlined below.
Below are the changes that need to be made to httpd.conf to setup two virtual hosts. One on port 80 and one on port 81.
# Lines that follow setup two virtual hosts on this machine # The following lines tell the Apache Server to listen on more than one port Listen 80 Listen 81 # The VirtualHost statements setup two document roots on different ports <VirtualHost 127.0.0.1:80> ServerAdmin email@example.com DocumentRoot "c:/dir1" ServerName www.host1.com </VirtualHost> <VirtualHost 127.0.0.1:81> ServerAdmin firstname.lastname@example.org DocumentRoot "c:/dir" ServerName www.host2.com </VirtualHost> # The Directory statements setup the permissions and behaviors <Directory "c:/dir1"> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> <Directory "c:/dir2"> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory>
The Listen statements are needed to tell Apache to accept requests on those ports. The VirtualHost statement defines the location of the document root, links the host to one of the ports being listened to, and defines a host name for that port. The directory statements setup up the permissions and behaviors for the directory.
Content last updated Oct 2012