About a week ago, I began having trouble viewing PHP files on my PC– not with editing or parsing them, but simply with viewing web site files on my server that contained any PHP code. Since this was a sudden problem, and because I had always been able to view PHP files in my browser before, I foolishly assumed that the errors coincided with the installation of a web development appplication (Macromedia/Adobe Dreamweaver) and were related to system file type associations. Boy, was I wrong!
As it turns out, the errors also coincided with another event, though not a local one: I had also updated my FreeBSD server from version 5.4 to 6.1 on the same day as the Dreamweaver installation. Apparently, the FreeBSD upgrade didn’t conclude as flawlessly as I had hoped, although I had no idea that anything had gone wrong. A few checks into the system (including a simple php -v command) revealed that three of the PHP modules for Apache (namely ImageMagick, GD, and PDF) were no longer functioning properly. I wonder whether anything else got screwed up…
In order to repair the PHP errors, and get the support on my web server for PHP code back up and running, I had to deinstall and reinstall PHP and its related extensions. The steps:
php -v # tests the current PHP installation (mine displayed module errors)
cd /usr/ports/lang/php5-extensions # the install directory for PHP extensions/modules
make deinstall clean # deinstalls the extensions (and the flotsam)
cd ../php5 # the install directory for PHP
make deinstall clean # deinstalls PHP
make config # PHP configuration; be sure to select the APACHE option to build the Apache module here
make install clean # installs PHP using your selected configuration options
cd ../php5-extensions # back to the extensions directory
make install clean # installs the extensions; again, you could (and probably should) do a make config first
Since this was a reinstall for me, and not an initial installation of PHP, I didn’t need to perform any additional configuration. But I did check my Apache configuration file (/usr/local/etc/apache2/httpd.conf) just to ensure it still contained the following lines, which load the PHP modules necessary to process both .PHP and .PHPS files, in the LoadModule section:
AddType application/x- httpd-php . php
AddType application/x- httpd-php-source . phps
LoadModule php5 libexec/libphp5.so
I then restarted my Apache web server:
Afterward, a final php -v command gave positive feedback. And back on my PC, I was once again able to view those PHP files on my server.
Since the errors originated from a few of the PHP library modules, and not from PHP itself, this could probably have been accomplished by deleting the offending library modules, and then deinstalling and reinstalling the extensions port, which would rebuild the missing library modules during installation.
If one or more library modules still turn up corrupt, you may have to deinstall the php5-extensions port, delete the offending modules from the PHP library (in the directory /usr/local/lib/php/[PHP_build_date]), deinstall and reinstall the module to rebuild the library, and finally, reinstall the php5-extensions package.