GoAdmio

checkphpini

Scan every php.ini on the server for startup errors and delete the line that causes each one

On this page: Overview · Quick start · Syntax · Options · Output · Examples · Troubleshooting · Details · See also


Overview

A syntax error in a php.ini file makes PHP print a startup error, and it can stop PHP-FPM or Apache from starting. This can happen after a bad edit or a failed change to a setting. /go/checkphpini looks for these errors in the php.ini of every installed PHP version and deletes the line that PHP reports.

[!WARNING] The command edits files in place and keeps no copy of the deleted line. Back up your PHP configuration before you run it. See Safety.


Quick start

/go/checkphpini

Syntax

/go/checkphpini

The command takes no options or arguments. Run it as root. It needs the PHP command line program (php).


Options

None. Any arguments you pass are ignored.

Files checked

System php.ini locations
AlmaLinux, Rocky, CentOS, Red Hat, Fedora /etc/php.ini and /etc/opt/remi/<version>/php.ini for each installed PHP version
Debian, Ubuntu /etc/php/<version>/fpm/php.ini, /etc/php/<version>/cli/php.ini, and /etc/php/<version>/apache2/php.ini for each installed PHP version

On any other system, the command does nothing.


Output

The command prints nothing when no php.ini has an error. When it finds one, it prints the error message that PHP reports and then a confirmation:

PHP:  syntax error, unexpected '=' in /etc/php/8.3/fpm/php.ini on line 45
Line 45 has been removed.

The deleted text is not printed. The error message names the file and the line number, so you can see where the change was made.

Each run also adds a line to /var/log/go/checkphpini.log.


Examples

# Back up the PHP configuration first (Debian/Ubuntu)
cp -a /etc/php /root/php-backup
# Scan and repair
/go/checkphpini
# Look for errors yourself without changing anything
php -c /etc/php/8.3/fpm/php.ini -i 2>&1 | grep " on line "
# Restart PHP-FPM so the change is used
/go/fpm

Troubleshooting

Symptom Likely cause Fix
Nothing is printed, but PHP still shows an error The error is not in a php.ini that was checked, or it has no file and line number. Run the php -c ... -i command from the Examples and read the message.
Line 0 has been removed. but the error stays The error is reported as in Unknown on line 0, as for an extension that cannot be loaded. The command has no file to edit and removes nothing. Fix the extension with extension.
Line <n> has been removed. but the line is still there The path of the file in the error has a hyphen, underscore, or capital letter, such as /etc/php/8.3/cli/conf.d/20-curl.ini. The command cannot read this path. Edit the file by hand.
The command fails when a file has several errors It handles one error per file. Fix the errors by hand, or run it again after fixing the first one.
A working setting disappeared The reported line was valid, and the real mistake was on an earlier line, such as a missing quote. Restore the file from your backup.
PHP still uses the old settings PHP-FPM or Apache was not restarted. Run fpm or reload.

Details

What it does, in order

  1. Logs the run to /var/log/go/checkphpini.log.
  2. Builds the list of folders to check for the operating system (see Files checked).
  3. For each folder that has a php.ini, runs the default php command with that file and looks for the text on line in its output.
  4. If an error is found, reads the line number and the file name from it, prints the error, and deletes that line from the file.

The command does not restart PHP-FPM or Apache.

Safety

[!WARNING]

  • The line is deleted with no backup, and it is not shown. A line that PHP complains about can be the result of an earlier mistake, so a valid setting may be removed.
  • The file named in the error is changed, which can be an extra .ini file and not the php.ini that was being checked.

Known issues


See also

Command Description
fpm Restart all installed PHP-FPM versions on your server
extension List, install, or remove PHP extensions across every version
displaystartuperrors Toggle PHP display_startup_errors across all php.ini files
memorylimit Change the PHP memory limit for all PHP versions
listphp List the available PHP versions on a GoAdmio server
reload Reload PHP-FPM and the active web server