Edits on PHP.INI not making effect - php

I'm on MacOS Mojave. phpinfo() shows my php.ini file is on
/usr/local/php5/lib/php.ini
But the problem is, i edit it, put new modules to be loaded, even put invalid instructions, and Apache log file show nothing / no errors when i restart it.
Is there any other location php.ini can be, even if phpinfo() shows the location above ?
Thanks

Is it possible that your Apache not using PHP from /usr/local/php5/ path? Did you install another PHP version (or update) before?
Can you please check phpinfo? For example what it does say for "Loaded Configuration File" and "Scan this dir for additional .ini files"

Related

php_ini_loaded_file not working with PHP 5.5.30, Apache 2.4 in El Capitan

I'm using Apache 2.4 on my El Capitan Mac. I would like to know which php.ini is used by the server.
The output of phpinfo() tells me that that the path for the php.ini file is the etc/ directory.
Unfortunately, there are four such files there :
php.ini-5.2-previous
php.ini.default
php.ini.default-5.2-previous
php.ini.default-5.2-previous~orig
My guess would be that it uses php.ini.default, but I would like to be 100% sure.
So I call php_ini_loaded_file(), which unfortunately returnsbool(false). Does it mean that the PHP module in Apache does not load any php.ini at all ???
Any help appreciated.
If you do not have any "Loaded Configuration File" row in your phpinfo() output, then probably there is no php.ini file loaded at all, as you suspect.
Try to copy one of the existing files to the filename php.ini, and restart the server. If it loads it, find out the differences between the variants and configure your system to your needs.

Why isn't Php not loading values from php.ini? [duplicate]

I have been trying for two days to increase the max filesize for file uploads via php to 10M from the default 2M. I change the php.ini file that is referenced by phpinfo to no avail.
I saw a few articles stating that there is a syntax error around line 109 of the php.ini file, but I don't know what the syntax error is or how to correct it. users stated that because the upload_max_filesize is AFTER this error in the config file it is being ignored. Please help.
This message helped me:
The newest php version installed on server does not allow global settings (such as execution time, max upload filesize, max post file size, etc.) to be changed.
Folow these steps to resolve the issue:
Eval phpinfo();
Search for 'Scan this dir for additional .ini files' text in phpinfo() output
It will be something like this /etc/php5/apache2/conf.d
Create your user.ini file inside the dir. (/etc/php5/apache2/conf.d/user.ini)
Use this ini file for custom settings.
Restart the server
File /etc/php5/apache2/conf.d/user.ini
post_max_size = 90M
upload_max_filesize = 50M
Update 2018.06
If you are using nginx + php-fpm your path will be something like this (use your php version in path). Create file using:
nano /etc/php/7.0/fpm/conf.d/user.ini
There are a lot of other .ini files in the conf.d directory. If you want your config to be the last included - use prefix.
For example: 30-user.ini.
After file creation don't forget to restart fpm:
sudo service php7.0-fpm restart
If you php.ini resides somewhere like /etc/php/7.*/fpm/php.ini - then modify it as needed and instead of sudo service apache2 restart go with service php7.1-fpm restart
Have you restarted apache2?
sudo service apache2 restart
The new php.ini configuration is only applied when apache starts.
You might also need to increase the maximum size of a post:
post_max_size=10M
Try that.
I had exactly the same problem and solved it using these steps:
When running the following command on my server
php --ini
I got the following path of my php.ini
Loaded Configuration File: /etc/php/7.0/cli/php.ini
I kept on making changes in this php.ini file, but none of the changes took effect. I then created a file called info.php in my /var/www/html directory and added the following code
<?php
phpinfo();
?>
Then I opened the file in my browser http://example.com/info.php, where I saw that the actual loaded php.ini file was in a different directory
Loaded Configuration File /etc/php/7.0/apache2/php.ini
When I made changes to the php.ini file inside of this directory, all the changes took effect. In summary make sure that you run the phpinfo(); function to make sure of the actual php.ini file which php uses.
service apache2 reload needs to be run as root, even if it does not appear to fail without root. Running sudo service apache2 reload works. This is in Ubuntu 14.04.
Maybe you find 2 directories for php.ini files.
If you search where php.ini is using cli like php --ini maybe it show you /etc/php/7.1/cli/php.ini, but thereis another folder to php-fpm found in /etc/php/7.1/fpm/php.ini and you need to create your new ini file under conf.d folder like /etc/php/7.1/fpm/conf.d/30-user.ini and if you need a ini file to cli command line you need to put your ini file under /etc/php/7.1/cli/conf.d/30-user.ini
I had a very strange experience which caused the same symptom like this.
The point is that my php.ini file contained an old-style comment (starting with hashmark) which, as of php 7.0, is not a comment any more. The incorrect comment confused the ini-parser.
The solution was to replace all # comment symbols with semicolon (;) which is the only standard way for writing comments.
For further details, please read my comment here:
https://serverfault.com/a/1012262/494670
After reading great #Jekis's answer, I solved the same issue for Fedora distribution (it's the same thing, just different path):
After evaluting phpinfo(); output I found out that other .ini files are stored in: /etc/php.d directory
In /etc/php.d I created a new file - 40-user.ini. I added upload_max_filesize and other settings that I wanted to change
Then I restarted apache (httpd)
And then changes were picked up.
Changes to Ubuntu php.ini will not take effect.
Steps to resolve this issue in Ubuntu 18.04 with Nginx 1.18.0.
Check the php version you are running: php -v
Check for syntax errors in php.ini: sudo php-fpm7.4 -t (change to the version you are running).
Use your favorite editor to fix syntax errors.
Restart php-fpm: sudo systemctl restart php7.4-fpm (change to the version you are running).
My results:
PHP: syntax error, unexpected END_OF_LINE, expecting '=' in /etc/php/7.4/fpm/php.ini on line 2
In my case it was a "w" before the [PHP] which must have happened when I was using Ctrl w for searching with nano.

