May 18

Apache post-install issue with mod_unique_id

If after installing Apache and starting the server the following message shows in the error logs and the apache server does not start:

hostname nor servname provided, or not known: mod_unique_id: unable to find IPv4 address of xxxxxx

then in httpd.conf disable the line

LoadModule unique_id_module libexec/apache2/mod_unique_id.so

Restart again. This is usually the fix if changing hosts and httpd.conf ServerName entries etc. do not fix the problem.

Dec 23

Getting Apache installed

Installing Apache2.2

Make sure you update ports and then run the following commands:

# cd /usr/ports/www/apache22
# make install clean
That will install apache2.2
Configuring apache2
Lets edit the httpd.conf file:

# vi /usr/local/etc/apache22/httpd.conf
Scroll down and change the following settings. The optional settings I will put OPTIONAL before the setting:

OPTIONAL: Listen 80 – You can change this default option if you have more than one apache server running on your network

User www – Changes what user apache runs as

Group www – Changes what group apache runs as

ServerAdmin you@example.com- change you@example.comto your email address.

DocumentRoot “/usr/local/www/apache22/data” – I don’t usually use the default path. I put my www documents on a seperate drive.

Directory “/usr/local/www/apache22/data” – Change this to the same path as DocumentRoot (See above)

<Directory /usr/local/www/apache22/> Change this to the root of your vhosts folder

DirectoryIndex index.html index.html.var – add any pages you would use. For instance, add index.php if you use php pages

OPTIONAL: #CustomLog /var/log/httpd-access.log combined – I usually leave this commented unless you want to use this to track users looking at your site

ScriptAlias /cgi-bin/ “/usr/local/www/cgi-bin/” – change this to your cgi-bin path

Directory “/usr/local/www/cgi-bin”> – change this to the same path as ScriptAlias /cgi-bin above

Now lets tell apache to start:

# apachectl start
and hit Enter on your keyboard
We now need to tell Apache to run on startup. Please run the following command:

# echo ‘apache22_enable=”YES”‘ >> /etc/rc.conf
If you get no errors, apache should be running. Look at the page by opening a browser to http://localhost or replace localhost with the IP or the actual hostname of the box. If you went with the DocumentRoot defaults, You will see an apache test page until you get your site up and going. If you are behind a router or firewall, make sure you forward the apache port (Port 80) to the FreeBSD box otherwise you won’t be able to get there from here. :-)

Configuring SSL

Let’s get SSL Configured and Installed:

(FROM http://www.bsdguides.org/guides/freebsd/webserver/apache_ssl_php_mysql.php)

# mkdir /usr/local/etc/apache22/ssl.key
# mkdir /usr/local/etc/apache22/ssl.crt
# chmod 0700 /usr/local/etc/apache22/ssl.key
# chmod 0700 /usr/local/etc/apache22/ssl.crt
Create Certificate
Now, you need to understand that one server can hold multiple certificates, but only one per listening IP address. So, if your server is listening on one IP address, you can only have one certificate for the server. Follow me so far? All of your virtual domains can share the same certificate, but clients will get warning prompts when they connect to a secure site where the certificate does not match the domain name. If your server is listening on multiple IP addresses, your virtual hosts have to be IP-based — not name-based. This is something to consider when creating your certificate. :-)

Change to your root dir by typing in the following command. We want to save this configuration there as a backup.

# cd /root
# openssl genrsa -des3 -out server.key 1024
You will now be prompted to enter in a password. Write this down as you will need it later. We need to make a Certificate Signing Request (CSR):

# openssl req -new -key server.key -out server.csr
Enter your password when it asks for it. Make sure you enter your FQDN for the “Common Name” portion.
Self-signing your Certificate
You could always pay money to Verisign or Thawte for this but it costs $$$. Here is the way to do it:

# openssl x509 -req -days 365 -in /root/server.csr -signkey /root/server.key -out /root/server.crt
Now your cert is good for 365 days. If you want to make it longer, go right ahead and do so :-)
If you would like more information about SSL Certs, go to http://httpd.apache.org/docs-2.0/ssl/ssl_faq.html#aboutcerts

Now we need to copy the certs to the right place:

# cp /root/server.key /usr/local/etc/apache22/ssl.key/
# cp /root/server.crt /usr/local/etc/apache22/ssl.crt/
Now to give them the right permissions as well:

# chmod 0400 /usr/local/etc/apache22/ssl.key/server.key
# chmod 0400 /usr/local/etc/apache22/ssl.crt/server.crt
We will now want to copy the default httpd-ssl.conf from the extras folder to the Includes folder:

# cd /usr/local/etc/apache22/extra
# vi httpd-ssl.conf
Now modify the following:

DocumentRoot “/usr/local/www/data” – Change the path to your httpd.conf document root.

ServerName www.example.com:443 – Change www.example.com to your domain name.

ServerAdmin you@example.com  Change this to your email address

ErrorLog /var/log/httpd-error.log – You can leave this or comment it out.

