Сменить версию php htaccess

how to change php version in htaccess in server

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?

11 Answers 11

AddHandler application/x-httpd-php4 .php 
AddHandler application/x-httpd-php5 .php 
AddHandler application/x-httpd-php51 .php 
AddHandler application/x-httpd-php52 .php 
AddHandler application/x-httpd-php53 .php 
AddHandler application/x-httpd-php54 .php 
AddHandler application/x-httpd-php55 .php 
AddHandler application/x-httpd-php56 .php 
AddHandler application/x-httpd-php7 .php 
AddHandler application/x-httpd-php71 .php 

when 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?

AddHandler application/x-httpd-php7 .php did not work for me, but AddHandler application/x-httpd-php70 .php did the job!

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.

Читайте также:  Contacts

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?

AddHandler application/x-httpd-php4 .php .php4 .php3

AddHandler application/x-httpd-php5 .php .php5 .php4 .php3

AddHandler application/x-httpd-php51 .php .php5 .php4 .php3

AddHandler application/x-httpd-php52 .php .php5 .php4 .php3

AddHandler application/x-httpd-php53 .php .php5 .php4 .php3

AddHandler application/x-httpd-php54 .php .php5 .php4 .php3

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

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.

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.

Источник

Изменение версии PHP

По умолчанию на всех серверах для новых сайтов используется версия PHP 7.4. Для изменения версии необходимо произвести некоторые изменения.

Чтобы изменить версию PHP для отдельного сайта, нужно вносить изменения в файл .htaccess, который находится в корневом каталоге. Если версию меняете для всех сайтов, можете создать файл .htaccess в корне аккаунта и прописать строку в него.

При отсутствии файла .htaccess, его необходимо создать и заполнить нужными строками.

Как обновить версию php

Версия 5.2
Добавьте в файл .htaccess: AddHandler application/x-httpd-php-5.2 .php

Версия 5.3
Добавьте в файл .htaccess: AddHandler application/x-httpd-php-5.3 .php

Версия 5.4
Добавьте в файл .htaccess: AddHandler application/x-httpd-php-5.4 .php

Версия 5.5
Добавьте в файл .htaccess: AddHandler application/x-httpd-php-5.5 .php

Версия 5.6
Добавьте в файл .htaccess: AddHandler application/x-httpd-php-5.6 .php

Версия 5.6 (для Битрикс в UTF-8)
Добавьте в файл .htaccess: AddHandler application/x-bitrix-php-5.6 .php

Версия 7.0
Добавьте в файл .htaccess: AddHandler application/x-httpd-php-7.0 .php

Версия 7.0 (для Битрикс в UTF-8)
Добавьте в файл .htaccess: AddHandler application/x-bitrix-php-7.0 .php

Версия 7.1
Добавьте в файл .htaccess: AddHandler application/x-httpd-php-7.1 .php

Версия 7.1 (для Битрикс в UTF-8)
Добавьте в файл .htaccess: AddHandler application/x-bitrix-php-7.1 .php

Версия 7.2
Добавьте в файл .htaccess: AddHandler application/x-httpd-php-7.2 .php

Версия 7.3
Добавьте в файл .htaccess: AddHandler application/x-httpd-php-7.3 .php

Версия 7.4
Добавьте в файл .htaccess: AddHandler application/x-httpd-php-7.4 .php

Версия 7.4 (для Битрикс в UTF-8)
Добавьте в файл .htaccess: AddHandler application/x-bitrix-php-7.4 .php

Версия 8.0
Добавьте в файл .htaccess: AddHandler application/x-httpd-php-8.0 .php

Версия 8.1
Добавьте в файл .htaccess: AddHandler application/x-httpd-php-8.1 .php

Версия 8.2
Добавьте в файл .htaccess: AddHandler application/x-httpd-php-8.2 .php

Изменение файла .htaccess

Где найти файл .htaccess?

Файл .htaccess располагается в корневом каталоге сайта. Узнать его можно с помощью нашего сервиса. Если файла .htaccess в этом каталоге нет, создайте его.

Как отредактировать файл .htaccess?

За пример возьмём файл .htaccess сайта, работающего на WordPress. Так как это текстовый файл — редактируем его в текстовом редакторе.

