php settings does not work at all - php

I have a Linux apache2 webserver with php version 7.0.22. It looks like the settings does not work at all :(
The .ini file is on the location: /etc/php/7.0/apache2/php.ini according to phpinfo(). When I look into the /etc/php/7.0/apache2 folder I see three files php.ini (the file that the settings are telling me that is in use),php.ini.save and php.ini.ucf-dist.
So I looked for allow_url_include and it was off, I change it to On and then allow_url_fopen = On. I did this to all of the .ini files saved them restarted apache2 and refreshed the phpinfo() page and nothing happened.
I tried to change another settings in all of the .ini files and did the same thing and nothing happened. I have permission 777 on all of the .ini files (not smart, but I'am just trying to get this thing working).
So is there maybe some other settings that I need to change so I can update the settings for real? Any idea?
UPDATE:
And this is in the Additional .ini files parsed field:
/etc/php/7.0/apache2/conf.d/10-mysqlnd.ini, /etc/php/7.0/apache2/conf.d/10-opcache.ini, /etc/php/7.0/apache2/conf.d/10-pdo.ini, /etc/php/7.0/apache2/conf.d/15-xml.ini, /etc/php/7.0/apache2/conf.d/20-calendar.ini, /etc/php/7.0/apache2/conf.d/20-ctype.ini, /etc/php/7.0/apache2/conf.d/20-dom.ini, /etc/php/7.0/apache2/conf.d/20-exif.ini, /etc/php/7.0/apache2/conf.d/20-fileinfo.ini, /etc/php/7.0/apache2/conf.d/20-ftp.ini, /etc/php/7.0/apache2/conf.d/20-gd.ini, /etc/php/7.0/apache2/conf.d/20-gettext.ini, /etc/php/7.0/apache2/conf.d/20-iconv.ini, /etc/php/7.0/apache2/conf.d/20-json.ini, /etc/php/7.0/apache2/conf.d/20-mbstring.ini, /etc/php/7.0/apache2/conf.d/20-mcrypt.ini, /etc/php/7.0/apache2/conf.d/20-mysqli.ini, /etc/php/7.0/apache2/conf.d/20-pdo_mysql.ini, /etc/php/7.0/apache2/conf.d/20-pdo_sqlite.ini, /etc/php/7.0/apache2/conf.d/20-phar.ini, /etc/php/7.0/apache2/conf.d/20-posix.ini, /etc/php/7.0/apache2/conf.d/20-readline.ini, /etc/php/7.0/apache2/conf.d/20-shmop.ini, /etc/php/7.0/apache2/conf.d/20-simplexml.ini, /etc/php/7.0/apache2/conf.d/20-sockets.ini, /etc/php/7.0/apache2/conf.d/20-sqlite3.ini, /etc/php/7.0/apache2/conf.d/20-sysvmsg.ini, /etc/php/7.0/apache2/conf.d/20-sysvsem.ini, /etc/php/7.0/apache2/conf.d/20-sysvshm.ini, /etc/php/7.0/apache2/conf.d/20-tokenizer.ini, /etc/php/7.0/apache2/conf.d/20-wddx.ini, /etc/php/7.0/apache2/conf.d/20-xmlreader.ini, /etc/php/7.0/apache2/conf.d/20-xmlwriter.ini, /etc/php/7.0/apache2/conf.d/20-xsl.ini, /etc/php/7.0/apache2/conf.d/20-zip.ini

They might have been overrewritten by .htaccess http://docs.php.net/manual/en/configuration.changes.php#configuration.changes.apache
or even in the php code http://php.net/manual/en/function.ini-set.php

You can try grep -r allow_url_include /etc/php/7.0 and see if that directive is defined anywhere else in your configuration path.
Also, make sure the setting in your ini file is not preceded by a semi-colon which is a comment. Depending on your distribution, this can be the case with defaults and it might read like this:
; Whether to allow include/require to open URLs (like http:// or ftp://) as files.
; http://php.net/allow-url-include
; allow_url_include = Off
So in addition to changing the setting to On, you'd need to remove the ;
; Whether to allow include/require to open URLs (like http:// or ftp://) as files.
; http://php.net/allow-url-include
allow_url_include = On

Related

shell_exec() has been disabled for security reasons

I executed a script with php cli : php myscript.php
In mycript.php, you can find $output = shell_exec('bash migration.sh');
When I trigger the script, I received this error : shell_exec() has been disabled for security reasons
So, I tried to solve with the following solution : php --ini
I had the following result :
Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File: /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/cli/conf.d
Additional .ini files parsed: /etc/php5/cli/conf.d/curl.ini,
/etc/php5/cli/conf.d/gd.ini,
/etc/php5/cli/conf.d/intl.ini,
/etc/php5/cli/conf.d/mcrypt.ini,
/etc/php5/cli/conf.d/memcache.ini,
/etc/php5/cli/conf.d/memcached.ini,
/etc/php5/cli/conf.d/mysql.ini,
/etc/php5/cli/conf.d/mysqli.ini,
/etc/php5/cli/conf.d/pdo.ini,
/etc/php5/cli/conf.d/pdo_mysql.ini,
/etc/php5/cli/conf.d/suhosin.ini,
/etc/php5/cli/conf.d/xcache.ini
I opened /etc/php5/cli/php.ini and looked for disable_functions
As a surprise, disable_functions was empty : disable_functions =
I also looked for shell_exec or exec in this file, but nothing was found. I also tried to find the php.ini path with phpinfo(), but it was the same path.
How can I solve my issue ?
Edit after answers : It's on my own VM. safe_mode is disabled : safe_mode = Off in php.ini.
Thanks in advance for your solutions.
To change disabled functions when using WHM.
instructions taken from this page
Log into WHM.
Navigate to MultiPHP Manager.
In the Set PHP Version per Domain section, search for your domain.
Click Edit PHP-FPM to the far right of your domain.
To enable a PHP function, click Edit function list and remove the desired function from the li
Have you checked the suhosin.ini File?
Depending on the Configuration there, suoshin can also deny certain PHP Functions.
See https://suhosin.org/stories/howtos.html. There are certain ways on how to Whitelist and Blacklist Functions.
You needed to tweak your php.ini and modify disable_functions entry to no longer list that function. Mind that common issue is editing wrong config file (use phpinfo() to check that).

webserver: php.ini changes not taking effect

According to phpinfo() the following php.ini files are loaded:
Configuration File (php.ini) Path /etc/php5/cgi
Loaded Configuration File /var/www/vhosts/mywebsite.com/etc/php.ini
Scan this dir for additional .ini files /etc/php5/cgi/conf.d
I've made changes to php.ini found in /etc/php5/cgi - restarted server - NO Effect.
This file: /var/www/vhosts/mywebsite.com/etc/php.ini has the note:
DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY, SO ALL
YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.
The server has these php.ini files
/etc/php5/cli/php.ini
/etc/php5/cgi/php.ini
/etc/php5/apache2/php.ini
/opt/psa/admin/conf/php.ini
/var/www/vhosts/mywebsite.com/etc/php.ini
Could you please tell me which php.ini file should I look for?
If you want to add something to php.ini (as xdebug properties, for example), then you should use /etc/php5/cgi/conf.d folder (create or edit one of that files).
As for php.ini located in cgi - seems right that you've done. However, there still exists a possibility, that you can edit these files, but they are overwritten by general configuration by your provider. I would advice to check it locally, if the same configuration would work.
EDIT: /opt/psa/admin/conf/php.ini looks like a possibility of this variant.
Also I would advice to edit apache's php.ini, but it looks more like a magic path.
I had a syntax error at 1. line!
It was :[php] instead of [php].
PHP ignored my config file because it couldn't see a php section
For me that fixed everything; Run php -c 'path-to-php.ini'. It will show you more information.

Php.ini production vs development

I'm using XAMPP to develop on my localhost. I would like to remove the PHP notices and keep only the warnings. I know this is done through the php.ini file, however I'm having trouble locating it. I followed the path in phpinfo() and it led me to /xampp/php. Inside this folder are two php.ini files: one for production and one for development. I have set them both to the error reporting level I'd like, however I still receive notices which makes me believe that neither of these actually control error reporting. I'm using the latest version of XAMPP. So I guess my question is where is the true php.ini and what are these two other versions?
As of PHP 7 the regular php.ini file was removed and added with php.ini-production and php.ini-devlopment. In PHP's installation text file they state, "We advise you to use php.ini-production, because we optimized the default settings in this file for performance, and security."
So in short use the php.ini-production
First, make sure you're editing php.ini, not php-development.ini or php-production.ini or anything BUT php.ini. After that, ensure you restart your Apache server or your changes won't take effect.
Also, check out ini_set for setting ini values at runtime.
I had this confusion, in my computer, the php.ini file didn't appear with the .ini extension name visible - it was just php , and in the type column, it has the value 'configuration settings'
I downloaded php-8.1.0 from official website. php.ini or configuration settings file is not present in it. Instead it has been replaced by two files i.e. php.ini-development and php.ini-production.
My requirement was to edit the php.ini file in order to enable pgsql extension. Alas! there were not one but two .ini files. Being new to php, I made changes to both the files but it didn't worked.
After doing some research, I came to know that in the recent versions of php (not sure from which), user is provided with two .ini files. As name suggests, php.ini-development contains settings suitable for development environment and php.ini-production contains settings suitable for production environment. As per your requirement, you need take backup of anyone of the file and rename that file to php.ini. In this file you will need make required changes for your php environment.
If you compare the two files using tools such as diff-merge, you will get more in-depth understanding.
php.ini.development and php.ini.production are entirely different from php.ini.
the problem is that in the php folder the required php.ini is not marked along with its extension ( .php). Only php is written.Check the properties of the file 'php' of "*configuration settings*" type.it must be .ini,This is the exact file which manages error reporting.
In XAMPP version 1.8.1 php.ini file located at \xampp\php\php.ini modify line 922 upload_max_filesize = 2M
Note: 2M means 2MB, so change to 10M for 10MB file upload. Also note that php.ini-development and php.ini-production are different files from php.ini.
My issue is that I was editing the php.ini-production and overlooked the standard php.ini file.
I edited the php.ini file by adding extension=php_odbc.dll and it fixed the error.
PHP 5.3.0 has significantly improved performance and parsing of INI files, and adds several new syntax features.
The standard php.ini files have been re-organized and renamed. php.ini-development contains settings recommended for use in development environments. php.ini-production contains settings recommended for use in production environments
The PHP.ini file is still there, only it doesn't include the extension .ini, the extension has been removed. You will notice two file name php, one is application file another is configuration setting when you open configuration setting in notepad you will notice that it has ini extension. so the php configuration file is ini file.

Custom php.ini file not working in VPS hosting

I've tried going through Network Solutions tech support but didn't get it resolved ("You need to talk to Signature Support, which is $50").
I'm running some sites off of a Net Sol VPS account and need to change the upload_max_filesize setting (which is apparently set to a paltry 2MB by default) for the php server. I've added:
upload_max_filesize = 20M
post_max_size = 20M
max_execution_time = 6000
to the /httpdocs/cgi-bin/php.ini file (per NS's instructions), and then restarted apache, but when I run a phpinfo on that domain, the settings are not applied. It still says "2M" for the upload max.
I also tried adding this to the server root at /cgi-bin/php.ini as well, to no effect.
There is no /cgi-bin/.php/php.coalesced.ini file that I can see.
Any ideas? I'm losing my mind with this.
First thought is to check your phpinfo() output for the value listed in the "Loaded Configuration File" setting and make sure that it matches the file you've been editing.
You can't just litter PHP.ini files around and expect PHP to load them. If it's not been told to look for one in that cgi-bin directory, the file will just get ignored.
Check the phpinfo() output - the first section will tell you exactly what .ini files were located/parsed, and their location. e.g. on my home server:
Configuration File (php.ini) Path /etc/php5/apache2
Loaded Configuration File /etc/php5/apache2/php.ini
Scan this dir for additional .ini files /etc/php5/apache2/conf.d
Additional .ini files parsed /etc/php5/apache2/conf.d/curl.ini, /etc/php5/apache2/conf.d/gmp.ini, /etc/php5/apache2/conf.d/mysql.ini, /etc/php5/apache2/conf.d/mysqli.ini, /etc/php5/apache2/conf.d/pdo.ini, /etc/php5/apache2/conf.d/pdo_mysql.ini
if your cgi-bin .ini file isn't listed, then PHP is NOT looking in that directory.
I know this is old but figured I'd share my experience. I tried adding a php.ini file to the /cgi-bin folder as I read was suggested, that didn't appear to work. My solution was to SSH onto the server and make a change to the real php.ini file and then restarting the server.

php.ini not working in IIS?

I've set magic_quotes_gpc = Off in php.ini,but I see it's still On in phpinfo();
First of all, you must be sure you modified the right php.ini file : there can be many files called php.ini -- and only one is "the right one".
You can see which php.ini file is used in the output of phpinfo() : there should be an entry called Configuration File (php.ini) Path that indicates the directory in which php.ini is looked for, and an entry called Loaded Configuration File that indicates the full path+name of the php.ini file that's used.
Then : don't forget to restart the webserver, so the modifications to php.ini are taken into account (Not sure that's necessary with IIS, but as it's required with Apache, I suppose it cannot hurt with IIS)
If that doesn't change a thing : what if you try to modify another directive : is the modification taken into account ?
As an alternative, you can disable it from your script too:
// disable magic_quotes_runtime
if (get_magic_quotes_runtime())
{
#set_magic_quotes_runtime(0);
}
You can check the php.ini file that was loaded via the php_ini_loaded_file function. Restart your web server.
On my installation the c:\php\php.ini file was named php ini. So phpmyinfo() was not loading it, despite the PATH environment variable including C:\php\. (Check this in a DOS prompt with SET PATH).
So rename it to php.ini.
It was difficult to spot in Windows Explorer.

Categories