Php – Apache: Change XAMPP/PHP handle from application/x-httpd-php to application/x-httpd-php5

apacheconfigurationPHPxampp

My goal is to stop having to have a local copy and a live copy of my .htaccess file and instead be able to use the same single .htaccess file for BOTH local/live configurations. This will force me to better understand configuring a server.

My local server is XAMPP on my computer while my live server is a shared web host where I obviously can't change settings. I'm not at the point where I can configure everything from scratch so I'll be sticking with XAMPP for a while longer. Additionally anyone familiar with XAMPP should know that I attempted to use their forums (broken signin/password reset) and the admin hasn't responded to my email for days so I did try the more on-target route without success.

The more specific issue is I want to use my live shared server's PHP handler for my local server.

To execute PHP in non-native files on my live shared web host I use the following…

public_html/.htaccess

AddType application/x-httpd-php5 .css .html .js .txt .xml

…I want to configure my computer/local setup to emulate this so I don't have to keep separate copies of .htaccess files for local/live (this forces me to learn how to configure the server). Currently I have to use the following locally…

public_html/.htaccess

AddType application/x-httpd-php .css .html .js .txt .xml

I was able to track down where the configuration seems to be in XAMPP 1.7.7 (current latest release)…

xampp\apache\conf\extra\httpd-xampp.conf

Now I'm not interested in changing the PHP version that's being used (not my goal)…I just want to make sure that I can use the same handle locally as I do live. I tried to simply add the string '5' to line 17(?) below though that didn't work (saved, stopped server, restarted server of course).

<IfModule env_module>
    SetEnv MIBDIRS "C:/MEDIA/INTERNET/xampp/php/extras/mibs"
    SetEnv MYSQL_HOME "\\xampp\\mysql\\bin"
    SetEnv OPENSSL_CONF "C:/MEDIA/INTERNET/xampp/apache/bin/openssl.cnf"
    SetEnv PHP_PEAR_SYSCONF_DIR "\\xampp\\php"
    SetEnv PHPRC "\\xampp\\php"
    SetEnv TMP "\\xampp\\tmp"
</IfModule>

#
# PHP-Module setup
#
LoadFile "C:/MEDIA/INTERNET/xampp/php/php5ts.dll"
LoadModule php5_module "C:/MEDIA/INTERNET/xampp/php/php5apache2_2.dll"

<FilesMatch "\.php$">enter code here
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>

#
# PHP-CGI setup
#
#<FilesMatch "\.php$">
#    SetHandler application/x-httpd-php-cgi
#</FilesMatch>
#<IfModule actions_module>
#    Action application/x-httpd-php-cgi "/php-cgi/php-cgi.exe"
#</IfModule>


<IfModule php5_module>
    PHPINIDir "C:/MEDIA/INTERNET/xampp/php"
</IfModule>

<IfModule mime_module>
    AddType text/html .php .phps
</IfModule>

ScriptAlias /php-cgi/ "C:/MEDIA/INTERNET/xampp/php/"
<Directory "C:/MEDIA/INTERNET/xampp/php">
    AllowOverride None
    Options None
    Order deny,allow
    Deny from all
    <Files "php-cgi.exe">
        Allow from all
    </Files>
</Directory>

<Directory "C:/MEDIA/INTERNET/xampp/cgi-bin">
    <FilesMatch "\.php$">
        SetHandler cgi-script
    </FilesMatch>
    <FilesMatch "\.phps$">
        SetHandler None
    </FilesMatch>
</Directory>

<Directory "C:/MEDIA/INTERNET/xampp/htdocs/xampp">
    <IfModule php5_module>
        <Files "status.php">
            php_admin_flag safe_mode off
        </Files>
    </IfModule>
    AllowOverride AuthConfig
</Directory>

<IfModule alias_module>
    Alias /security "C:/MEDIA/INTERNET/xampp/security/htdocs/"
    <Directory "C:/MEDIA/INTERNET/xampp/security/htdocs">
        <IfModule php5_module>
            <Files "xamppsecurity.php">
                php_admin_flag safe_mode off
            </Files>
        </IfModule>
        AllowOverride AuthConfig
   </Directory>

    Alias /phpmyadmin "C:/MEDIA/INTERNET/xampp/phpMyAdmin/"
    <Directory "C:/MEDIA/INTERNET/xampp/phpMyAdmin">
        AllowOverride AuthConfig
    </Directory>

    Alias /webalizer "C:/MEDIA/INTERNET/xampp/webalizer/"
    <Directory "C:/MEDIA/INTERNET/xampp/webalizer">
        <IfModule php5_module>
            <Files "webalizer.php">
                php_admin_flag safe_mode off
            </Files>
        </IfModule>
        AllowOverride AuthConfig
    </Directory>
</IfModule>

So I don't know how to assign "application/x-httpd-php5" to work with whatever "application/x-httpd-php" is assigned to and remember I do not want to change the version of PHP I'm using (works fine).

I should also note that after using the program Advanced Find & Replace that I've found eight total files in the XAMPP directory with the string "application/x-httpd-php" however the file above is the only one that seems relevant to Apache's configuration.

Best Answer

Not really an answer to your question, but I wouldn't do this to myself. Apache's config file format isn't really built for stuff like this.

To me, having two separate htaccess files (like .htaccess and .htaccess.local, and controlling the local server through the AccessFileName directive:

AccessFileName .htaccess.local

is the best way to go.

If you really want to have everything in one file, it may be possible by using <IfDefine> blocks to separate local and live directives. You would have to set a define when starting your server locally, and could then test for the presence or non-presence of that define.