I need to add a php.ini in a specific folder in my server to set allow_url_fopen = true for a website. The website has its root folder an plenty of sub-folders that also have many sub-folders.
If I place the php.ini in the root of the website, it seems to only affect that folder (I've run phpconfig() there and in the subfolders.
Is it possible to make it somehow that affects all the subfolders without having to palce uno php.ini per sub-folder?
Regarding Mario's comment, I tried both php.ini and .user.ini. As he said php.ini is not recursive, but .user.ini is working recursively for me. I am also on 1and1 shared linux hosting with PHP5 as well. I just put the .user.ini in my root directory.
You could set PHP configurations options in .htaccess.
php_flag allow_url_fopen on
Related
My project directory has php.ini file on root and I want to make some changes to configuration therefore I edited php.ini file through cpanel but whenever I edit php.ini file a file .user.ini is created which has some directives already added. .user.ini file is being used by 'u' folder of my project which is on root. I tried editing .user.ini file through cpanel but changes do not reflect.
In snapshot you can see that changes done in php.ini which is on root has reflected changes but when I go inside 'u' folder of my project which is using .user.ini file the configurations are still disabled
This is the extension I want to enable:
allow_url_fopen
If someone knows how I can make changes to .user.ini file please guide. Thanks!
You should try using MultiPHP from your cPanel web interface in order to change PHP settings.
I want to load the file variables.php (that simply contains variables) at the run of any pages of my project so I can use the variables from any place.
I created a file called .user.ini (and placed it in the root folder):
; Automatically add files before PHP document.
; http://php.net/auto-prepend-file
auto_prepend_file = /Volumes/www/project_name/admin/libs/variables.php
It doesn't work. It seems that PHP doesn't read the .user.ini file.
php.ini is right configured by default:
user_ini.cache_ttl 300 300
user_ini.filename .user.ini .user.ini
Where am I wrong?
Well, the manual says it all:
Since PHP 5.3.0, PHP includes support for configuration INI files on a
per-directory basis. These files are processed only by the CGI/FastCGI
SAPI. This functionality obsoletes the PECL htscanner extension.
And:
If you are using Apache, use .htaccess files for the same effect.
... though it actually refers to the Apache module (mod_php).
If you need SAPI-independent custom settings I'm afraid you'll have to use both. You can minimise the maintenance burden if you keep those settings to the minimum (most PHP directives can be provided in PHP code itself). And you need to ensure that .htaccess settings don't crash when mod_php is not available:
<IfModule mod_php5.c>
php_value auto_prepend_file /Volumes/www/project_name/admin/libs/variables.php
</IfModule>
I think .user.ini should be located in project root folder, for example, /Volumes/www/project_name/.user.ini
In addition to the main php.ini file, PHP scans for INI files in each
directory, starting with the directory of the requested PHP file, and
working its way up to the current document root (as set in
$_SERVER['DOCUMENT_ROOT']). In case the PHP file is outside the
document root, only its directory is scanned.
.user.ini documentation
My development environment is shared with other developers of my startup and is setup on Rackspace. The php.ini file is located in /etc/ folder, and I believe this is a centralized location from where every other developer's dev environment setting is being configured from. I want to customize this php.ini file specifically for myself rather than having to do it in the /etc/ location.
Specifically I am setting up XDEBUG in my environment, some other developers don't want it, so I don't want to bug em :)
To do so, I scanned the Internet on how to override the php.ini file specifically for a directory, and found this page on stackoverflow
And following that, I simply copy pasted the php.ini file within my htdocs folder and then simply echoed out phpinfo() (I echoed this in one of my Controllers, (using Zend)). The index.php file is within the htdocs folder.
When I look # "Loaded Configuration File", it still reads
/etc/ instead of ../htdocs/
Anybody know what's up?
In general, it isn't possible to load php.ini on a per directory basis, but in some special cases (CGI/FastCGI), it is: see documentation for Per-user configuration
Since PHP 5.3.0, PHP includes support for .htaccess-style INI files on a per-directory basis. These files are processed only by the CGI/FastCGI SAPI. This functionality obsoletes the PECL htscanner extension. If you are using Apache, use .htaccess files for the same effect.
In addition to the main php.ini file, PHP scans for INI files in each directory, starting with the directory of the requested PHP file, and working its way up to the current document root (as set in $_SERVER['DOCUMENT_ROOT']). In case the PHP file is outside the document root, only its directory is scanned.
If you are hosting several independent sites on one server, you should consider FastCGI anyway, to keep them separated. With php5-fpm it's very easy to setup many pools of workers.
Note that only set a limited subset of the ini-options in the user-ini-file.
As you said you don't have control on the server, the possible work-arounds would be to:
Use ini_set() to override the changes inside your script. Not all of the configuration directives can be changed using ini_set() though.
Use an .htaccess file in your directory to override the configurations in php.ini file.
(certain parts adapted from #1438393)
Hope this helps!
I'm not sure you understood the post. The post means if you run the server and want a per domain php.ini you can run the module as a per domain so each user controls there domain php.ini however it looks like your server does not offer this so you will need to us htaccess file to overwrite the php.ini settings.
By over write this doesn't mean you can change the directory this means maybe add a module or add error reporting ect...
You can do it by using this post: How can I use xdebug to debug only one virtual host?
I have a custom php.ini file I created in my public_html directory. It works as I have checked the settings set are correct using phpinfo().
But the strange problem is the php.ini settings do not seem to apply to all sub_folders in the public_html directory?
Any ideas perhaps theres a setting needed in php.ini to apply to all subdirectories in public_html?
I found the answer myself you have to add the line into .htaccess file so it uses the custom php.ini file you created in public_html instead of having to copy php.ini file in every subdirectory you create.
Add this to .htaccess does the trick obviously replacing username
SetEnv PHPRC /home/USERNAME/public_html/php.ini
Not really a solution, but you can disable overriding the display_error setting by using php_admin_flag in your sites configuration. If it still happens then, you have set an error handler which misbehaves.
Hi I'm used shared hosting. I want to turn off php safe_mode off for my site. My provider gave me a php.ini file and asked me to put it with my settings in my public_html folder to override the settings, but it didn't work.
You can also try to create a file called php.ini in the root (public_html or other) folder, and putting the following in it:
safe_mode = Off
Depending on server settings, this may or may not work.
Your service provider might have forgot to tell you that you need to enable your user defined php.ini configuration by adding this line in the .htaccess file that you find in your public_html folder:
#Activates php.ini config located in main folder to work also recursively for all subfolders
suPHP_ConfigPath /home/YOUR_CPANEL_USER_NAME/public_html
Obviously replace YOUR_CPANEL_USER_NAME with your cPanel user name.
I'm supposing your server has got suPHP module(which is quite common in nowdays).
BTW: the php.ini file need to be in /home/YOUR_CPANEL_USER_NAME/public_html too and inside you should write this:
safe_mode = Off
And remember that Safe Mode is deprecated in PHP 5.3.0 and is removed in PHP 6.0.0.
TRY:
You can turn it off by adding the following line to a .htaccess file in your root (public html) folder.
If the .htaccess file doesn't exist, you can create it using a simple text editing program.
php_flag safe_mode Off