1212
1313abstract class AbstractGenerateConfig
1414{
15+ protected const PHP_VALUE_TOKEN = '@@VITO_PHP_VALUE@@ ' ;
16+
1517 /**
1618 * Generate the full vhost config for a site.
1719 */
@@ -26,7 +28,9 @@ public function generate(Site $site, ?string $template = null): string
2628 'escape ' => fn ($ value ) => $ value ,
2729 ]);
2830
29- return format_webserver_config ($ engine ->render ($ template , $ data ));
31+ $ rendered = format_webserver_config ($ engine ->render ($ template , $ data ));
32+
33+ return str_replace (self ::PHP_VALUE_TOKEN , $ data ['php_value_string ' ], $ rendered );
3034 }
3135
3236 /**
@@ -197,6 +201,9 @@ protected function buildCommonData(Site $site, string $primaryDomain): array
197201 $ isOctane = (bool ) data_get ($ site ->type_data , 'octane ' , false );
198202 $ isPhp = ($ siteTypeData ['is_php ' ] ?? false ) && ! $ isOctane ;
199203
204+ $ phpEnabled = $ isPhp && $ site ->vhost_template === null ;
205+ $ phpValueString = $ phpEnabled ? $ this ->phpValueDirectives ($ site ) : '' ;
206+
200207 $ basicAuth = data_get ($ site ->type_data , 'basic_auth ' , []);
201208 $ basicAuthEnabled = ! empty ($ basicAuth ['enabled ' ]) && ! empty ($ basicAuth ['users ' ]);
202209
@@ -211,6 +218,10 @@ protected function buildCommonData(Site $site, string $primaryDomain): array
211218 'is_octane ' => $ isOctane ,
212219 'octane_port ' => data_get ($ site ->type_data , 'octane_port ' , 8000 ),
213220 'php_socket ' => $ isPhp ? $ this ->buildPhpSocket ($ site ) : '' ,
221+ 'php_value ' => $ phpValueString !== '' ,
222+ 'php_value_string ' => $ phpValueString ,
223+ 'php_max_upload_size ' => $ phpEnabled ? $ this ->phpSetting ($ site , 'max_upload_size ' ) : null ,
224+ 'php_max_execution_time ' => $ phpEnabled ? $ this ->phpSetting ($ site , 'max_execution_time ' ) : null ,
214225 'port ' => $ site ->port ,
215226 'redirects ' => $ this ->buildRedirects ($ site ),
216227 'type_data ' => $ site ->type_data ?? [],
@@ -240,6 +251,7 @@ protected function enrichServerBlocks(array $blocks, array $data): array
240251 $ block ['is_octane ' ] = $ data ['is_octane ' ];
241252 $ block ['octane_port ' ] = $ data ['octane_port ' ];
242253 $ block ['php_socket ' ] = $ data ['php_socket ' ];
254+ $ block ['php_value ' ] = $ data ['php_value ' ];
243255 $ block ['port ' ] = $ data ['port ' ];
244256 $ block ['redirects ' ] = $ data ['redirects ' ];
245257 $ block ['basic_auth_enabled ' ] = $ data ['basic_auth_enabled ' ];
@@ -266,4 +278,44 @@ protected function buildRedirects(Site $site): array
266278
267279 return $ redirects ;
268280 }
281+
282+ /**
283+ * Build the multi-line PHP_VALUE directive string from the site's
284+ * per-site PHP settings (type_data['php']). Empty when nothing is set.
285+ */
286+ protected function phpValueDirectives (Site $ site ): string
287+ {
288+ $ directives = [];
289+
290+ $ upload = $ this ->phpSetting ($ site , 'max_upload_size ' );
291+ if ($ upload !== null ) {
292+ $ directives [] = "upload_max_filesize= {$ upload }M " ;
293+ $ directives [] = "post_max_size= {$ upload }M " ;
294+ }
295+
296+ $ execution = $ this ->phpSetting ($ site , 'max_execution_time ' );
297+ if ($ execution !== null ) {
298+ $ directives [] = "max_execution_time= {$ execution }" ;
299+ $ directives [] = "max_input_time= {$ execution }" ;
300+ }
301+
302+ $ memory = $ this ->phpSetting ($ site , 'memory_limit ' );
303+ if ($ memory !== null ) {
304+ $ directives [] = "memory_limit= {$ memory }M " ;
305+ }
306+
307+ $ inputVars = $ this ->phpSetting ($ site , 'max_input_vars ' );
308+ if ($ inputVars !== null ) {
309+ $ directives [] = "max_input_vars= {$ inputVars }" ;
310+ }
311+
312+ return implode ("\n" , $ directives );
313+ }
314+
315+ protected function phpSetting (Site $ site , string $ key ): ?int
316+ {
317+ $ value = data_get ($ site ->type_data , "php. {$ key }" );
318+
319+ return is_numeric ($ value ) ? (int ) $ value : null ;
320+ }
269321}
0 commit comments