@@ -37,8 +37,6 @@ class webserver_plugin {
3737 * This function is called during ispconfig installation to determine
3838 * if a symlink shall be created for this plugin.
3939 */
40-
41-
4240 public function onInstall () {
4341 global $ conf ;
4442
@@ -92,10 +90,6 @@ public function check_phpini_changes() {
9290 'mode ' => 'mod ' ,
9391 'php_version ' => 0 ); // default;
9492
95- $ check_files [] = array ('file ' => $ web_config ['php_ini_path_cgi ' ],
96- 'mode ' => '' , // all but 'mod' and 'fast-cgi'
97- 'php_version ' => 0 ); // default;
98-
9993 if ($ fastcgi_config ["fastcgi_phpini_path " ] && $ fastcgi_config ["fastcgi_phpini_path " ] != $ web_config ['php_ini_path_cgi ' ]) {
10094 $ check_files [] = array ('file ' => $ fastcgi_config ["fastcgi_phpini_path " ],
10195 'mode ' => 'fast-cgi ' ,
@@ -106,6 +100,16 @@ public function check_phpini_changes() {
106100 'php_version ' => 0 ); // default;
107101 }
108102
103+ $ check_files [] = array ('file ' => $ web_config ['php_fpm_ini_path ' ],
104+ 'mode ' => 'php-fpm ' ,
105+ 'php_version ' => 0 ); // default;
106+
107+ if (!array_search ($ web_config ['php_ini_path_cgi ' ], array_column ($ check_files , 'file ' ))) {
108+ $ check_files [] = array ('file ' => $ web_config ['php_ini_path_cgi ' ],
109+ 'mode ' => '' , // all but 'mod' and 'fast-cgi'
110+ 'php_version ' => 0 ); // default;
111+ }
112+
109113
110114 //** read additional php versions of this server
111115 $ php_versions = $ app ->db ->queryAllRecords ('SELECT server_php_id, php_fastcgi_ini_dir, php_fpm_ini_dir FROM server_php WHERE server_id = ? ' , $ conf ['server_id ' ]);
@@ -114,7 +118,8 @@ public function check_phpini_changes() {
114118 $ check_files [] = array ('file ' => $ php ['php_fastcgi_ini_dir ' ] . '/php.ini ' ,
115119 'mode ' => 'fast-cgi ' ,
116120 'php_version ' => $ php ['server_php_id ' ]);
117- } elseif ($ php ['php_fpm_ini_dir ' ] && $ php ['php_fpm_ini_dir ' ] . '/php.ini ' != $ web_config ['php_ini_path_cgi ' ]) {
121+ }
122+ if ($ php ['php_fpm_ini_dir ' ] && $ php ['php_fpm_ini_dir ' ] . '/php.ini ' != $ web_config ['php_fpm_ini_path ' ]) {
118123 $ check_files [] = array ('file ' => $ php ['php_fpm_ini_dir ' ] . '/php.ini ' ,
119124 'mode ' => 'php-fpm ' ,
120125 'php_version ' => $ php ['server_php_id ' ]);
@@ -134,6 +139,13 @@ public function check_phpini_changes() {
134139 }
135140 if (!is_array ($ php_ini_md5 )) $ php_ini_md5 = array ();
136141
142+ // verify needed php file settings if that hasn't been done since 15 minutes
143+ $ now = time ();
144+ $ verify_php_ini =false ;
145+ if (!isset ($ php_ini_md5 ['last_verify_php_ini ' ]) || ($ now - intval ($ php_ini_md5 ['last_verify_php_ini ' ]) > 15 *60 )) {
146+ $ verify_php_ini =true ;
147+ }
148+
137149 $ processed = array ();
138150 foreach ($ check_files as $ file ) {
139151 $ file_path = $ file ['file ' ];
@@ -145,6 +157,11 @@ public function check_phpini_changes() {
145157 if (in_array ($ ident , $ processed ) == true ) continue ;
146158 $ processed [] = $ ident ;
147159
160+ //** check that needed php.ini settings/changes are made
161+ if ($ verify_php_ini ) {
162+ $ this ->verify_php_ini ($ file );
163+ }
164+
148165 //** check if md5sum of file changed
149166 $ file_md5 = md5_file ($ file_path );
150167 if (array_key_exists ($ file_path , $ php_ini_md5 ) == false || $ php_ini_md5 [$ file_path ] != $ file_md5 ) {
@@ -158,13 +175,32 @@ public function check_phpini_changes() {
158175 $ new_php_ini_md5 [$ file_path ] = $ file_md5 ;
159176 }
160177
178+ $ new_php_ini_md5 ['last_verify_php_ini ' ] = time ();
179+
161180 //** write new md5 sums if something changed
162- if ($ php_ini_changed == true ) $ app ->system ->file_put_contents (SCRIPT_PATH . '/temp/php.ini.md5sum ' , base64_encode (serialize ($ new_php_ini_md5 )));
181+ if ($ php_ini_changed == true || $ verify_php_ini == true ) $ app ->system ->file_put_contents (SCRIPT_PATH . '/temp/php.ini.md5sum ' , base64_encode (serialize ($ new_php_ini_md5 )));
163182 unset($ new_php_ini_md5 );
164183 unset($ php_ini_md5 );
165184 unset($ processed );
166185 }
167186
187+ /**
188+ * The method checks/sets needed php.ini settings
189+ */
190+ public function verify_php_ini ($ file ) {
191+ global $ app ;
192+
193+ if (isset ($ file ['file ' ]) && is_file ($ file ['file ' ])) {
194+ $ php_ini = $ file ['file ' ];
195+ // ensure opcache.validate_root = 1
196+ $ app ->system ->exec_safe ('grep ^opcache.validate_root ? ' , $ php_ini );
197+ if ($ app ->system ->last_exec_retcode () != 0 ) {
198+ $ app ->log ('verify_php_ini(): php.ini ' .$ php_ini .' is missing validate_root ' , LOGLEVEL_DEBUG );
199+ $ sed_script ='s/; *opcache\.validate_root *= *.+$/opcache.validate_root = 1/g ' ;
200+ $ app ->system ->exec_safe ('sed -E -i ? ? ' , $ sed_script , $ php_ini );
201+ }
202+ }
203+ }
168204
169205 /*
170206 * Checks for changes to jailkit settings in server config and schedules affected jails to be updated.
0 commit comments