rayan khaled

Registered
Jul 9, 2020
1
0
1
Amman
cPanel Access Level
Website Owner
I am running cpanel and EasyApache 4 and know how to change the version of PHP per site, but what I really need to do is to be able to run PHP7 in a sub-folder . For example, the root site runs PHP 5.6 with vbulletin , but I would like /sub-folder to run PHP7. Does anyone know a way to do that?

subfolder contain .htaccess with

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php70” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php70 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

but when i test the php version in subfolder it keeps telling me it is PHP 5.6
 

cPanelLauren

Product Owner
Staff member
Nov 14, 2017
13,296
1,271
313
Houston
This should be as easy as placing the appropriate .htaccess file in the folder SOLVED - PHP7 Per Directory? this goes over basically the same thing you did. How are you testing the PHP version?
 

bear

Well-Known Member
Sep 24, 2002
136
4
168
cPanel Access Level
Root Administrator
I'm finding this issue as well. If the server default is still php 5.6 (i know, working on it), and a single site is set to use PHP7 via the PHP selector (which generates an .htaccess entry in the doc root), then any other folders within the doc tree for that account won't honor other .htaccess in other folders; not lower nor greater versions of php.
Example:
public_html
--.htaccess: php 7.2
---- new folder
------ .htaccess: php 5.6
PHPinfo in either folder says it's on 7.2

The only way to get it to work is if the site uses the system default and there's no .htaccess directive in the doc root.
Is there no way to have the root dir use a "forced" php version and other folders within the same tree use some other "forced" lower version? This is a non-permanent fix while working on removing the scripts that require the old one while the other folder has the software that won't run on the old one...
 

bear

Well-Known Member
Sep 24, 2002
136
4
168
cPanel Access Level
Root Administrator
I guess I didn't explain well.
If the server default is used, and not telling Cpanel to use something else, there is no htaccess entry in root, and other folders will see older/lower versions fine when added manually using the same CP generated code.
As soon as I use Cpanel to change the PHP version, which adds info to the doc root htaccess in public_html, any manually added htaccess rules to folders below it like "public_html>new_folder" will not see any PHP version but the one CP added in the root. This was checked not only using phpinfo but by adding a quick script that would fail using PHP5.
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
6,896
910
313
cPanel Access Level
Root Administrator
To test this, I set up one domain using the default PHP version on the server. I then went into cPanel for the user, and changed the PHP version through MultiPHP Manger.

I then created a subdomain inside public_html, and then used MultiPHP Manager, again though cPanel as the user, to change the PHP version to something different. All of that worked how I would expect and I didn't see it inherit the PHP values from the main .htaccess.

It might be a good idea to submit a ticket to our team since it sounds like this could be an issue specific to your environment. If you do create a ticket, please post the number here so I can follow along and keep this thread updated.
 

bear

Well-Known Member
Sep 24, 2002
136
4
168
cPanel Access Level
Root Administrator
I didn't create a subdomain, so am adding this manually to the directory. If you access the subdomain via the main site: "domain.tld/sub", does it still work and see whatever version you'd set?