|
Apache Installation on Windows/IIS is fairly simple using Windows Installer service for .MSI Apache package installation wizard file.
Discussion here, atleast applies to '4.5+ MB apache_2.0.53-win32-x86-no_ssl.msi' Apache HTTP Web Server package for Windows.
You may use older/newer software than Apache/2.0.53 (Win32) PHP/4.3.4; please check Apache HTTP server project page under httpd.apache.org for latest information.
You just need to run .MSI file; this usually installs Apache files in \Program Files\Apache Group\Apache2\ and automatically creates Apache Service Monitor icon in right-side of your Windows start-menu taskbar.
Before attempting Apache installation, stop the IIS Admin Service; this is important. If Apache 2.x.yz installs successfully, it will create Apache2 service with description Apache/2.0.53 (Win32) PHP/4.3.4.
Note that path for Apache executable Apache.exe will be \Program Files\Apache Group\Apache2\bin\Apache.exe.
After installation, it may be good, you change Startup Type of Apache2 service and WWW Publishing Service ( which is dependent on IIS Admin Service ) to Manual
to prevent unexpected/possible failure of Apache2 service or WWW Publishing Service ( IIS Admin Service ) as both these services will run on port 80, by default.
Indeed, this is not exactly neccessary, as later you see, you may change Apache2 ( HTTP ) service to use another port, say, port 8080. Or you may change WWW Publishing Service port 80 to some other port, say 8090 ( use MMC Console, to do this ).
And then, Apache will use port 80.
If suppose Apache2 service fails to start, or fails to install as a Windows service; you may then either need a re-installation of Apache2 or you may do this:
navigate to \bin of Apache at command-prompt ( run \winnt\system32\command.com ) and try:
Apache -k install
Apache -k start or
Apache -k uninstall
Apache -k install Apache -k start
Refresh and see ( if it worked! ) Services MMC Console. Enough with Apache installation; let's come to httpd.conf settings. This is a main ( magic! ) configuration file for Apache HTTP Web Server.
You can easily open/edit/save this file using Windows Notepad. Apache needs restart, for new settings of httpd.conf file to work.
Typical settings for localhost are shown here:
ServerRoot "C:/Program Files/Apache Group/Apache2"
Listen 8080 LoadModule alias_module modules/mod_alias.so LoadModule cgi_module modules/mod_cgi.so LoadModule isapi_module modules/mod_isapi.so LoadModule rewrite_module modules/mod_rewrite.so LoadModule php4_module C:/php/sapi/php4apache2.dll ServerAdmin postmaster@localhost ServerName localhost:8080 DocumentRoot "C:/Inetpub/wwwroot" <Directory "C:/Inetpub/wwwroot"> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> DirectoryIndex index.htm index.html index.php index.html.var AccessFileName .htaccess ErrorLog logs/error.log CustomLog logs/access.log common ScriptAlias /cgi-bin "C:/Inetpub/wwwroot/cgi-bin" <Directory "C:/Inetpub/wwwroot/cgi-bin"> AllowOverride None Options Indexes Order allow,deny Allow from all </Directory> AddType application/x-httpd-php .php AddHandler cgi-script .cgi .pl AddType text/html .shtml AddOutputFilter INCLUDES .shtml ErrorDocument 404 /404.shtml ErrorDocument 500 /500.shtml Alias /error/include "C:/Inetpub/wwwroot"
Note that drive letters should be correct; For example— you may put Program Files and Apache, PHP, Perl on E:, Windows/IIS on D:, Windows 98 on C:.
It doesn't matter, but it matters to provide correct paths. ServerRoot is the loacation of Apache HTTP Web Server; you need not change.
If you use Listen 8080 lieu Listen 80 ( as here ), HTTP requests will then be http://localhost:8080/.
( When I got familiar with Apache, I gave IIS for it!, and changed IIS to port 8090, Apache runs on port 80, and Tomcat on 8080. )
Accordingly, you need set ServerName directive also ( as I did here ), if you need/want.
You can use directives Listen 80 and ServerName localhost:80,
but ensure that only one service is running, at port 80, out of, Apache2 Service and WWW Publishing Service.
If you are in LAN ( each system has an IP ), you may use Listen IP:Port and ServerName IP:Port.
Next, you may need to uncomment one or more LoadModule lines, as per, your requirement.
If you want to experiment with Apache Module mod_rewrite, uncomment ( remove # ) before it.
Last line ( here ), under LoadModule is for loading PHP 4.3.4 SAPI ( Server Application Programming Interface ) for Apache Web Server.
You should write exacly php4_module and php4apache2.dll.
So, Apache 2.0 and PHP 4.3.y can serve PHP/MySQL Web sites. If you need further information about Apache/PHP, see their Web sites online.
In short you need, PHP Version 4.3.2 or newer or which has Apache2 module, to work it, with Apache daemon.
Indeed, http://localhost:8080/manual/en/ is a very elaborate Apache manual. If you have PHP documentation downloaded, you may also see it.
Note that ( you are using PHP 4 ), path for php4_module is correct e.g.,
it may be LoadModule php4_module C:/php4/php/php4apache2.dll; this depends on, where you installed PHP.
Please note that Apache needs php.ini and php4ts.dll.
Since php.ini is Windows OS file, put it under /Windows or /Winnt directory.
php4ts.dll should be in /bin of Apache installation ( copy it there ).
Note that, Windows 2003 ( SE or Web or Enterprise ) has no browscap.ini file, so if you're loading PHP module in Apache installed on Windows 2003,
disable [browscap] directive in php.ini ( just put ; or # before that directive ).
It is good to see, Apache Module mod_cgi takes care of your CGI/Perl scripts; but you need Perl ( PerlScript ) environment on your machine.
Install Perl to C:/perl/ if you want CGI/Perl on localhost.
Call a PHP script <?php echo phpinfo(); ?> in your browser to see a list of Apache Loaded Modules and Apache Environment variables.
You'll see:
GATEWAY_INTERFACE CGI/1.1
SERVER_PROTOCOL HTTP/1.1
E-mail of Web site administrator ( Web master ) is set postmaster@localhost, for your local machine. For Web, it is set as for e.g., webmaster@ejaadu.com.
We changed DocumentRoot "C:/Inetpub/wwwroot/" lieu DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs".
This specfies root directory for your Web site. Do you want to duplicate or cut/paste your Web sites/directories of /wwwroot to /htdocs ? No!
<Directory "~"></Directory> specifies settings for directories, in your Web site. Since you've a /wwwroot directory ( lieu /htdocs ), you need specify settings for it.
We changed AllowOverride None to AllowOverride All for /wwwroot directory. It should be clear that /wwwroot is the root directory ( / ) for your Web site.
This is, /wwwroot or /htdocs is same as /public_html or /www placed in ( /usr ) your remote Web server ( shared hosting ).
You may use AllowOverride Options FileInfo Limit or AllowOverride Options FileInfo lieu AllowOverride All. Do you need to experiment with .htaccess files ?
Please, note that, we also changed other configuration in httpd.conf as shown above.
You can see Apache log files from C:/Program Files/Apache Group/Apache2/logs/.
Error documents will be called from /wwwroot ( e.g., we specified 401 Not Authorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error ).
Finally, your cgi-bin directory ( for CGI/Perl scripts ) is /wwwroot/cgi-bin/. For this directory, AllowOverride None is set, so you can't place .htaccess file in /wwwroot/cgi-bin/.
For CGI/Perl scripts, Perl interpreter should be located at C:/perl/bin/perl.exe ( as we declared in htttpd.conf, above ).
So, first line of each .pl or .cgi file is #!C:/perl/bin/Perl.exe; otherwise, it'll return 500 Ineternal Server Error.
If you've other path for CGI/Perl specify it correctly in your CGI/Perl scripts. For your remote-server path to Perl is usually #!/usr/bin/perl
In case, you want to allow CGI/Perl scripts to all directories in /wwwroot you may add ExecCGI to Options for /wwwroot, as here:
<Directory "C:/inetpub/wwwroot">
Options Indexes FollowSymLinks ExecCGI </Directory>
Example .cgi or .pl script, you may want to test:
#!C:/perl/bin/Perl.exe
print "Content-type: text/plain; charset=iso-8859-1\n\n"; print "Hello World!";
Note that CGI stands for Common Gateway Interface for server-side scripts.
CGI is not a language in itself; you can rename .pl files as .cgi and vice-versa ( see AddHandler for httpd.conf, we just wrote ).
This tutorial is not about Perl or CGI; just note that, CGI is an interface as another SAPI is, e.g., you can run PHP as CGI or ISAPI ( Internet SAPI ) for IIS ( PHP ISAPI is recommended ).
And you use Perl as a powerful server-side CGI script. Perl ( PerlScript ) has credits for text-processing ( using regular expresions ). Apache and PHP also use PCRE library.
I hope you've successfully installed Apache, PHP, CGI/Perl environment on your localhost. An example code is given below:
VirtualHost directive
This is a really magic directive! It enables you to run ( test ) a virtual Web site locally.
You can run a Web site as http://IP:port/ or http://www.full-domain-name-or-subdomain-name/.
NameVirtualHost 127.0.0.1:80
Listen 80 <VirtualHost 127.0.0.1:80> ServerAdmin webmaster@mediasworks.org DocumentRoot C:/Inetpub/wwwroot ServerName www.mediasworks.org ServerAlias mediasworks.org www.mediasworks.org </VirtualHost> <VirtualHost 127.0.0.1:80> ServerAdmin webmaster@mediasworks.org DocumentRoot C:/Inetpub/wwwroot/funds ServerName funds.mediasworks.org ServerAlias funds.mediasworks.org www.funds.mediasworks.org </VirtualHost> <VirtualHost 127.0.0.1:80> ServerAdmin webmaster@anshul.com DocumentRoot C:/Inetpub/wwwroot/anshul ServerName www.anshul.com ServerAlias anshul.com www.anshul.com </VirtualHost>
You also need change hosts file; D:\WINDOWS\system32\drivers\etc\hosts or D:\WINNT\system32\drivers\etc\hosts.
Alike, httpd.conf file, this file also has no extension and can be easily edited using Windows Notepad.
Corressponding to above VirtualHost entries, we need put few lines in hosts file:
127.0.0.1 localhost
127.0.0.1 www.mediasworks.org 127.0.0.1 mediasworks.org 127.0.0.1 www.funds.mediasworks.org 127.0.0.1 funds.mediasworks.org 127.0.0.1 www.anshul.com 127.0.0.1 anshul.com
Unlike the case of httpd.conf, you need not restart Apache, when you make changes in hosts file.
However, when you connect to Internet, either rename this file or delete this file or remove entries in this file.
Otherwise your browser will pull pages from your HDD lieu Internet!
As said before, you can use IP:port also in VirtualHost, you need no update in hosts file for IP:port to work ( But, restart Apache, as you did changes to httpd.conf ):
NameVirtualHost 127.0.0.1:555
Listen 555 <VirtualHost 127.0.0.1:555> ServerAdmin webmaster@mediasworks.org DocumentRoot C:/Inetpub/wwwroot ServerName www.mediasworks.org ServerAlias mediasworks.org www.mediasworks.org </VirtualHost> NameVirtualHost 127.0.0.1:999 Listen 999 <VirtualHost 127.0.0.1:999> ServerAdmin webmaster@mediasworks.org DocumentRoot C:/Inetpub/wwwroot/funds ServerName funds.mediasworks.org ServerAlias funds.mediasworks.org www.funds.mediasworks.org </VirtualHost> Discussion for this tutorial
So, you see Apache is a grand HTTP Web server ( Apache HTTPd ) ( it is and it will be! ). You should read Apache manual ( http://localhost:8080/manual/en/ ). You may subscribe to Apache mailing-lists.
See the Perl Web sites: pcre.org, perldoc.com, perlscript.com for information about Perl and regular expressions.
One problem in experimenting Perl on Windows is, remember, you need change Perl path, when you upload it.
Other thing may be said in this discussion, is that, if you skip drive letter like C: or D: or E: while making changes in directives of httpd.conf, php.ini ( and PHP scripts ),
i.e., you use /, then / points to drive letter of Windows OS installation drive. I said this, just to say, Linux has now paths specified in drive letters.
I also say here, httpd.conf is a ( magic! ) file, which behaves Apache. This file has <VirtualHost "~"></VirtualHost> definitions,
which enables hundreds of Web sites ( shared hosting ) run from same Apache/Linux server. We also configured few bits of this file to make Apache work for our local machine.
Actually, there is a lot you can do with httpd.conf file and .htaccess files ( and of course Apache modules ); and it takes good learning-curve to use these for a real Web server.
What I am trying to say is, if you can fetch few samples of these files, you may read/interpret it ( and test something of it, localhost! ).
You will get actual experience, when you configure Apache daemon on real live WWW server!
Lastly, I might state, Apache people ( ASF i.e., Apache Software Foundation ) has another blessing 'Jakarta Project' ( jakarta-tomcat, Java application server ) for the Web.
So, apart PHP scripts, Apache can also power JSP ( Java Server Pages ). These are free ( give-away! ) projects ( httpd.apache.org and jakarta.apache.org ).
Happy Apache journey, I say.
Errata for this tutorial
None
User comments/feedback for this tutorial
None
This tutorial ends here.
|