PHP goes AWOL

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:
apachectl restart

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.

Advertisements

4 thoughts on “PHP goes AWOL

  1. John,
    Found this page on a search and am having a similar problem, however, I am nearly not as technical as you ( newbie) so your description of what to do is foreign. Let me explain my problem – have coded an html form whose action is to load a php file (myfile.php). When executed, the file is loaded into dreamweaver editor! yet when I go to browser and type localhost/myfile.php it executes fine. Is this similar to your issue and is the above required to correct it? If so, where would I get info on how to do the above.
    Thanks in advance.
    Bob

  2. Hi Bob,

    Believe it or not, I think your system is behaving the way you want it to. In order to execute properly, a PHP file has to be parsed and processed by a code processor (in your case, that would be the php.exe file on your system). Since it’s generally unsafe to execute scripted code on your local machine (unless you know it’s your code and not someone else’s malicious program… you never know what someone else’s code will do when it’s executed), the action assigned to double-clicking the file is to edit it using Dreamweaver, instead of trying to process it. As long as the code appears properly in your browser when you check it on your localhost “server”, I think you’re okay.

    Does that help? If not, let me know.

    ~John

  3. John,
    I understand what you are saying and thanks for the caveat. Yet, in other pages, I call a php routine using the and it executes; I have html programs that go in and out of php, yet I still can’t call this script from the form action field…..am I missing something; it seems to me it should work. Thanks for your assistance.
    Bob

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s