I am coding in PHP on Apache, and I have access to two main areas on the Unix server. I have a personal directory and I have a project directory. I noticed that in the project directory there is a extension/module that I have access to automatically which I don't have in my personal directory (I can see it listed in phpinfo()).
So I'm guessing that the server admins set it up this way because most users wouldn't require this extension in their personal area, but I do.
I have looked through several base level .htaccess files and conf files, but can't seem to find the point that this extension is being initialized for the project area. Is there a way via PHP for me to list not only all the loaded extensions but at what point they are loaded?
I can think of 2 ways for loading extensions
through php.ini with the extension/zend_extension directories. Note that this would not work with user.ini files (per directory configuration)
through the combined usage of auto_prepend_file INI setting and the dl() function. The latter can load extensions dynamically. And auto_prepend can be used to make the PHP interpreter run any code before yours runs. But dl() has been deprecated in PHP 5.3 and will be completely gone in PHP6.
And if all else fails - why don't you ask your server admins?
Is there a way via PHP for me to list
not only all the loaded extensions but
at what point they are loaded?
No. Ask server admin.
Related
Working with WordPress, I often come across the same issue where hosting companies set the initial PHP settings for things like upload_max_filesize and max_execution_time to very low values. This becomes an issue when trying to import large demo content or migrate data from another server. I'm trying to find a way around it using only a PHP script (no FTP access, can't recompile PHP etc...). How can this be accomplished?
Here are a few things to consider:
Using ini_set() only works for certain directive, which makes it useless in my case.
Creating a php.ini or php5.ini file in the root of WordPress only works if PHP is set to scan this directory for additional ini files, which is rarely the case.
Modifying the .htaccess file is an excellent way to achieve this, however, if PHP is run in "CGI mode" and not as an Apache module, this won't work.
Is there a solution that can work regardless of the host's settings? Is there a way to force PHP to scan an additional directory for php.ini files?
I am trying to set the include_path specifically for a given script in a given configuration.
Per Directory Values would be ideally suited for the task, so I am trying this:
[HKEY_LOCAL_MACHINE\SOFTWARE\PHP\Per Directory Values\c\phpDevScripts]
"include_path"="c:\\path\\to\\dev\\lib"
It doesn’t seem to work for CLI scripts but the docs say nothing about this.
Quoted from the "User Contributed Notes":
Being able to put php directives in httpd.conf and have them work on a per-directory or per-vitual host basis is just great. Now there's
another aspect which might be worth being aware of:
A php.ini directive put into your apache conf file applies to php when
it runs as an apache module (i.e. in a web page), but NOT when it runs
as CLI (command-line interface).
Such feature that might be unwanted by an unhappy few, but I guess
most will find it useful. As far as I'm concerned, I'm really happy
that I can use open_basedir in my httpd.conf file, and it restricts
the access of web users and sub-admins of my domain, but it does NOT
restrict my own command-line php scripts..
I've been developing a PHP application using the Zend framework for awhile on a Linux-based hosting provider, and it's gone along more or less swimmingly.
The time has come to be able to develop locally on my Mac, so I configured Apache to run PHP, grabbed the source code, and symlinked /Library/WebServer/Documents to the public/ folder in my Zend web app.
That was fine. The controllers were executing and loading the correct scripts, which seemed to parse and render correctly. Except, I wasn't able to connect to my local MySQL database. I realized that I hadn't copied /etc/php.ini.default to /etc/php.ini, so I went ahead and did that. I then updated this line:
pdo_mysql.default_socket=/tmp/mysql.sock
and restarted Apache. Now, suddenly, none of the PHP executes. Instead, the raw PHP is sent back to the browser.
The effect is more or less the same as if I was trying to load a .php file directly with an Apache instance that didn't recognize the .php file extension. Based on what I've experienced, I'm guessing that maybe somewhere in php.ini there is a setting that is causing this to happen (when I rename php.ini and restart Apache, the scripts once again parse and render correctly, but again I can't hit the database) but I'm not sure where to look. Does anyone have any thoughts?
In case anyone is reading this, here's the answer that I finally discovered:
short_open_tag = On
The above needs to be set in php.ini, particularly because all of my controllers, models, helpers, etc were using short tags (e.g. ), as is common with Zend applications.
I run some PHP websites on a FreeBSD server which was recently updated to PHP 5.2.17, after which exec("something") stopped working, and I was required to write exec("/full/path/something").
Since the scripts run on different machines where executables are in different places writing full paths is not acceptable.
Running passthru("set") from PHP reveals the PATH variable (for user "www") to be:
PATH=/sbin:/bin:/usr/sbin:/usr/bin
I need PATH to point to the PHP safe_mode_exec_dir directory:
PATH=/usr/phpsafe_bin
Running putenv("PATH=/usr/phpsafe_bin") in PHP resolves the problem, but I need a solution that fixes the problem on a global level for all PHP scripts running on this machine, in other words changing php.ini, Apache settings, or other system settings.
Hope someone can provide a good solution to this, maybe even an explanation why this changed in the PHP update. There seems to be no PHP documentation on how the search path for exec() and friends is determined.
It's not a pleasant solution, but it's all I could think of. Create a script file that does the change you've suggested and then use the "auto_prepend_file" in php.ini or .htaccess to include this script. Then in effect every php script that is run will have this file run before it gets executed and thus your directory is changed.
Caution: You need to be very careful using this since any errors, extra white space etc in the prepend script can break whole pages, existing features such as download scripts, or any number of unknown effects.
Read More: http://php.net/manual/en/ini.core.php
I need to install or use php on a windows 2003 server that already has php 5.2.0.0 installed due (I think) to setting up symantec backup exec. I don't want to interfere with backup exec's php.ini settings - and would rather be able to control my own configuration of php.
searching for php shows that php.exe and other php files are currently installed in
c:\program files\symantec\backup exec\
I'm almost certain that installing the current version of php 5.2.8 to c:\php would be disastrous or calamitous in some way.
There is no PHPRC entry in the server properties > environment variables and I'm pretty sure that the php.exe location is not included in the PATH variable. ...unless the actuall install location is different from the c:\program files\symantec\backup exec\ dir.
Any suggestions on how to proceed?
I'm almost certain that installing the current version of php 5.2.8 to c:\php would be disastrous or calamitous in some way.
What makes you say that :) I've run separate PHP versions on the same machine side by side and not run into bother.
AFAIK the Symantec install should not conflict with your own installation, nor should the separate php.ini files conflict with each other.
[Response to comment]
First thing to note is that I have no experience of Backup Exec or what it uses PHP for. I'm guessing it uses it for its own internal stuff and doesn't spread itself over the OS. Test this by searching for php.ini and php DLLs on the file system. I'm betting it's all quite self contained. PHP searches for the config file as noted here: PHP Site . As you note, BE hasn't set the PHPRC variable. Check it hasn't used those Registry entries either. On a different tack, has BE installed an admin site already on IIS? If so, check the IIS Web Service Extensions to make sure it hasn't already registered the PHP ISAPI dll or PHP CGI exe. IF not, I think you should be okay for your new install.
To be on the safe side, do a manual PHP install as illustrated here: PHP Site. That way, you know exactly what you have installed, and can easily remove the files again if they cause a problem. I can't imagine a problem here that would require you to reinstall BE.