Editing php.ini file - php

I'm using phpinfo to find out where the server's php.ini file is located:
<?php phpinfo() ?>
When I log-onto the server using FTP, I don't see it in the path under Loaded Configuration File.
How can I download/edit the php.ini file?
Can I create a custom php.ini file for one directory (and its sub directories), so that the global PHP settings are not changed?

probably you don't have permissions to view the file.
what you can do is make a custom_settings.php and use ini_set() to change the configurations and include that file where ever need, to change the configuration settings.
Please refer to http://us1.php.net/ini_set

If you have Direct Admin installed, you can login as admin and edit it there.

It should be on location
/etc/php.ini
If not found there, you can search it by using
locate php.ini

If you want to change any values​​, try to do it in .htaccess file
Examples:
php_flag display_errors Off
php_value upload_max_filesize 2M
php_value error_reporting 0
php_flag magic_quotes_gpc Off

Related

Enable php-logging on server of godaddy hosted wordpress

for about a day I'm trying to find a way to see php logs on a server by godaddy where wordpress is hosted.
I can ssh to the server, but I'm not able to edit the php.ini because it's readonly.
I've read that it would be possible to add a custom php.ini to change some settings. I've put one in the public folder where the wordpress site is located and added the line:
error_log = "/php_error.log"
In the same folder I've created the file php_error.log and set the following permissions:
-rw-rw----
As this seemed not to work, I've tried an approach editing the .htaccess file.
# log php errors
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_flag log_errors on
php_value error_log /php_error.log
Still I don't see any errors in the file.
Is it a problem of the permissions of the error file or should the path be different e.g. html/php_error.log ?
I've finally found a solution.
I have to create a .user.ini file to set custom settings of php.ini.
I've put the file in the root of my public website directory and inserted the following line:
error_log = "/var/www/php_error.log"
It took me quite a while to figure out what the expected path to my log file is. Hopefully this will save some other people a lot of time and headache.

Set php second configuration ( php.ini file )

I want to set my own (php2.ini) file, with just a few lines that must overwrite the first php.ini settings - only for those lines.
So I start looking on google and it seems like what I need is the parse_ini_file function.
Ok. Now, in index.php I have:
parse_ini_file("php2.ini");
phpinfo();
exit();
But those settings from php2.ini are not loaded...
Trying to see if the file php2.ini is read-it and it is, beacause if I set parse_ini_file("php2-not-exist.ini"), it tells me that the file cannot be found. So the file php2.ini is read, but the settings are not overwritten.
The php2.ini file has inside the next lines:
error_log = "errors.log"
display_errors = "0"
max_execution_time = "300"
upload_max_filesize = "60M"
post_max_size = "60M"
date.timezone = "Europe/Bucharest"
default_charset = "UTF-8"
mbstring.internal_encoding = "UTF-8"
mbstring.http_output = "UTF-8"
mbstring.encoding_translation = "On"
mbstring.func_overload = "6"
Trying to let this file with just one line like post_max_size = "60M", but still not overwriting the general php.ini settings.
What am I missing here?
I know that some settings can be setted only and only using the php.ini file configuration. So setting a second file with parse_ini_file witch is a function from php... something is not correct, because some servers doesn't allow you to edit the general php.ini file. So how can the php let you set a second php ini file if you don't have access to the general one ? I don't know if that has something to do with my problem. I'm just saying that maybe here is the problem.
Right now I'm using wamp with php 5.5.12. I just want when I upload my website up, to be all done. I know that some hosting servers lets you to have a second php.ini file that must be uploaded in public_html or whatever folder it is. This is why I want to set my php2.ini file. To have the website clean when I'll upload to hosting.
Thank you.
The php parse_ini_file() function reads an ini file into an associative array. It does not set them up as settings like the php.ini file.
There is not a convenience function to override the server settings like this. What you may want here are .user.ini (the leading dot is important) files:
Since PHP 5.3.0, PHP includes support for configuration INI files on a per-directory basis.
and:
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.
For full documentation on that feature, take a look at http://php.net/manual/en/configuration.file.per-user.php.
Note that only a subset of settings can be changed here:
Only INI settings with the modes PHP_INI_PERDIR and PHP_INI_USER will be recognized in .user.ini-style INI files.

