Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.3: Where to find and edit the php.ini file UNIX
Upon doing a clean install of Panther and reconfiguring Apache via the /etc -> http -> httpd.conf file to enable PHP, I noticed that some settings have changed. In paticular, register_globals is off by default now.

After some searching on the net, I couldn't find anything that told me where to look for php.ini to change this setting. However, when I ran the phpinfo() command, in the output it shows that the php.ini is loaded from /etc, and not /usr/local/, like the sites I found describing the same problem.

So to properly set up your PHP environment, you can copy another php.ini to /etc or copy the /etc/php.ini.default to /etc/php.ini and edit the file accordingly. After you're done, restart Apache to have the settings take effect.

[robg adds: This one bit me, too -- PHP recommends register_globals be set to off, so Apple did the right thing by setting it that way. However, many scripts, such as Geeklog!, require register_globals to be on. If it's off, Geeklog appears to mostly work, but it stops loading pages after the header. It took me a bit of digging to figure out the php.ini location, so hopefully this hint will help some others in the same boat.]
    •    
  • Currently 3.14 / 5
  You rated: 4 / 5 (7 votes cast)
 
[70,992 views]  

10.3: Where to find and edit the php.ini file | 23 comments | Create New Account
Click here to return to the '10.3: Where to find and edit the php.ini file' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: Where to find and edit the php.ini file
Authored by: TvE on Nov 12, '03 11:37:52AM

Create a phpfile containing

<?php
echo info() ;
?>

and it'll display lots of PHP related info including the location of the php.ini file (or to be more correct - where PHP will look for one...)



[ Reply to This | # ]
10.3: Where to find and edit the php.ini file
Authored by: JoeGrind on Nov 12, '03 12:16:22PM
You sure you didn't mean this?

<?php phpinfo() ?>
I've used "phpinfo()" so I was curious what else "info()" offered but all I get is an error reporting "undefined function".

[ Reply to This | # ]
10.3: Where to find and edit the php.ini file
Authored by: wallyfoo on Nov 13, '03 12:25:50AM

You dropped the semicolon.

<? phpinfo(); ?>

---
_____________________________
My other sig is really witty.



[ Reply to This | # ]
10.3: Where to find and edit the php.ini file
Authored by: TvE on Nov 13, '03 11:46:33AM

Damn - I was to quick on the keyboard - YES I meant

<?php
echo phpinfo() ;
?>

Sorry for the confusion!



[ Reply to This | # ]
10.3: Where to find and edit the php.ini file
Authored by: TvE on Nov 13, '03 11:47:52AM

I did it again - there is no need to use "echo"...



[ Reply to This | # ]
.htaccess is another option
Authored by: sierratarn on Nov 12, '03 11:46:38AM

Another option is to put commands in .htaccess files. You have to ensure they are activated for the server but it does make it easy to seperate areas of your server. For example to run an old program where Register Globals must be on while developing your killer app in a seperate area with Register Globals turned off.



[ Reply to This | # ]
.htaccess is another option
Authored by: cteselle on Nov 12, '03 12:56:20PM
in the .htaccess file the entry would look like this:

php_flag register_globals on

[ Reply to This | # ]

There is yet a better way
Authored by: wallyfoo on Nov 13, '03 12:23:06AM

Better yet, if you have access to edit the php.ini file, you probably have access to edit your site's .conf file.

Given that, you should probably set a per-directory access option for your virtual host because
1. Virtual Host options are faster than parsing .htaccess files (read the Apache docs for why this is)
2. You'll need to check your .conf file anyway to make sure it has its AllowOverride option set to recognize .htaccess files at all.

So set the directory option.

For the sake of illustration, say you have a PHP-based forum installed in your document root in a folder called "forum" and it requires PHP register_globals on. Inside your Virtual Host you'd add this block of text:

<Directory "::absolute path to your document root::/forum">
php_flag register_globals on
</Directory>

Simple. Save the .conf file. sudo apachectl graceful. You're golden. Every PHP script inside that directory (and recursively within, I believe) will now recognize register_globals on.

Don't believe me? save

<? phpinfo(); ?>

to a file named, say, phpinfo.php within the forum directory and look on the page for register_globals.

Note, that syntax above for php_flag will not work on Apache 2. But if you're running Apache 2 on OS X, then you probably already know enough about Apache administration to not need this hint in the first place.

---
_____________________________
My other sig is really witty.



[ Reply to This | # ]
There is yet a better way
Authored by: WAW401 on Nov 13, '03 12:01:39PM

I agree that apache .conf files are the easiest way to do this. Also, the php configuration directives are not restricted to Directory containers, they can be used in a VirtualHost container. This is a great way to change settings for one php driven website without affecting all of your php driven websites.



[ Reply to This | # ]
There is yet a better way
Authored by: Bytesmiths on Dec 16, '03 10:25:57PM

In general, I agree with wallyfoo, but you might want to stick it in .htaccess if it is a short-term solution, while hunting down and clobbering your globals. That way, you can quickly turn it off an on for debugging, but you have to restart Apache every time you change http.conf.

---
: Jan Steinman, Bytesmiths



[ Reply to This | # ]
What version of PHP does Panther come with?
Authored by: jecwobble on Nov 12, '03 11:47:12AM

Does it include the CLI version?



[ Reply to This | # ]
What version of PHP does Panther come with?
Authored by: fds on Nov 12, '03 12:26:39PM

4.3.2, and yes it does.



[ Reply to This | # ]
Security Note...
Authored by: natecook on Nov 12, '03 01:51:22PM
The reason register globals is off by default is that turning it on opens up a potential security issue in PHP pages: anything in the querystring ends up as part of the default namespace. If you're writing PHP yourself, this means you should either code with register globals off and use the global $_GET[] &co (which I've found quite handy) or always declare and initialize your variables before using them. Good idea anyway, but there you go.

[ Reply to This | # ]
10.3: Where to find and edit the php.ini file
Authored by: vorovsky on Nov 12, '03 02:41:42PM

Its always a good idea to keep register_globals turned off if possible. Just as in C/C++ programming, making every variable a global variable just for the sake of being easy is poor programming practice and can lead to some very serious security flaws.

Also, anyone familiar with *nix should know that to locate any file, just use:

find / | grep "php.ini"

and it'll search through the drive and give you a list of results.



[ Reply to This | # ]
10.3: Where to find and edit the php.ini file
Authored by: fds on Nov 12, '03 05:53:28PM
Note that in my experience Panther does not install a php.ini anywhere. PHP is just configured to look for it in /etc, but no customized or sample php.ini ends up there on its own; so PHP as it ships with Panther simply gets initialized with all the default options.

As such searching for the non-existant file isn't particularly helpful.

Since the CLI version gets installed, the easiest way is probably to extract the path from the phpini output, as it's already noted above:


php -i | grep php.ini
Theoretically of course it's perfectly possible to have the Apache SAPI copy of the PHP interpreter and the CLI version point to different php.ini paths, so it's not a bad idea checking the phpinfo() output via a web browser.

[ Reply to This | # ]
Sample file was installed...
Authored by: robg on Nov 13, '03 10:11:26AM

On my clean install of 10.3, I wound up with php.ini.default in /etc, and I know I didn't put it there!

-rob.



[ Reply to This | # ]
Sample file was installed...
Authored by: TvE on Nov 13, '03 11:52:20AM

It's probably because a lot of people asked "where IS that php.ini" in previous versions of X" and it took them a long time to realise that they had to create (copy) it themselves...



[ Reply to This | # ]
10.3: Where to find and edit the php.ini file
Authored by: mark242 on Nov 12, '03 05:54:15PM

Horribly inefficient.

Run this command from the terminal:

sudo find / -name php.ini -print

That will only spit out files called "php.ini". Your grep will spit out files that contain php.ini in them.



[ Reply to This | # ]
10.3: Where to find and edit the php.ini file
Authored by: nayr on Nov 13, '03 12:17:32AM

Horribly inefficient.

locate php.ini



[ Reply to This | # ]
10.3: Where to find and edit the php.ini file
Authored by: Anonymous on Nov 25, '03 12:10:37AM
Not being a professional programmer, how do I go about correcting those scripts that use globals. I have a few that stopped working with the Panther update so I turned register_globals on, but if they can be repaired I would rather do that. Even simple relocates such as,
<a href="file.php?var=something">test</a>
no longer worked. Any suggestions? Cheers, ptervin...always in a fog

[ Reply to This | # ]
10.3: Where to find and edit the php.ini file
Authored by: Bytesmiths on Dec 16, '03 10:22:37PM
Replace every global with an access to the $_GET array. For example:
$someGlobalVariable

becomes
$_GET['someGlobalVariable']

---
: Jan Steinman, Bytesmiths

[ Reply to This | # ]

Restarting Apache via Terminal or System Preferences?
Authored by: robertm on Oct 31, '04 04:52:22PM

Thanks for the tip. After making a php.ini file and copying it to /etc, I tried stopping and restarting Apache using apachectl stop and apachectl start (normally that has worked fine when I've made changes to httpd.conf)

But when I reloaded my phpinfo() file, it showed register_globals still were off.

So I stopped and restarted Personal Web Sharing in System Preferences. Checking phpinfo() again, that worked. I am probably missing something basic here, but I thought apachectl stop/start were the same thing.

Isn't there a Terminal command that will cause php to reload after making changes to php.ini?



[ Reply to This | # ]
10.3: Where to find and edit the php.ini file
Authored by: josh.legogeek on May 16, '10 07:48:05AM

/etc is an alias to /private/etc



[ Reply to This | # ]