Lampros - Weird Bricks

PHP Support for Apache 1.3 on FreeBSD

20 February, 2011 | FreeBSD

In the 2 previous tutorials, we saw how to install Apache on FreeBSD and how to get it to work with OpenSSL for encrypted connections. In this one, we'll install the uber popular server-side programming language PHP


Start by booting up FreeBSD. Then the first thing you'll want to do is install PHP5.

Go to the PHP5 port directory.
cd /usr/ports/lang/php5
Then do a make install clean



You'll get a screen with Options for PHP5. Take the defaults and also add the Apache module, then select OK to continue.



When the port is done you should get something like this:



Now let's go ahead and also install the PHP5 extensions. You need this to get things like MySQL support, SQLite, LDAP, sessions etc.

cd /usr/ports/lang/php5-extensions
make install clean




You're going to get lots of options and it's up to you what to select here, however I recommend at least the defaults.



Like before, use TAB to go to 'OK' and continue.


In my case, SQLite gave me a bunch of options to select, I'm good with the defaults, so just select 'OK' to continue.



and more :



just go with the defaults, unless you know better.

If all went well, the end should look like this:



Now, let's check if Apache was configured correctly,
ee /usr/local/etc/apache/httpd.conf



Go to the end of the document and add the following lines:
<IfModule mod_php5.c>
DirectoryIndex index.php index.html
</IfModule>
<IfModule mod_php5.c>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
</IfModule>


it should look like this:



then exit and save.

In case Apache is already running, restart it, type:

/usr/local/sbin/apachectl restart



To try and see if PHP is working the easiest thing to do is:
ee /usr/local/www/data/phptest.php

And inside the file type:
<?php
phpinfo(INFO_MODULES);
?>

should look like this:


Fire up a browser (Firefox of course!) and type the following to access our test page: http://192.168.2.101/phptest.php

You should get something like this …



If you scroll down enough, you should see the SQLite details too



Works fine! Time for coding!!