How to run PHP5 on 1and1.com in 1 easy step…
It actually can’t get any easier than this.
Just put the following line in your .htaccess file:
AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php
And your done! Your site is now running under PHP5.
Enjoy…
Want proof? Want to know details?
Well… Here you go…
It turn’s out that 1and1.com accounts all come with PHP4 active. By default php files are processed by PHP Version 4.4.2.
Test this out on your 1&1 server without affecting the operation of your site:
Create a new directory called TestPHP4
Create a file in that folder called index.php that contains the following text
-
<?php
-
?>
Then open that directory in your web browser.
You’ll get something that looks like this:
PHP Version 4.4.2 |
| System | Linux infong 2.4 #1 SMP Wed Jan 18 14:53:29 CET 2006 i686 unknown |
| Build Date | Feb 6 2006 10:16:02 |
| Configure Command | ‘../configure’ ‘–with-pear’ ‘–with-mysql=/usr’ ‘–with-zlib’ ‘–enable-debug=no’ ‘–enable-safe-mode=no’ ‘–enable-discard-path=no’ ‘–with-gd=/usr’ ‘–with-png-dir=/usr/lib’ ‘–enable-track-vars’ ‘–with-db’ ‘–with-gdbm’ ‘–enable-force-cgi-redirect’ ‘–with-ttf=/usr/’ ‘–enable-ftp’ ‘–with-mcrypt’ ‘–enable-dbase’ ‘–enable-memory-limit’ ‘–enable-calendar’ ‘–enable-wddx’ ‘–with-jpeg-dir=/usr/src/kundenserver/jpeg-6b’ ‘–enable-bcmath’ ‘–enable-gd-imgstrttf’ ‘–enable-shmop’ ‘–enable-mhash’ ‘–with-mhash=/usr/src/kundenserver/mhash-0.8.9/’ ‘–with-openssl’ ‘–enable-xslt’ ‘–with-xslt-sablot’ ‘–with-dom’ ‘–with-dom-xslt’ ‘–with-dom-exslt’ ‘–with-imap’ ‘–with-curl’ ‘–with-iconv=/usr/local’ ‘–with-freetype-dir=/usr/include/freetype2′ ‘–with-bz2′ ‘–with-gettext’ ‘–enable-exif’ ‘–with-idn’ ‘–enable-mbstring=all’ |
| Server API | CGI |
| Virtual Directory Support | disabled |
| Configuration File (php.ini) Path | /usr/local/lib/php.ini |
| PHP API | 20020918 |
| PHP Extension | 20020429 |
| Zend Extension | 20050606 |
Now copy and rename the TestPHP4 directory as TestPHP5 (or create the directory as above manually). Now create one more file in the TestPHP5 directory named .htaccess
Make certain a period is in front of htaccess like this: .htaccess
The period indicates this it is a hidden file. It tells your system how to process requests. In this case we will tell it to process all .php files as php5 files. That is done by adding the following line:
AddType x-mapp-php5 .php
Now save that file and browse to the directory with your web browser. You’ll see something like the following:
PHP Version 5.1.4
| System | Linux infong371 2.4.28-grsec-20050113a #1 SMP Thu Jan 13 08:59:31 CET 2005 i686 |
| Build Date | May 4 2006 13:56:29 |
| Configure Command | ‘../configure’ ‘–program-suffix=5′ ‘–with-pear=/usr/local/lib/php5′ ‘–with-config-file-path=/usr/local/lib/php5′ ‘–with-libxml-dir=/usr/local/php5′ ‘–without-sqlite’ ‘–with-config-file-scan-dir=.’ ‘–with-mysqli=/usr/local/mysql/bin/mysql_config’ ‘–enable-soap’ ‘–with-xsl=/usr/local/php5′ ‘–enable-mbstring=all’ ‘–with-curl=/usr/local/php5′ ‘–with-mcrypt=/usr/local/php5′ ‘–with-gd’ ‘–with-pdo-mysql=/usr/local/mysql’ ‘–with-freetype-dir’ ‘–with-libxml-dir=/usr/local/php5′ ‘–with-mysql=/usr/local/mysql’ ‘–with-zlib’ ‘–enable-debug=no’ ‘–enable-safe-mode=no’ ‘–enable-discard-path=no’ ‘–with-png-dir=/usr/lib’ ‘–enable-track-vars’ ‘–with-db’ ‘–with-gdbm’ ‘–enable-force-cgi-redirect’ ‘–with-ttf=/usr/’ ‘–enable-ftp’ ‘–enable-dbas’ ‘–enable-memory-limit’ ‘–enable-calendar’ ‘–enable-wddx’ ‘–with-jpeg-dir=/usr/src/kundenserver/jpeg-6b’ ‘–enable-bcmath’ ‘–enable-gd-imgstrttf’ ‘–enable-shmop’ ‘–enable-mhash’ ‘–with-mhash=/usr/src/kundenserver/mhash-0.8.9/’ ‘–with-openssl’ ‘–enable-xslt’ ‘–with-xslt-sablot’ ‘–with-dom’ ‘–with-dom-xslt’ ‘–with-dom-exslt’ ‘–with-imap’ ‘–with-iconv=/usr/local’ ‘–with-bz2′ ‘–with-gettext’ ‘–enable-exif’ ‘–with-idn’ |
| Server API | CGI |
| Virtual Directory Support | disabled |
| Configuration File (php.ini) Path | /usr/local/lib/php5/php.ini |
| Scan this dir for additional .ini files | . |
| PHP API | 20041225 |
| PHP Extension | 20050922 |
| Zend Extension | 220051025 |
You now have two different directories that process files using two different php engines.
Pretty cool huh?
Thanks pal much appreciated - great tip. saved me a lot of time
Comment by j2ee — August 21, 2006 @ 6:01 pm
Hey thanks man. I called 1and1 and they insisted that mysqli wont work unless i get a dedicated server. This is a great tip. I didnt even notice it defaults to php4.
Comment by ugabuga — November 25, 2006 @ 1:04 pm
ugabuga: that's a stock response from 1and1's support drones. Part of the reason I'm going to dump them shortly.
The other part of the reason: This recent php5 upgrade has, predictably, killed my site with incessant "cgi-limits reached" error messages (an obviously false result). I'm going to try this .htaccess fix tonight, assuming I can find a brief window in which to actually access the site. Hope it works. Regardless, I've had it with 1and1 -- every time they inflict a change, I have to scramble, and they NEVER accept responsibility for the problems.
Comment by CT — December 13, 2006 @ 12:52 pm
Interesting, what changes have you run afoul of before? I've not noticed them update much of anything I care about at all...
My question would be, if you are running still php4 how did the update have any affect? Did they make other change?
Comment by Brian — December 14, 2006 @ 5:38 pm
but if you type
php -v
In the command line, you will get php 4.4.1
which one tell you the truth? phpinfo() or command line?
Comment by pear — May 16, 2007 @ 2:11 pm
Both!
The default PHP processor IS 4.4.1. and that's what you get when you run php directly from the command line.
However, when a request comes through the http: interface, Apache will see the over-ride and send it to the newer release.
So, both are telling the truth, because you are asking two different questions.
Hope that helps
Comment by Brian — May 16, 2007 @ 2:42 pm
[...] How to run PHP5 on * in 1 easy step… Originally about 1and1, who host some of my sites. (tags: php web hosting howto reference BryanLayman) Tags:None [...]
Pingback by elliptical . . . : Blog Archive : links for 2007-05-20 — May 20, 2007 @ 3:42 am
The "AddType" rule works great for non-secured sites on 1and1.com, but NOT secured sites. From one of the "support" people at 1and1 (I use the word "support" lightly).
"The AddType rule will not work when accessing through https. You will
need to rename any scripts that should be parsed in PHP 5 to end in
.php5."
I ended up renaming everything to get it to work. Ridiculous actually.
Comment by JTS — June 4, 2007 @ 11:43 pm
Oh, how interesting... I'm not buying the "simply doesn't work" answer. There's more to it then that, I'm sure. How do you have your https configured. Are you using your own certificate or the shared one? This is something I've not yet played with on these servers. I bet there is a deeper answer to your problem.
Comment by Brian — June 5, 2007 @ 6:42 am
Brian, the cert came with the developer package. I used the default setup procedures that 1and1.com provides.
My entire web-app was built in PHP5. It works great with the .HTACCESS file in non-secure mode. As soon as you switch over to the good ol' HTTPS, it bombs miserably. I've tried renaming some of the files to be .PHP5 and it does actually work. Its just frustrating that the .HTACCESS file does not work in HTTPS mode. 1and1 usually hasn't given me any grief, but if they are going to support PHP5 AND provide documentation demonstrating the .HTACCESS file, they should definetly make it clear that it will not work in Secure mode.
Comment by jts — June 5, 2007 @ 2:01 pm
Oh, I understood that, I just don't understand why secure mode has any thing do do with it unless it is somehow first being processed through a seperate server...
Comment by Brian — June 5, 2007 @ 3:00 pm
hehe. That's the million dollar questions (or 14.95 a month). Thank God I built the system in a relatively modular fashion, as I only had to change the names of the business processing scripts. (http://EverythingFreight.com if you are interested).
Comment by JTS — June 6, 2007 @ 9:49 pm
Hiya - I had the same issue on 1and1 - using the SSL certificate that comes integrated with their accounts - https seemed to just the AddType from working.
I used phpinfo to check - and the https server did default back to PHP4.
So I added AddHandler x-mapp-php5 .php to my .htaccess ... and way hay everything is back to php5
Another way round this is to use their free ssl relay service which seems to keep everything working happily on PHP5 - but you do end up with an ugly url ...
In 1and1 control panel - in admin / domains select which domain you want to register with their relay server then just use
https://sslrelay.com/
Hope that helps someone ...
Comment by bluefish — June 29, 2007 @ 7:20 am
In .htaccess put:
AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php
seems to work on our secure site
Comment by Rail — October 29, 2007 @ 4:56 pm
Rail....
Tried it and used a specific PHP5 test (hello world with a try/catch) and it seemed to work. Not sure why the help desk didn't offer that up! Will have to do more testing to double check it is working.
Comment by jts — October 29, 2007 @ 5:10 pm
There is a link somwhere in 1and1's help desk but it is buried really deep in there. I thought about taking down this post when I saw it was there but then I figured that if I couldn't find it till I knew what to look for, others were probably in the same boat. Glad this worked for you!
Comment by Brian — October 30, 2007 @ 1:11 am
works fantastic, but any chance you know why something keeps rewriting my htaaccess file and removing those lines?
Comment by Lon — November 30, 2007 @ 4:44 pm
Probably one of their automated tools? Did you password protect any directories or use any other 1and1 web tools to manage your account?
Comment by jts — November 30, 2007 @ 4:47 pm
Thanks so much man! As soon as I needed PHP 5 and found it was not the default, I got a little worried, but one quick search and alas I found your tip! You've saved the day for me! Keep up the great work!
Comment by James — January 21, 2008 @ 5:39 pm
For those of you who are anti 1and1, what host would you suggest as an alternative (and don't say godaddy) ? I have been relatively pleased with 1and1 until I tried using the Zend Framework with it and it has just been a confusing mess.
Comment by Michael Ray — February 9, 2008 @ 1:36 pm
Thanks for the tip, I had AddType x-mapp-php5 .php already in my .htaccess and experienced the issue with it defaulting to php4 when using SSL. I added the line AddHandler x-mapp-php5 .php and it worked great!! thanks for saving me from renaming all my php files!
Comment by travis — February 14, 2008 @ 9:36 pm
@Michael
A Small Orange offers both PHP4 and PHP5. SSL works with no gimmicks.
http://www.asmallorange.com/
Comment by Craig — February 16, 2008 @ 1:03 am
There are two that I have experience with and would personally recommend. They are in no particular order, ServerBeach.com and DreamHost.com.
Server Beach is VERY WordPress friendly and I've met them and wear their shirts. We host some machines with them for b5media. In fact I should make certain I put one of their stickers on my laptop.
DreamHost.com is well named. You will not be unhappy with them. They have a great group of people and their tech team is top knotch. They had a recent billing snafu, that went spiraling south quickly as they quickly swung the other way sending out refunds where none were due. Through this whole thing, they handled the issues quite openly and professionally. The fact of the matter is that stuff happens. What you do about it shows your character and how Dreamhost handled this proved everything I'd always suspected about them when I looked at them from a distance. And I would proudly wear one of their shirts too if I had one.
Comment by Brian — February 21, 2008 @ 5:48 pm
THX very much for the tipp.
Since 1and1 changed something on their hosting enviroment my gallery2 and wordpres just gave up working. Just with these two tiny lines everything is fine now.
2 thumbs up
Comment by Hendrik — March 26, 2008 @ 11:26 am
Thank you so much - this really helped us out - all fixed now at http://www.empdesigns.co.uk
Comment by Emily — April 17, 2008 @ 4:27 am
Thanks! I just created a file in my root directory called "testphp.php" and opened that in my browser after editing my .htaccess ... Worked great.
Comment by Jim — April 22, 2008 @ 7:09 pm