PDA

View Full Version : Stop PHP executing on a (or multiple) sub-domain(s)


James Birkett
10-26-2009, 11:01 PM
Server: Fedora 7 i686 virtuozzo
cPanel 11.24.5-R38506
WHM 11.24.2 - X 3.9

I'm trying to stop PHP from parsing (executing) on sub domains so that I can offer my VIP members a free sub-domain for their portfolio's (I run a GFX-related forum).

Is this possible?

I don't want it globally disabled for obvious reasons - just for specified sub-domains.

Thanks in advance.

P.S: It's my own VPS.

RenatoMN
10-27-2009, 08:19 PM
What you mean by "PHP executing"?

vBulletin don't allow PHP code to be executed in the frontend. The [PHP] bbcode is there just for code highlighting.

James Birkett
10-27-2009, 10:39 PM
This isn't forum-related it's server-related. I posted it here because it's "Forum and Server Management" and this comes under server management.

I want to stop PHP from parsing or executing on sub-forums on my server - not my forum. I know I can globally stop PHP - but I just want to stop it on certain sub-forums.

I am aware of the BBCodes ;)

Woops.. title said sub-forums. Dammit. I've done that so many times on Google searches ;(.

Sorry guys.

TurkeySub
10-28-2009, 03:01 PM
This isn't forum-related it's server-related. I posted it here because it's "Forum and Server Management" and this comes under server management.

I want to stop PHP from parsing or executing on sub-forums on my server - not my forum. I know I can globally stop PHP - but I just want to stop it on certain sub-forums.

I am aware of the BBCodes ;)

Woops.. title said sub-forums. Dammit. I've done that so many times on Google searches ;(.

Sorry guys.

Are you asking if you setup new accounts as sub-domains off your primary domain if you can manage whether or not they have access to PHP?

Are you using a control panel or manual editing apache?

James Birkett
10-28-2009, 04:32 PM
I have a VIP feature which is the ability to have a sub-domain set up for their own personal use - as I explained in the first post.

Of course, I don't want that to be abused in any way so I would like to disable PHP on that sub-domain so that they cannot run PHP scripts on their sub-domain.

I am using cPanel and WHM - that is all I am using to run my server. I am hoping there's a configuration option.

snakes1100
10-28-2009, 05:19 PM
You try this in a php.ini in their public folder?
engine = Off

Then chown to root & chmod the php.ini to 000 so they cant see or access it.

James Birkett
10-28-2009, 05:25 PM
I'll try it.

I'm not familiar with chowning, got any idea what command i'd use?

Also, would this be in effect only for that sub-forum or throughout everything?

EDIT: I created a file named "php.ini" and put in it "engine = Off" and it hasn't worked.

snakes1100
10-28-2009, 08:09 PM
chown -h

chown root:root php.ini

It should only be in that users sub-domain folder
xxxx.xxxxx.xxx/username

When apache/php was compiled, was rights given to allow php.ini overwirte by users?

James Birkett
10-28-2009, 08:54 PM
The sub-domain is:
../public_html/{sub-domain} which is where I placed the php.ini.

I'm not sure if the rights were given - the installation of everything was there before I bought the server. Any way I can check?

snakes1100
10-28-2009, 11:49 PM
try a simple php flag like memory_limit and view a phpinfo file from that location and see if it raises the limit, you should have the two columns in phpinfo and the memory limit for the local side should rise, if not you will need to recompile apache/php.

James Birkett
10-29-2009, 01:08 PM
I put memory_limit = 50M into the php.ini and it didn't affect the phpinfo file.

I suppose i'll have to recompile?

bobster65
10-29-2009, 01:32 PM
I put memory_limit = 50M into the php.ini and it didn't affect the phpinfo file.

I suppose i'll have to recompile?

no, you should just have to restart apache for it to take effect..

snakes1100
10-29-2009, 01:40 PM
Bob, there is NO need to restart, if local override is allowed, it's on the fly.

bobster65
10-29-2009, 01:44 PM
Bob, there is NO need to restart, if local override is allowed, it's on the fly.

