I'm using php 5.3
on my local machine. On our webserver we have php 4.8
. Our server is a shared server. So I want to change the php version on our server via .htaccess
file. Is it possible to do it? If yes how to do it?
12 Answers
To switch to PHP 4.4:
AddHandler application/x-httpd-php4 .php
To switch to PHP 5.0:
AddHandler application/x-httpd-php5 .php
To switch to PHP 5.1:
AddHandler application/x-httpd-php51 .php
To switch to PHP 5.2:
AddHandler application/x-httpd-php52 .php
To switch to PHP 5.3:
AddHandler application/x-httpd-php53 .php
To switch to PHP 5.4:
AddHandler application/x-httpd-php54 .php
To switch to PHP 5.5:
AddHandler application/x-httpd-php55 .php
To switch to PHP 5.6:
AddHandler application/x-httpd-php56 .php
To switch to PHP 7:
AddHandler application/x-httpd-php7 .php
To switch to PHP 7.1:
AddHandler application/x-httpd-php71 .php
-
9when I do this none of my php files are processed correctly. Is there something that you need to add to the .htaccess file before you add these statements? Sep 20, 2013 at 0:47
-
8
AddHandler application/x-httpd-php7 .php
did not work for me, butAddHandler application/x-httpd-php70 .php
did the job! May 8, 2017 at 15:26 -
This is a great starting point, but I'll caution you to check with your particular Web host, as some settings can be different. Since I have client sites hosted with different providers, what may work with one won't with another.– karolusJul 10, 2017 at 15:46
-
For me this works when i check phpinfo() but not when running php -v, this still shows the old version and so does composer (uses the old version). any ideas? Jan 3, 2019 at 23:36
Note that all above answers are correct for Apache+mod-php setups. They're less likely to work with more current PHP-FPM setups. Those can typically only be defined in VirtualHost section, not .htaccess.
Again, this highly depends on how your hoster has configured PHP. Each domain/user will typically have it's own running PHP FPM instance. And subsequently a generic …/x-httpd-php52
type will not be recognized.
See ServerFault: Alias a FastCGI proxy protocol handler via Action/ScriptAlias/etc for some overview.
For Apache 2.4.10+/mod-proxy-fcgi configs you might be able to use something like:
AddHandler "proxy:unix:/var/run/php-fpm-usr123.sock|fcgi://localhost" .php
Or SetHandler
with name mapping from your .htaccess
. But again, consulting your hoster on the concrete FPM socket is unavoidable. There's no generic answer to this on modern PHP-FPM setups.
-
I tried to add this but there is no fpm sock file in that path so I am facing an error. I added multiple PHP and applied php80 for a particular folder but that's not working. globally ma has PHP 7.0 but for that application file, I configured 8.0. but the application loaded with 7.0 only. May 13, 2022 at 17:24
-
Gotta check your
/etc/php/***/fpm/pool.d/www.conf
(or related configs) for thelisten=
directive, to figure out if there's a socket path, or a plain old port listener.– marioMay 14, 2022 at 16:40
To switch to PHP 4.4:
AddHandler application/x-httpd-php4 .php .php4 .php3
To switch to PHP 5.0:
AddHandler application/x-httpd-php5 .php .php5 .php4 .php3
To switch to PHP 5.1:
AddHandler application/x-httpd-php51 .php .php5 .php4 .php3
To switch to PHP 5.2:
AddHandler application/x-httpd-php52 .php .php5 .php4 .php3
To switch to PHP 5.3:
AddHandler application/x-httpd-php53 .php .php5 .php4 .php3
To switch to PHP 5.4:
AddHandler application/x-httpd-php54 .php .php5 .php4 .php3
To switch to PHP 5.5:
AddHandler application/x-httpd-php55 .php .php5 .php4 .php3
To switch to the secure PHP 5.2 with Suhosin patch:
AddHandler application/x-httpd-php52s .php .php5 .php4 .php3
Try this to switch to php4:
AddHandler application/x-httpd-php4 .php
Upd. Looks like I didn't understand your question correctly. This will not help if you have only php 4 on your server.
This worked for me
PHP 7.2
AddHandler application/x-httpd-ea-php72 .php
PHP 7.3
AddHandler application/x-httpd-ea-php73 .php
-
-
1You need to create a .htaccess file in the root folder of your website usually the same folder of your index page May 31, 2022 at 13:55
An addition to the current marked answer:
Place the addhandler inside the following scope, like so:
<IfModule mod_rewrite.c>
AddHandler application/x-httpd-php71 .php
RewriteEngine On
....
</IfModule>
for php8 code generated by Cpanel:
<IfModule mime_module>
AddHandler application/x-httpd-ea-php80 .php .php8 .phtml
</IfModule>
required PHP version should be installed
Go to File Manager on your CPanel >>> Public html >>> find the .htaccess file >>> right click on the on it >>>> click edit.see picture
Type the number of the version you want to change to. i.e - 73, 70 or 71.
Hope this helps. After that, save changes.
For CPanel users (as of May 2022, selecting PHP v8.1), use Software -> "MultiPHP Manager" modifies PHP versions per subdomain. it adds this to the subdomain's directory's .htaccess file:
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php81” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php81 .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
If you don't see the PHP version you want in the select list, then install it via WHM -> Software -> "EasyApache".
Just my two cents here as this question is old, but I found myself needing an answer for a legacy site that supports PHP 5.6 at best.
Site is on Media Temple (which is now GoDaddy). I set the PHP version to 5.6 in cPanel but it wasn't taking on one of my sites. None of the above answers worked for me, but if you are running cPanel, adding this to the a site's individual .htaccess file seems to do the trick:
<IfModule mime_module>
AddHandler application/x-httpd-ea-php56___lsphp .php .php5 .phtml
</IfModule>
If you're on cPanel now, chances are you are using Easy Apache v3 or 4, hence the "ea" part of the handler. This part I'm not sure about:
___lsphp
Any other combination of handlers from the above answers would just force a download on any page.
BTW, MultiPHP Manager isn't an option on my cPanel. I would guess this would add it for you per directory / site.
Here's where I pulled this from: https://www.gonlinesites.com/web-hosting-tips/how-to-add-handlers-to-change-php-version-in-cpanel-setup-php-version/
You can't change PHP version by .htaccess.
you need to get your server updated, for PHP 5.3 or you can find another host, which serves PHP 5.3 on shared hosting.
-
ok, is there is any alter way to do it (with out upgrading or changing host server) ??– jeevaSep 24, 2012 at 8:23
-
Does your application use any feature, that is very specific to PHP 5.3?? If not, running your application on the available host, won't be an issues, i guess. if it is giving errors, then you have to get your host changed.– s_s_Sep 24, 2012 at 8:25
-
-
-