TransferLog /var/log/httpd-access.log – You can leave this or comment it out.

SSLCertificateFile “/usr/local/etc/apache22/ssl.crt/server.crt”

SSLCertificateKeyFile “/usr/local/etc/apache22/ssl.key/server.key”

One additional thing you will need to do is open up  /usr/local/etc/apache22/httpd.conf and comment out the following line:
Include etc/apache22/extra/httpd-ssl.conf
Now run the following:

# apachectl stop
# apachectl start
The start means it will start in ssl mode to serve both http:// and https:// addresses. This used to be apachectl sslstart but that command has been depreciated.
The URL below includes instructions on how to remove the pass phrase prompt when apache starts

http://httpd.apache.org/docs/2.0/ssl/ssl_faq.html#removepassphrase

Nov 26

Installing Apache 2.0.* with PHP 5.* in Windows

Much documented as the above process is, a lot of people still get stuck in some part of the installation process or the other (me included). It is not a complicated process really, its just that there are some simple tips and tricks which people have learned the hard way and these tips and tricks are often not available to the newbie installer.

Apache and PHP are softwares which are actually meant for *nix environments but a surprisingly large number of Windows developers use these platforms as a basis of all web development. Given below are the steps to get a successfull installation of Apache and PHP on Windows.

Why Apache 2.0 and not the latest Apache 2.2.3? Because as of this date, Apache 2.0 has some dll inconsistencies with PHP 5.x versions. PHP 5.2.0 has been released but I havent tried installing it with the latest Apache. Hopefully the problems of incompatibilities have been solved this time round.

1.Installing Apache 2.0

  1. Download the msi installer version of Apache 2.0. Its simpler to install from that than the zip installer
  2. For Windows machines which are running PWS or IIS, you need to turn off the WWW service before running the installer, because Apache defaults to using port 80 for HTTP and it wont start if it finds that port 80 is already in use.
  3. Run the msi installer
  4. Installing the Apache webserver is very simple. Simply follow the default installation screens and you are done.
  5. If all went well, then you will see the red Apache icon in your taskbar.
  6. To test if apache is running, open your web browser and type http://localhost or http://127.0.0.1 . You will see different pages in both the urls but it means your Apache webserver is up and running.

2.Installing PHP

  1. Unzip the php zip file to a folder of your choice.
  2. Thats it. PHP is installed. Simple, huh? Unfortunately you cant fire up your browser and see any php files running just yet. PHP need to be linked in with Apache before php pages start to run on your machine.

3.Changes to Apache 2.0 configuration

  1. Open up httpd.conf file in a text editor. This file exists in the /conf subdirectory of the folder in which Apache is installed.
  2. Do a text search for ‘AddType’. You will find lines which start with the AddType directive. After the last AddType line add these two lines:
    1. #php 5
    2. AddType application/x-httpd-php .php
    3. This tells Apache to handle php files as a registered application type.
  3. Do a text search for ‘DirectoryIndex’. Most likely this line will show as :
  4. DirectoryIndex index.html index.html.var
  5. This means that if a url does not specify a file, but only a folder, then the default page to load will be index.html. We want to change it so that it loads index.php when no file is specified. So change it to :
    DirectoryIndex index.php index.html index.html.var
  6. So now index.php becomes the default file for all directories.
  7. Do a text search for ‘LoadModule’ in httpd.conf. After all the LoadModule lines add the following line (assuming php is in c:php) :
    1. LoadModule php5_module c:/php/php5apache2.dll

4.Changes to PHP configuration

  1. Copy php.ini-dist in the php folder to php.ini. If php.ini-dist is not present, copy php.ini-recommended to php.ini.
  2. Open php.ini in an editor.
  3. Do a text search for ‘extension_dir’ . Most likely this line will show as
    1. extension_dir = “./”
    2. Change that to the complete path where the php extensions are present. Generally this is the ext folder under the php folder. So an example of this would be :
    3. extension_dir = “c:/php/ext”
  4. Do a text search for ‘Windows Extensions’. Once there, scroll down till you find the lines starting with extension= . If you plan to use mysql then uncomment the line extension=php_mysql.dll.
  5. If you want to run php with mysql then copy a file called libmysql.dll from the php directory to the Windows sytem folder i.e /System32.
  6. If you want to use the curl module then asuming you have uncommented the extension=php_curl.dll in php.ini , copy ssleay32.dll and libeay32.dll from the php directory to the Windows sytem folder (System32).
  7. Copy the updated php.ini file into the Windows folder i.e c:windows or c:winnt.
  8. Copy php5ts.dll from the php directory into the Windows system folder ie.System32

5.Test php with apache

Make a page called test.php with the following line:

phpinfo();

and save it in the Apache default website folder ie. the htdocs folder under the Apache folder.

Type http://localhost/test.php

If all has gone well, then you should see the page run.

Let me know if I missed out on something. I would be glad to incorporate your inputs to this blog