ah, gotcha.. makes perfect sense :)

snakes1100
10-29-2009, 05:11 PM
Yea, you wouldn't want to restart apache 300 times a day because ppl keep changing variables.

Angel-Wings
10-30-2009, 09:29 AM
Depending on how you use PHP - if it's the Apache module a simple:


<VirtualHost ....>
php_flag engine Off
php_admin_value engine Off
...
</VirtualHost>


Should do it. If you run it as CGI / FastCGI just remove the Handler for the specific sub-domains or directories.
Little bit :confused: first allowing this handler to be executed - if it's CGI - just to run PHP in order the PHP interpreter gets it isn't allowed to do anything - so better remove it completely that there're no CGI / FastCGI calls made anyways.

James Birkett
10-30-2009, 01:26 PM
Where do I put that Angel?
In php.ini or in htaccess? :confused:

Angel-Wings
10-30-2009, 01:29 PM
Webserver Configuration if you're using Apache. For Nginx / Lighty or other server just look how PHP is called - usually via FastCGI then - and remove the handler / caller on your virtual hosts where you don't want to have them.

RenatoMN
10-30-2009, 11:01 PM
This is usually located in /etc/apache2/httpd.conf

I'm not sure for cPanel, I do not use it for years. Using Kloxo (formerly LxAdmin) and Virtualmin.

However, if you have root access to cPanel, all config files are editable from within WHM.

snakes1100
10-31-2009, 02:15 AM
This is usually located in /etc/apache2/httpd.conf

I'm not sure for cPanel, I do not use it for years. Using Kloxo (formerly LxAdmin) and Virtualmin.

However, if you have root access to cPanel, all config files are editable from within WHM.

cpanel: /usr/local/apache/conf/httpd.conf

James Birkett
11-01-2009, 12:47 PM
Webserver Configuration if you're using Apache. For Nginx / Lighty or other server just look how PHP is called - usually via FastCGI then - and remove the handler / caller on your virtual hosts where you don't want to have them.

Can I allow that handler to only run on sub-domains to stop PHP parsing on them sub-domains? I still host a vBulletin forum on the same server - so, of course, I don't want to stop PHP altogether.

snakes1100
11-01-2009, 09:08 PM
place it in the sub-domain container <virtualhost> subdomain </virtualhost>

Angel-Wings
11-02-2009, 02:10 PM
Can I allow that handler to only run on sub-domains to stop PHP parsing on them sub-domains? I still host a vBulletin forum on the same server - so, of course, I don't want to stop PHP altogether.

Depends on how your PHP is set. If you run it via CGI or FastCGI - usually you've an Suexec Wrapper - something like:

Global HTTP Conf:


FastCgiWrapper /usr/local/sbin/suexec


And then place in your Vhosts:


<VirtualHost ....>
FastCgiServer /usr/local/example/php_vhost_1 -user domain_1 -group domain_2
...
</VirtualHost>


Using this you've PHP running under different users for each Vhost. If that line is missing, no PHP will be executed.
Just look how you can set FastCGI with an Suexec Wrapper.

If you use the Module:


<VirtualHost ...>
php_admin_flag engine off
php_admin_value open_basedir /nonexistent
</VirtualHost>


Will do it. The second one isn't required, just to be safe setting open_basedir to a non existing directory never hurts.
Or you do it vise versa and disable PHP globally by php.ini then enabling it only for the Vhosts you will need it. :)

snakes1100
11-03-2009, 06:29 PM
Depends on how your PHP is set. If you run it via CGI or FastCGI - usually you've an Suexec Wrapper - something like:


He is using a cpanel server, those instructions will not help him to put it in the needed location.

Angel-Wings
11-05-2009, 04:32 PM
He is using a cpanel server, those instructions will not help him to put it in the needed location.

Someone else might not using cpanel so these instructions might be still useful

snakes1100
11-06-2009, 01:36 AM
I didn't state they wasn't useful, i only stated that they won't work on a cpanel server, which he is using.