Friday, June 27, 2008

Err: PHP files opened to save instead of run in Apache, Ubuntu

Error:
    PHP file will give as 'Save as dialog' while accessing .php file in browser.

Reasons:
   
    This is because, each and every MIME file-type with respect to the computer should be registered before to be accessed by the users. Otherwise the system throws error instead of executing (or) opening that requested file.
    Similarly, in Ubuntu, after installing all the needed packages for PHP, a package called 'libapache2-mod-php5' will be in the state of corrupted. This the PHP linking package for Apache which tells that 'How to handle the .php files'.
       
Solution:

    Reinstall the package once and restart the Apache too. Even the same problem occurs, the give the 'Completely remove option before reinstalling that.
    Or else use this command,
   
    $ apt-get remove --purge libapache2-mod-php5
    $ apt-get install libapache2-mod-php5
    $ /etc/init.d/apache2 restart



Other than Ubuntu OS use this,


Step 1: Create a file called php.conf and fill it with this data:

        AddType application/x-httpd-php .php .phtml
        DirectoryIndex index.php

    Save it @ /etc/apache2/mods-enabled/

Step 2: Create a file called php.load and fill it with this data:

        LoadModule php5_module modules/libphp5.so

    Save it @ /etc/apache2/mods-enabled/
    Note : I'm using my libphp5.so as example but yours might be in other place. Search for it in your machine and use the path to your file.

Ste 3: Restart your apache with
    sudo /etc/init.d/apache2 restart

No comments:

Post a Comment