/    Sign up×
Community /Pin to ProfileBookmark

help editing apache config file (httpd.conf) using php script???

Hi,

i want to edit httpd.conf using php script
open it
edit it
close it

i am trying to edit httpd.conf but it says that i dont have permission to edit this file
then i apply chmod() on it but no success. it says that file cannot be chmod()

what i m trying to do is to create VirtualHosts using php script

plz anybody help me
i’ll be thankfull

regards

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@bokehOct 17.2007 — This is a very stupid idea. The PHP module should never be able to the alter configuration settings of the server on which it is running.
Copy linkTweet thisAlerts:
@haroon373authorOct 17.2007 — This is a very stupid idea. The PHP module should never be able to the alter configuration settings of the server on which it is running.[/QUOTE]

i am the owner of the server

i want to create 1000 domains at time

one by one will be a lengthy task

so i suppose to do this
Copy linkTweet thisAlerts:
@MrCoderOct 17.2007 — Include files in to your httpd.conf file that you have created using php.

Great care should be taken when working on something like this thou.

Please take on board Bokeh's warning.

Lots of packages, mainly back end website hosting software, will allow the server to reconfigure vhost's. It is something that could be dangerous it you allowed any of your scripts to be executed by visitors to your site.
Copy linkTweet thisAlerts:
@bokehOct 17.2007 — i am the owner of the server

i want to create 1000 domains at time

one by one will be a lengthy task

so i suppose to do this[/QUOTE]
Ok, first every time you change the config file you need to restart the server for the changes to take effect that certainly would not be possible from your script.

Second, since the webserver runs as "[I]nobody[/I]", if it could edit the config file, so could any other process running on the same machine, (maybe external ones too).

Third, having 1000's of v-hosts is not a very clever idea as far as resources, descriptors, etc are concerned and just to load the server config will consume several hundred megabytes of RAM and take forever.

I recommend a different approach that neither requires modification of the config file nor does it call for a server restart for the changes to take effect. The following code would be the first (and maybe the only) virtual host in your httpd.conf file:[CODE]<VirtualHost *:80>
ServerName default
<IfModule mod_rewrite.c>
RewriteEngine on
# grab the hostname, ignore the www
RewriteCond %{HTTP_HOST} ^(www.)?(.+)$ [NC]
RewriteRule !^/*(icons|cgi-bin)(/?|/.+)$
/root/apache2/htdocs/%2/public%{REQUEST_URI} [L,NC]
</IfModule>
DocumentRoot /root/apache2/htdocs
php_admin_value open_basedir /root/apache2/htdocs;/root/php/temp
php_admin_value upload_tmp_dir /root/php/temp
php_admin_value auto_prepend_file /root/apache2/htdocs/php-prepend.php
</VirtualHost>[/CODE]

This points "[I]http://www.domain.com/subdirectory/file.php[/I]" to "[I]/root/apache2/htdocs/domain.com/public/subdirectory/file.php[/I]".

There is a small issue [I]document root[/I] being out of sync with the domain document root and this is corrected with a prepended file placed at "[I]/root/apache2/htdocs/php-prepend.php[/I]". The contents of that file would be:[code=php]<?php

$_SERVER['DOCUMENT_ROOT'] = substr($_SERVER['SCRIPT_FILENAME'], 0, strlen($_SERVER['SCRIPT_FILENAME'])-strlen($_SERVER['PHP_SELF']));

?>[/code]
Ok, now you've done that all you need to do (on the webserver front) to add a new domain is add a directory tree for each domain inside your htdocs directory.
Copy linkTweet thisAlerts:
@MrCoderOct 17.2007 — Very nice bokeh!

Would that kind of catch all domain system need declaring after the other real domains in the vhost file?

Is there any kind of security hole when using something like this?
Copy linkTweet thisAlerts:
@bokehOct 17.2007 — Very nice bokeh!

Would that kind of catch all domain system need declaring after the other real domains in the vhost file?[/QUOTE]
No. The default (name based) virtual host is always the first one. If the host name is not mentioned in any of the virtual hosts the request is handled by the first one.
Is there any kind of security hole when using something like this?[/QUOTE]The biggest problem is that it is the directory structure is traversable back to wherever your open base directory boundary is (if you bother with one). This is because it is not possible to make the boundary dynamic from the vhost (except if you do a mod to the PHP source code) meaning the is one boundary is used by all domains. The open base directory restriction is a band-aid measure anyway and ideally this should be handled by your *nix permissions. On a dedicated server though none of that is of much importance because there aren't other users that might try to access each others files.
Copy linkTweet thisAlerts:
@MrCoderOct 17.2007 — A perfect solution to the problem!
Copy linkTweet thisAlerts:
@NightShift58Oct 18.2007 — i am the owner of the server

i want to create 1000 domains at time

one by one will be a lengthy task

so i suppose to do this[/QUOTE]

Get WebMin. It has a [b]VirtualMin[/b] module which has a batch option to create your 1000 domains, done by importing a file. The basic application is free.

All this hokey-pokey with the config files is a disaster in waiting...
Copy linkTweet thisAlerts:
@haroon373authorOct 18.2007 — Ok, first every time you change the config file you need to restart the server for the changes to take effect that certainly would not be possible from your script.
[/QUOTE]

[B]THNX ALOT

SO NICE OF YOU[/B]
×

Success!

Help @haroon373 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 11.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @bahaedd,
tipped: article
amount: 1000 SATS,

tipper: @Balmasexy,
tipped: article
amount: 1000 SATS,

tipper: @mbsaad,
tipped: article
amount: 1000 SATS,
)...