There are many PHP sub-ports in the ports tree, each port passes a different switch to the php configuration script and rebuilds php. If you need a particular option turned on in PHP you can install it through the specific port, for example you may want to add the ctype extension to PHP,
cd /usr/ports/textproc/php4-ctype
make
make install
make clean && make distclean
If you look at the Makefile for php4-ctype, it contains one switch -ctype. This port will rebuild php with the -ctype extension enabled.
If you want a nice interface to add multiple php extensions then look no further than /usr/ports/lang/php4-extensions. It will rebuild php with the extensions you want:

Note: If you need to reconfigure php4-extensions at a later stage, make sure to remove
/var/db/ports/php4-extensions/optionsotherwise typing make will simply bypass the configuration screen and build with the previous set of options.
Configure and build PHP from source.
First fetch the latest source code from here. In my case I fetched the file from a local mirror:
fetch http://php.planetmirror.com/get/php-4.4.1.tar.gz/from/au.php.net/mirror
I tend to download all my tarballs to a local source directory /usr/local/src
cd /usr/local/src/php-4.4.1/
./configure --with-apxs=/usr/local/sbin/apxs
--enable-track-vars
--enable-versioning
If you’ve installed mod-ssl as per my apache-mod-ssl guide, you may wish to add the following
--with-openssl to the configuration options.
If you’ve installed mysql or postgres you may wish to add the following to your configure options
--with-pgsql=/usr/local
--with-mysql=/usr/local
There are many, many command line switches available for php, if you want to add others look at the documentation or at the list of php configuration options.
Next we build php with the usual
make
make install.
Finally copy the php.ini-dist file from the local directory to /usr/local/lib/
cp php.ini-dist /usr/local/lib/php.ini
PHP should now be configured.
Note: For production servers it is better to copy php.ini-recommended from the build directory to /usr/local/lib
Edit /usr/local/etc/apache/httpd.conf
While the php install script modifies httpd.conf, it fails to add the appropriate line
AddType application/x-httpd-php .php
to the httpd.conf, I usually add it just under the line that says AddType application/x-tar .tgz.
Finally, we add a test file to see if php has run up without problems:
echo "< ?php phpinfo(); ?>" > /usr/local/www/data/info.php
Depending on your setup you may need to change file permissions,
chmod 644 /usr/local/www/data/info.php
If apache is running stop it with
apachectl stop.
Restart apache now, so that it runs up with PHP
apachectl start
Then point your browser to www.yourdomain.com/info.php, where yourdomain
is your domain name, or just to your ip address: 111.222.333.444/info.php
If all has gone well, apache is up and running, and you should see your php information.