Thursday, February 23, 2012 - 04:55
FeedBurner  RSS 2.0 Feed  Follow Me On Twitter  Save On Delicious

Installing Apache 2.2 With Php 5

Guide on how to install Apache 2.2 With Php 5 On FreeBSD

Yes yet another guide on how to install Apache 2.2 with Php 5 on FreeBSD. There are many ways to do this. And I’m not saying my way better. But I can confirm this method has worked fine on all systems I’ve installed Apache 2.2 with php5 on.

As root
cd /usr/ports/www/apache22
make install clean

When the configuration screen pops up just accept the default values unless you have very specific needs. Note if you need “mod_security” you will not find it in this listing.

Once the installation is done we need to add apache to rc.conf so it will launch at startup.

Add the following to /etc/rc.conf

As root
apache22_enable="YES"

If you don’t feel like editing the file manually you can append it to /etc/rc.conf like this.

As root
echo apache22_enable=\"YES\" >> /etc/rc.conf

We can now try and start apache

As root
apachectl start

After starting apache 22 you will most likely get an error saying something like below

Output
[warn] (2)No such file or directory: Failed to enable the ‘httpready’ Accept Filter

In order to fix this add the following to your loader.conf accf_http_load="YES" you can do it like this

As root
echo accf_http_load=\"YES\" >> /boot/loader.conf

Either reboot or load the module manually. In order to load the module manually type the following

As root
kldload accf_http

And then restart apache like this

As root
apachectl stop
apachectl start

Before you proceed and install Php5 take the time and adjust the httpd.conf file to reflect your minimum needs and test if the installation works. Doing this saves you the time of doing troubleshooting 2 places PHP and or Apache if something fails.

Installing Php5

This is quite easy and straight forward we will install Php5 from ports.

Before we begin I would like to point out that if you intend to run Squirrelmail you will need to enable “Track-Vars” when compiling Php5.

To be honest I haven’t checked lately if Squirrelmail still requires it, but there is absolutely no harm done in enabling it. Enabling track-vars is not listed in the option screen when we run “make install clean” so we need to edit the “Makefile” before we install Php5.

As root
cd /usr/ports/lang/php5

As root
vi Makefile

Find the following lines
--with-layout=GNU \
--localstatedir=/var \
--with-config-file-scan-dir=${PREFIX}/etc/php \
--disable-all \
--enable-libxml \
--with-libxml-dir=${LOCALBASE} \
--with-pcre-regex=${LOCALBASE} \
--with-zlib-dir=/usr \
--program-prefix=""

Add the following line:

Add the following line
--enable-track-vars \

They should now look like this
--with-layout=GNU \
--localstatedir=/var \
--with-config-file-scan-dir=${PREFIX}/etc/php \
--disable-all \
--enable-libxml \
--enable-track-vars \
--with-libxml-dir=${LOCALBASE} \
--with-pcre-regex=${LOCALBASE} \
--with-zlib-dir=/usr \
--program-prefix=""

Now that everything is in place we are ready to install Php5

As root
cd /usr/ports/lang/php5
make install clean

Accept the default values [Screenshot] and be sure to also check the following:

Build Apache Module
Enable Sohusin protection system
Enable Zend multibyte support

Once done we need to make sure that Pph5 is Added as a Type in apaches httpd.conf file. Add the the lines shown below to the httpd.conf file just below the line that says “#AddType application/x-gzip .tgz”

Add the following lines to httpd.conf
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Your httpd.conf should look like this
# AddType allows you to add to or override the MIME configuration
# file specified in TypesConfig for specific file types.
#
#AddType application/x-gzip .tgz

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

We need a php.ini configuration file for php to work with. We’ll use one of the defaults that came with the installation.

As root
cp /usr/local/etc/php.ini-development /usr/local/etc/php.ini

Restart apache for the changes to take affect.

As root
apachectl restart

Now we just need to test if things are running as intended. We will need create a php test file for this.

As root
echo -e "<?php \nphpinfo();\n?>" > /usr/local/www/apache22/data/phptest.php

Test if things are running as intended by launching phptest.php in a browser.

Finishing Up

With Php5 installed a lot of your old Php proggies will probably do a lot of complaining and show a lot of warnings on your Php pages even though they’re working. Displaying this should be disabled for security reasons. So let’s do this

As root
vi /usr/local/etc/php.ini

Find the following line

Find the following line
Change error_reporting = E_ALL | E_STRICT

Change it to
error_reporting = E_ALL & ~E_NOTICE

Find the following line
display_errors = On

Change it to
display_errors = Off

Next you will see php5 spamming your log files with a timezone warning we need to fix this as well.

Find the following line
;date.timezone =

Remove the ; and add the correct timezone. I use Europe Copenhagen here cause this is where this server is located.

Example of my timezone
date.timezone = Europe/Copenhagen

Restart apache for the changes to take affect.

As root
apachectl restart
Related Guides  Links  Requirements