Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

It's possible in apache's configuration httpd.conf to set up .htaccess so that it is named something different, using the AccessFileName .htaccess directive.

Is there any way to set up PHP so it looks for the php.ini file under a different name? (I'm not trying to symlink - thanks)

Update

For those of you who are curious about why I would want to do such a thing:

I would be looking at changing the name of the file on the development machine, not the production machine. I've already set up a different .htaccess name on my local machine and it's been great. I can rsync between remote and local and keep different copies of both files on each machine, and yet only the proper file has effect. I can then diff the two files locally, which is nice.

These files both have more to do with the web sever configuration, and less to do with the web applications. Perhaps it is important to set up different include paths, or other such variables which are server specific. That sort of thing. Ideally your development server is a duplicate of the production server, but if you work on several different remote servers, especially with shared hosting, this is the kind of thing which is really convenient.

So basically having a different config file name for these local files and the remote files just allows keeping both copies side by side.

share|improve this question
4  
... why? What's wrong with php.ini? –  ceejayoz Oct 12 '11 at 1:16
    
ditto on @ceejayoz: What reason could you possibly have to rename this file? I can think of numerous reasons not to change this file name. –  JDS Oct 12 '11 at 2:00
1  
I hope you're not thinking that doing such things will aid security. The person why could directly access those files can also look at the Apache config to find out what names you're using. –  John Gardeniers Oct 12 '11 at 2:02
    
It'll also confuse the hell out of someone else having to fix a broken server. –  ceejayoz Oct 12 '11 at 2:54
    
I've updated the question to give you some insight. –  cwd Oct 12 '11 at 5:52

4 Answers 4

up vote 2 down vote accepted

It looks like the answer is "maybe"

PHP CLI has an arg, "-c", that lets you specify the path in which to search for the php.ini file, or the full path to the file itself.

PHP run as an Apache module has only directives to specify the path in which to search for the file, not the name of the file itself.

Finally, using a symlink as suggested will only work for the CLI version of PHP. A symlink to a directory in which to search for php.ini may work, but a symlink to the file will only work if the name of the symlink is "php.ini" which is not quite what your question asked to accomplish.

References

http://www.php.net/manual/en/configuration.file.php

The question from me is, "Why?" Why would you want to do this? I have a few instances of configuring services where at the time, I changed the name the configuration file to something related to the company or group or product or whatever that I was supporting with the service. i.e., Something different from the default. In pretty much all of those cases I've learned the hard way that doing so was a bad idea, from the point of view of maintainability, manageability, supportability, handoff to colleagues, etc.

share|improve this answer

You could setup a symbolic link

share|improve this answer
    
Definitely the right way to solve the problem (you can sync the /usr/local/etc/live.php.ini and /usr/local/etc/test.php.ini but leave the link at /etc/php.ini alone. B syncing files in /etc would be a bad idea. –  symcbean Oct 12 '11 at 11:17

I think you are searching for ---exclude=php.ini --exclude=.htaccess switches of rsync. If you sync with script, add these two switches to it and rsync willn't copy these files anymore.

Anyway, I do not think renaming php.ini (even if it is possible) is a good idea. Do not do it.

share|improve this answer

The name .htaccess can be changed in httpd.conf or apache2.conf. And for php.ini, that may be buried in some apache include or in some c source itself. Would it be enough to symlink it?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.