Файл .htaccess

Чтобы поменять версию PHP на 7.4, добавим AddHandler application/x-httpd-php-7.4 .php первой или последней отдельной строкой в файл .htaccess.

Файл .htaccess с PHP 7.4

Обратите внимание, что в панелях управления хостинга отображается системная версия PHP сервера. Проверять версию PHP на сайте нужно с помощью функции phpinfo() .

Источник

Change PHP version on server using either .htaccess or php.ini

I added this in my htaccess but when go to my homepage, it just downloaded my index.php file :/ what’s the reason behind it?

This is a provider-specific directive. It may be supported by some backwards web hosts which still support PHP 5.2 (which has, by this point, been end-of-life for roughly eight years), but it is not generally applicable.

I take it you want to process e.g. .php3 files with php 3.x.

You can’t switch between php versions like this, but you might be able to do it by setting up a proxy server that distributes the query to one of several servers (one for each PHP version).

There might also be some apache hack that works by calling the cgi-bin mode php in FastCGI mode. See the linked answer for this.

According to https://www.first2host.co.uk/f/change-php-version-php-ini/, adding the following line to your php.ini file will change you to PHP version 5.2:

AddHandler application/x-httpd-php52 .php 

It only works if your host is first2host though, I reckon.

This is a provider-specific directive, and will not work elsewhere. It’s also effectively identical to the other answers already present on this question. (Unrelatedly, it’s terrifying that a web host is still supplying a PHP version which has been end-of-life for nearly eight years.)

This question is in a collective: a subcommunity defined by tags with relevant content and experts.

Источник

How to Change the PHP Version of Your WordPress Site Using .htaccess

  • php

At some point, you might need to change the PHP version of your WordPress website, especially if you’re running on an old version.

Cloudways

So, in this tutorial, I’ll show you how to do that using .htaccess, which is a configuration file for servers that run on the Apache software.

Change the PHP version of your WordPress site using .htaccess

Before proceeding, back up your .htaccess file or your entire website, just to be extra safe!

Cloudways

Also, if you’re doing this to permanently upgrade the PHP version of your WordPress website, find out if your web host, theme, and plugins support a higher version of PHP, such as 7+.

Step 1 – Access your site’s files

Cloudways

The .htaccess file should normally be in your WordPress website’s root folder – public_html .

.htaccess via cPanel

Step 2 – Edit the .htaccess file

Open the .htaccess file for editing.

Cloudways

If you’re in cPanel, right-click on it and select Edit or Code Edit.

edit .htaccess in cpanel

Editing .htaccess in cPanel

Step 3 – Add the code and save the file

I’ll give you several handlers to add, but you should stick to PHP 7+ (7.2 currently recommended) because it’s faster and more secure!

Add one of the below handlers right above the #BEGIN WordPress line in your .htaccess file.

change php version wordpress .htaccess

AddHandler application/x-httpd-php73 .php

AddHandler application/x-httpd-php72 .php

AddHandler application/x-httpd-php71 .php

AddHandler application/x-httpd-php70 .php

AddHandler application/x-httpd-php56 .php

AddHandler application/x-httpd-php55 .php

Related posts:

That’s a wrap

Hope you found the tutorial useful and managed to change the PHP version of your WordPress website using .htaccess!

Don’t forget to share the post to help out others!

You can quickly subscribe to my newsletter by using this link.

If you have any questions or thoughts, drop a comment or send a message via contact or Facebook page.

Источник

Change PHP Version Using .htaccess File

Change PHP Version Using .htaccess File

  1. Use the .htaccess Files to Change Version of PHP
  2. Use the phpinfo() to Check Our Version in PHP

We will look at how to change the PHP version using .htaccess files.

Use the .htaccess Files to Change Version of PHP

We will add the line below to our .htaccess file to specify the php version we want to use, in this case, php 7.3.

php  # Use PHP(7) as default  SetHandler application/x-lsphp73  ?> 
   SetHandler application/x-lsphp73  

Use the phpinfo() to Check Our Version in PHP

Use the phpinfo() to Check Our Version in PHP

Related Article — PHP Version

Copyright © 2023. All right reserved

Источник

Оцените статью