Optimize & Secure PHP.INI for php-fpm
This script that optimize and secure your PHP configuration.
Displaying error only enabled on Development enviroment, in production it's disabled.
Disabling the errors and limiting it only to Information will limit its vulnerabilities such as:
-
PHP scripts path disclosure;
-
Displaying Enabled/Disabled php extensions ;
For more info about PHP path disclosure vulnerability or path traversal exploit
The following settings are altered:
-
Error logging: production >
syslog; development >web client; -
PHP exposition: prevents exposing if you're running PHP and/or which version.
-
memory limit: a generous 512 MB.
-
POST and upload maximum sizes.
-
cgi.fix_pathinfo set to 0.
-
Disallow
fopenorincludeto open files specified through a URI. -
disallow for manipulation of cookies through the DOM.
-
Setup additional entropy for session token generation using the hardware random number generator
/dev/urandom. This requires PHP 5.3 or later.
To use this script(s) do the following:
-
Clone the git repo.
git clone https://github.com/azoughbi/php-ini-optimize.git -
Run the shell script
php_optimize. It has three argumentsphp_optimize -p [-d] -m 2G /path/to/php.ini:a) the first argument: either
-pto optimize production environment or-dto optimize development enviroment.b)
-m 2Gspecifies the memory limit for PHP. By default is 512M.c) The last argument specifies the full path of
php.inifile. if running from inside/etc/php5/fpmno need to specify the path.
-
Optimize production site, running the script on the current directory:
php_optimize -p -
Optimize development site, running the script on the current directory:
php_optimize -d -
Optimize production site with PHP FPM, from outside
/etc/php5/fpmdirectory:php_optimize -p /etc/php5/fpm/php.ini -
Optimize a production site with PHP FPM, from outside
/etc/php5/fpmdirectory and set the memory limit to 2G:php_optimize -p -m 2G /etc/php5/fpm/php.ini