Switching to PHP5 on 1and1 Linux Hosting

I recently upgraded a client to a 1and1 Linux Business Pro hosting package and so far I have found no major obstacles.

The previous environment was a dedicated Windows 2003 server in which there was free reign to modify any of the core files, including the PHP installation and any other similar files.

Within the hosted environment, the access you have to installation directories or configuration files is nil. One related error I came across within the first few minutes of moving an installation of Joomla! 1.5.x from the Win2k3 environment running IIS to the Linux host running Apache was that the following error:
Parse error: syntax error, unexpected T_OBJECT_OPERATOR

The error, in this case, was caused by the fact that the server was running PHP4 whereas the Joomla! installation required PHP5 to operate. In a dedicated environment this wouldnt be problem, merely a case of updating the installation. In a hosted environment I immediately assumed it would require me contacting 1and1 and getting them to upgrade.

Apparently, one solution requires you to alter the file-extension of all PHP files to .php5, but really – who on Earth would want to do that? Granted, you could do it with a .bat in a couple of minutes but still it doesn’t seem as elegant as the alternative.

Fortunately, the answer was much more straightforward than that. I quickly discovered from the 1and1 FAQ that in the Linux hosting package you can choose to run either PHP4 or PHP5, with PHP4 running as default. To parse all PHP files within a directly as PHP5 simply requires the editing of the root (to that specific directory) .htaccess file.

In altering the .htaccess, simply add the following line:
AddType x-mapp-php5 .php

Uploading this modified .htaccess will tell Apache to use PHP5 instead of PHP4 for the extension .php in the directory the .htaccess is placed and all sub-directories under it.

Using the .htaccess is a great way to control the configuration of your Apache installation if you do not have direct access to the httpd.conf or the PHP installation.

2 Comments

  1. William from Lagos
    Posted July 27, 2009 at 12:38 am | Permalink

    Hey thanks. Just came across this great tip

  2. Posted May 24, 2010 at 8:45 pm | Permalink

    This was very helpful thank you very much. I almost accidentally alter the root/log .htaccess file on accident. You might want to mention that the root directory might not have an .htaccess file but you can create one with the single line of code mentioned above and it works flawlessly!

Post a Comment

Wrap code blocks with <pre lang="LANGUAGE" line="1"> and </pre> where LANGUAGE is a GeSHi supported language syntax. The line attribute is optional. More help here.

Your email is never shared. Required fields are marked *

*
*