I have php script that must be runned from console (php-cli). But configuration of php.ini for php-cli was incorrect. I fix it, but when I run script a had error with php config, because php.ini uses an old.
How I can reload php.ini for console without restart server?
The configuration is loaded fresh each time you invoke PHP from the CLI.
Related
I needed to change few values in php.ini file and after running phpinfo() within my application, found my php.ini file in below location
Configuration File (php.ini) Path /opt/php-5.6.30/lib
Loaded Configuration File /opt/php-5.6.30/lib/php.ini
Changed the values in above php.ini file followed by apache2 restart but they didn't reflect.
I ran php --ini command to see any other php.ini files and got following folders:
/etc/php/7.0/cli
/etc/php/7.0/apache2
/etc/php/7/0/fpm
so changed values in all of those php.ini files followed by apache2 and php7.0-fpm restart but to no effect.
I'm puzzled as my application's "loaded configuration file" is using php 5.6.30 which is in /opt/php-5.6.30 folder without any apache2 folder within and php-fpm points at /etc/php/7.0 folder.
None of those ini files followed by apache & php-fpm service restarts is actually reflecting my changes.
Any suggestions/pointers would be much appreciated.
I think the problem is that you are using different php versions for php-fpm (web), and cli. You should create test.php file, and run there phpinfo(). And check where loaded php.ini of web version is located. You should access test.php from web, like https://example.com/test.php
If you've made changes to your php.ini file and the changes are not being reflected, even after restarting your server, there are a few things you can try:
Check that you are editing the correct php.ini file: Make sure you are editing the correct php.ini file that your server is using. You can check which file your server is using by creating a PHP file with the following content:
<?php
phpinfo();
?>
Save the file to your server and open it in your browser. Look for the "Loaded Configuration File" directive in the output to determine the location of the php.ini file.
Check that you have permission to edit the php.ini file: Make sure that you have permission to edit the php.ini file. If you are not the owner of the file, you may need to use sudo to edit it.
Check for syntax errors: Make sure that there are no syntax errors in your php.ini file. You can check for syntax errors by running the following command:
php -c /path/to/php.ini -l
Replace /path/to/php.ini with the actual path to your php.ini file. If there are syntax errors, you will need to correct them before the changes can take effect.
Clear any opcode caches: If you have an opcode cache, such as APC or OPcache, you may need to clear it before the changes to the php.ini file take effect. You can usually clear the opcode cache by restarting your web server or by using the cache's built-in function.
Check that your changes are in the correct section: Make sure that your changes are in the correct section of the php.ini file. For example, if you are trying to change the max_execution_time directive, make sure that it is in the [PHP] section of the file.
Restart your web server: Finally, make sure to restart your web server after making changes to the php.ini file. Depending on your server configuration, you may need to restart both the web server and the PHP FPM process.
Followed a few tutorials but it just doesn't update.
I restarted the server many times with sudo service apache2 restart and sudo apachectl restart
I ran php --ini to check all the files being loaded
I checked each file to see if it is being overwritten
I made another override and checked if its being loaded
Used the phpinfo() function to check if its being updated
I'm using PHP Version 5.5.9-1ubuntu4.21
Its a virtual machine in virtualbox
the change that I'm trying to make is for php to allow more inputs in a post.
I don't know if I should post here or in Super User
Chances are you are modifying the php.ini of the CLI instead of the one for apache. It should be under:
/etc/php/$VERSION/apache2/php.ini
Then restart apache.
i have installed php on windows just for having opportunity running php commands.
One of those commands required from me enabling few extensions (mbstring, openssl). I have enabled them in php.ini, but still it cant see it because php is not reloaded. I dont have any webservers on windows (no IIS, Apache, Nginx). How can i just reload php and php.ini without any webservers?
Thanks!
Use php.exe --ini to display what configuration files are being used and edit the correct php.ini file.
I want to try the ZeroMQ, and I write two php file, service.php and client.php.
I use the linux terminal to run service php /web/test/service.php,it's ok, terminal print a "waiting for client connecting...".
but, I request my client.php through chrome explorer,error happened, I check my error.log,there is message "php fatal error: class 'ZMQContext' not found........"
and I use command php -m to check my php extension, zmq is already in that list.
The problem is that the ZMQ module is loaded in the PHP CLI (Command Line Interface) but it's not loaded into Apache. Therefore, service.php runs smoothly from the Command Line but client.php can't use ZMQContext because Apache does not load ZMQ.
There are two different .ini-files. These probably are (but can be different, depending on your distro):
/etc/php5/apache2/php.ini for Apache
/etc/php5/cli/php.ini for CLI
However, all .ini files from the /etc/php5/conf.d/ directory are loaded into both Apache and the CLI.
See also: PHP - An external Class/library is accessible from apache but not from phpunit (the exact opposite of your problem)
Check which php.ini files are loaded
Checking (with phpinfo) which php.ini files are loaded when requested via nginx (which probably means via php-fpm) - will almost certainly reveal that it loads different ini files than the cli. Assuming php-fpm usage, the following ini files are probably loaded:
/etc/php5/fpm/php.ini
/etc/php5/fpm/conf.d/*
and no zmq.ini file listed.
Loading zmq for php-fpm
Follow the instructions for installing zmq on php, and create an ini file for zeromq (or copy the one from /etc/php5/cli/conf.d/ since evidently it's loaded for cli usage):
# /etc/php5/conf.d/zeromq.ini
extension=zmq.so
Then restart php-fpm
sudo /etc/init.d/php5-fpm restart
And zeromq should be available for use.
A really easy way to solve this issue is to enable ZMQ globally (cli + Apache) with phpenmod
For example with php5
php5enmod zmq
service apache2 restart
I've see a few other similar questions on here, but most of the answers are Apache specific (dealing with their .htaccess file) and I'm using nginx.
I'm having trouble making my change to the upload_max_filesize in php.ini stick. I'm using nginx, php5 and wordpress on Debian.
When I run phpinfo() I see the following output:
Loaded Configuration File /etc/php5/cgi/php.ini
I then go to the relevant .ini file, change a few values, and then restart nginx. When I fire up a phpinfo() plugin I got for wordpress, it reports the values as unchanged.
I'm at a loss because phpinfo() reports that it is loading config values from the file that I've changed, but it doesn't report the changes.
You might be using FAST CGI:
[webserver] <----> [fcgi daemon]
`- [php]
If you restart the webserver, PHP is not restarted, so still has the old ini values because it didn't reload the ini file.
Restarting the fcgi daemon solves that issue, PHP will be restarted, re-reading the ini.
Some fcgi daemons have a command that reloads the child processes more gracefully. Depends on what you use.
For me the problem was a syntax error in the custom php.ini file, which I found after checking the error logs.
This might help the ones that are using php -i from the terminal to check php.ini settings.
In my case, I increased the upload_max_filesize from 2M to 20 MB by editing /etc/php/7.3/apache2/php.ini and restarted the apache by apachectl restart command.
I used php -i command from the Debian terminal to see the changes are in effect but upload_max_filesize was still 2M.
Then I realized settings readings came from /etc/php/7.3/cli/php.ini because I was using php -i from the terminal instead of phpinfo() function in a web page.
$ sudo service php7.4-fpm restart
Resolved my problem. change the php version to the one you using.