Composer can't find ext-mbstring even though it is installed

When I attempt to install Laravel 5 I get a dependency error. I'm using Uniform Server on Windows 7. I have enabled php_mbstring.dll and I checked it's loading properly. (I think)
Here is the console output (Composer):
Here are the extensions in my php.ini
Here are the phpinfo() mbstring details:
I don't know where to go from here.
Any idea?
Pay attention that, both in Windows and Linux, PHP can run with multiples php.ini configuration files.
In general, when you find this kind of issue, you have to double check that the configuration file loaded is the same that you are editing or you need to find the right path and add the extension also to the right php.ini configuration file.
While running a script through a web server, you can find the configuration file using the function
phpinfo();
and checking the line "Loaded Configuration File" (or just look for php.ini)
For what concern the CLI you can run in CMD
php --ini
and check the first lines in order to find the Loaded Configuration File value.

Opcache does not get enabled

I've installed Apache 2.4.x webserver on Ubuntu and also PHP5.5.x from sources. I go to php installation folder and do find . -name "opcache.so". Then, to php.ini (same as in phpinfo()), I add zend_extension=/php5/lib/php/extensions/no-debug-zts-x/opcache.so, and opcache.enable=On (or 1) and restart Apache with apachectl restart. Then I check phpinfo() but opcache does not get enabled! Please help.
I think a wrong php.ini file might be used, but in phpinfo() it shows the path to file which I do edit. When I change maximum upload filesize from 2M to 4M in the php.ini, and restart Apache, it does not get changed in phpinfo()
Turns out, after compilation PHP would look for the ini file in /usr/local/lib rather than where I installed it despite
--with-config-file-path=PATH
Set the path in which to look for php.ini [PREFIX/lib]
To check it, you can run php --ini to see if the file has been read fine.
But now I'm seeing white screen when trying to load php files :)
Hope it helps.

php not working with php.ini file on mac os x

I'm running a local server on my macbook (os x 10.9.2)
I'm trying to install mcrypt and I've run into a problem that I can't add the extension to my php.ini file, because apparently my php installation doesn't use a php.ini file.
Looking at phpinfo(), I see this:
Configuration File (php.ini) Path: /etc
Loaded Configuration File: (none)
In my /etc folder, a php.ini file doesn't exist. I do have a php.ini.default, but when I make a copy of that and name it php.ini, and restart apache, PHP just stops working entirely (my php code isn't interpreted and shows up when viewing the web site's source).
Is there something in the php.ini.default file I have to change before copying it to php.ini?
Edit: Upon further trial and error, I have found that if I create a blank php.ini file and restart the server, PHP runs just fine. There must be an error in php.ini.default that is killing PHP on my local server. I've tried using php.ini.default~orig too and the same problem happens. Any way to find out what is wrong with the php.ini.default file?
Edit2: Upon further random trial and error, if my php.ini only contains:
[PHP]
short_open_tag = On
PHP works. If it only contains:
[PHP]
short_open_tag = Off
PHP doesn't work. I'm so confused.
Edit3: Oh! The php.ini.default file had short_open_tag = Off, and of course I'm using short open tags everywhere. Edit2 clued me in. Wasted half a day on this. This is so embarrassing. Everything is working now.
In case someone else runs into the missing php.ini problem on OS X 10.9 or 10.10:
I ran into the same problem after trying install the latest php through homebrew. Turns out mac comes with php already installed, but no config file. Homebrew won't overwrite the system php binary, which remains the default.
Try sudo rm /usr/bin/php then brew install homebrew/php/php55.

Categories