PHP ignoring config file

I'm trying to turn off magic_quotes_gpc in PHP. I'm running PHP with Apache and Ubuntu.
I have in my config file (/etc/php5/apache2/php.ini):
magic_quotes_gpc Off
Where I create a page with phpinfo() it shows magic_quotes_gpc as on. I've also looked in Additional .ini files parsed and there is no setting for it.
Why is PHP ignoring this?
try to add/edit in php.ini
magic_quotes_gpc = Off
after adding restart your apache services for taking effect this
You can turn them off using .htaccess with:
php_flag magic_quotes_gpc Off
and also using php if writable php.ini
ini_set('magic_quotes_gpc' , 0 );
Firstly, it is deprecated so, don't rely on it. Mmmmmmmkay?
Secondly, Check
Loaded Configuration File
Under phpinfo()
Also Add :
php_flag magic_quotes_gpc Off to your .htaccess file.
Cool?
Did you recently make this change? If so, you have to restart PHP for it to take effect.

file_uploads is on in the server but shows off in xcart installation

The link to the site is http://64.37.106.37/. It shows file_uploads as zero. I have printed the value of file_uploads on the top and it is displaying 1. I have also checked it in the control panel and there also its showing On. I have checked the code and nowhere the value of file_uploads is overwritten. What can be the solution to this?
You should check php.ini and .htaccess files, not just a control panel (whatever that may be).
To verify what's in php.ini and what's overridden locally, create a new php file containing:
<?php phpinfo(); ?>
This will list all of your directives, search for 'upload' and see what the values are. If it's set to 0 in your php.ini, update that. Otherwise for locally different values, search through .htaccess files for a php_value or php_admin_value message.
If there is no .htaccess file in the web root, try creating one with php_admin_value file_uploads 1 in it.

PHP.ini does not work

I opened the notepad, inserted 3 lines in it, saved it as php.ini, and uploaded it in public_html, but I am still getting an error that requires to first switch the magic quotes off. The syntax of the three lines is as following:
magic_quotes_gpc = 0
magic_quotes_runtime = 0
magic_quotes_sybase = 0
What am I doing wrong?
use phpinfo() function to see what php.ini file you're actually using
You can probably alter these settings in a .htaccess configuration file as well:
php_flag magic_quotes_gpc off
php_flag magic_quotes_runtime off
php_flag magic_quotes_sybase off
See PHP: How to change configuration settings.
Most hosting companies lets you define a local ini file. Check their support pages, and see where you should put your php.ini file for it to be read by the php engine. If they have an option for this, you don't have to worry about restarting the server.
If you can't find any info about it, create a page with the following code:
<?php phpinfo(); ?>
And look for the property named "Configuration File (php.ini) Path". This is where you should put the file.
It's not meant to be placed in the public_html folder... it should be in your PHP installation folder.
Php.ini is not usually located in public_html. If you can't access your real php.ini, try writing
php_flag magic_quotes_gpc off
in a .htaccess file (in public_html).
Most hosting companies won't let you play around with the php.ini unless you rent a dedicated server from them. On that, you could try on page php.ini settings like the following:
ini_set("magic_quotes_gpc", "0");
ini_set("magic_quotes_runtime", "0");
ini_set("magic_quotes_sybase", "0");
If that doesn't work, then you'll have to ask your hosting company about it.
On CentOS 8 run
service php-fpm restart
To read the edited php.ini file
Well, you have to change your main php.ini which I don't think is in public_html.
Moreover, in order to see the changes you have to restart your php engine.

Categories