Guide On How To Install Apache 24 With Php7 On FreeBSD

Guide On How To Install Apache 24 With Php7 On FreeBSD 2017-08-23T01:29:20+00:00

A Step By Step Guide On How To Install Apache 2.4 With Php71 On FreeBSD
Another Apache how to guide you say. Well the ones I tried “and there are quite a few out there” did not quite work out. So I decided to create my own. Is it better? I don’t know, all I know is that it works. Right let’s get started shall we?

cd /usr/ports/www/apache24 && make install clean BATCH=yes

Enable apache to start after boot. Add the following to /etc/rc.conf


We need to edit some startup parameters for apache. Change the following lines in /boot/defaults/loader.conf

accf_data_load="NO"             # Wait for data accept filter
accf_dns_load="NO"              # Wait for full DNS request accept filter   
accf_http_load="NO"             # Wait for full HTTP request accept filter

To the following

accf_data_load="YES"            # Wait for data accept filter
accf_dns_load="NO"              # Wait for full DNS request accept filter   
accf_http_load="YES"            # Wait for full HTTP request accept filter

Now we need to think about the payload this web server will be getting. If your are not getting flooded by bots and other stuff you are probably fine otherwise you can tweak your connection settings like the example below by editing this file /etc/sysctl.conf


Next we are going to add some default directories /var/log/www for specific web site log files and. And I’ve chosen the old directory structure regarding cgi-bin. The last one is merely because many programs still rely on cgi-bin being located there. And insted of doing rewrite rules everytime for each website I rather just go with this option and set the cgi-bin path globally in httpd.conf.

mkdir /var/log/www
mkdir /usr/local/www/cgi-bin
:> /usr/local/www/apache24/data/index.html

Right time to check the sanity of apache.

apachectl configtest

Now because we have not configured the apache configuration file yet you may receive an error stating the following.
“Could not determine the server’s domain name, using Set the ‘ServerName’ directive globally to suppress this message”
As the error says the “Servername” is not set in the httpd.conf file. Apache will still work though. So let’s start apache.

apachectl start

You should now be able to access your apache server through a browser using the ip address.

Installing Php71
Now before you start you need to consider one thing. Do you need track vars? If you don’t know then you probably wont need it. And you can skip the track vars part. Reason I write this is because we need to enable track vars before we do anything else in terms of php7 installation.

Optional compile php71 with track vars start:

cd /usr/ports/lang/php71
vi Makefile

Modify the Makefile in the configure_args section by addig the following line. Somewhere around the highlighted area.

--localstatedir=/var \
--with-config-file-scan-dir=${PREFIX}/etc/php \
--disable-all \
--enable-libxml \
--enable-track-vars \
--enable-mysqlnd \
--with-libxml-dir=${LOCALBASE} \
--with-pcre-regex=${LOCALBASE} \

Optional compile php7 with track vars stop:

cd /usr/ports/www/mod_php71 && make install clean BATCH=yes

Next let’s get the php.ini configuration file in place.

cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
chmod 444 /usr/local/etc/php.ini
apachectl restart

Create a php test page showing info about our apache and php installation. Note this will not work until you are done configuring your httpd.conf file as apache is not yet instructed to handle php files. I have a guide on how to configure httpd.conf [here].

echo -e "" > /usr/local/www/apache24/data/phptest.php

Installing Php71 Extensions

If you which to add some Php71 extensions I have a guide [here]

And we are done here.

Spell checkers don’t – Grammar checkers don’t either.