Fix php version variable

This commit is contained in:
VirtuBox
2023-08-05 11:02:24 +02:00
parent 5c39f01670
commit 666f61e620

View File

@@ -483,29 +483,29 @@ def post_pref(self, apt_packages, packages, upgrade=False):
for php_version in php_list: for php_version in php_list:
WOGit.add(self, ["/etc/php"], msg="Adding PHP into Git") WOGit.add(self, ["/etc/php"], msg="Adding PHP into Git")
Log.info(self, "Configuring php{0}-fpm".format(php_version)) Log.info(self, "Configuring php{0}-fpm".format(php_version[0]))
ngxroot = '/var/www/' ngxroot = '/var/www/'
# Create log directories # Create log directories
if not os.path.exists('/var/log/php/{0}/'.format(php_version)): if not os.path.exists('/var/log/php/{0}/'.format(php_version[0])):
Log.debug( Log.debug(
self, 'Creating directory /var/log/php/{0}/' self, 'Creating directory /var/log/php/{0}/'
.format(php_version)) .format(php_version[0]))
os.makedirs('/var/log/php/{0}/'.format(php_version)) os.makedirs('/var/log/php/{0}/'.format(php_version[0]))
if not os.path.isfile( if not os.path.isfile(
'/etc/php/{0}/fpm/php.ini.orig'.format(php_version)): '/etc/php/{0}/fpm/php.ini.orig'.format(php_version[0])):
WOFileUtils.copyfile(self, WOFileUtils.copyfile(self,
'/etc/php/{0}/fpm/php.ini'.format( '/etc/php/{0}/fpm/php.ini'.format(
php_version), php_version[0]),
'/etc/php/{0}/fpm/php.ini.orig' '/etc/php/{0}/fpm/php.ini.orig'
.format(php_version)) .format(php_version[0]))
# Parse etc/php/x.x/fpm/php.ini # Parse etc/php/x.x/fpm/php.ini
config = configparser.ConfigParser() config = configparser.ConfigParser()
Log.debug(self, "configuring php file " Log.debug(self, "configuring php file "
"/etc/php/{0}/fpm/php.ini".format(php_version)) "/etc/php/{0}/fpm/php.ini".format(php_version[0]))
config.read('/etc/php/{0}/fpm/php.ini.orig'.format(php_version)) config.read('/etc/php/{0}/fpm/php.ini.orig'.format(php_version[0]))
config['PHP']['expose_php'] = 'Off' config['PHP']['expose_php'] = 'Off'
config['PHP']['post_max_size'] = '100M' config['PHP']['post_max_size'] = '100M'
config['PHP']['upload_max_filesize'] = '100M' config['PHP']['upload_max_filesize'] = '100M'
@@ -521,29 +521,29 @@ def post_pref(self, apt_packages, packages, upgrade=False):
config['opcache']['opcache.revalidate_freq'] = '5' config['opcache']['opcache.revalidate_freq'] = '5'
config['opcache']['opcache.consistency_checks'] = '0' config['opcache']['opcache.consistency_checks'] = '0'
config['opcache']['opcache.validate_timestamps'] = '1' config['opcache']['opcache.validate_timestamps'] = '1'
with open('/etc/php/{0}/fpm/php.ini'.format(php_version), with open('/etc/php/{0}/fpm/php.ini'.format(php_version[0]),
encoding='utf-8', mode='w') as configfile: encoding='utf-8', mode='w') as configfile:
Log.debug(self, "Writting php configuration into " Log.debug(self, "Writting php configuration into "
"/etc/php/{0}/fpm/php.ini".format(php_version)) "/etc/php/{0}/fpm/php.ini".format(php_version[0]))
config.write(configfile) config.write(configfile)
# Render php-fpm pool template for phpx.x # Render php-fpm pool template for phpx.x
data = dict(pid="/run/php/php{0}-fpm.pid".format(php_version), data = dict(pid="/run/php/php{0}-fpm.pid".format(php_version[0]),
error_log="/var/log/php{0}-fpm.log".format( error_log="/var/log/php{0}-fpm.log".format(
php_version), php_version[0]),
include="/etc/php/{0}/fpm/pool.d/*.conf" include="/etc/php/{0}/fpm/pool.d/*.conf"
.format(php_version)) .format(php_version[0]))
WOTemplate.deploy( WOTemplate.deploy(
self, '/etc/php/{0}/fpm/php-fpm.conf'.format(php_version), self, '/etc/php/{0}/fpm/php-fpm.conf'.format(php_version[0]),
'php-fpm.mustache', data) 'php-fpm.mustache', data)
php_short = php_version.replace(".", "") php_short = php_version[0].replace(".", "")
data = dict(pool='www-php{0}'.format(php_short), data = dict(pool='www-php{0}'.format(php_short),
listen='php{0}-fpm.sock'.format(php_short), listen='php{0}-fpm.sock'.format(php_short),
user='www-data', user='www-data',
group='www-data', listenuser='root', group='www-data', listenuser='root',
listengroup='www-data', openbasedir=True) listengroup='www-data', openbasedir=True)
WOTemplate.deploy(self, '/etc/php/{0}/fpm/pool.d/www.conf' WOTemplate.deploy(self, '/etc/php/{0}/fpm/pool.d/www.conf'
.format(php_version), .format(php_version[0]),
'php-pool.mustache', data) 'php-pool.mustache', data)
data = dict(pool='www-two-php{0}'.format(php_short), data = dict(pool='www-two-php{0}'.format(php_short),
listen='php{0}-two-fpm.sock'.format(php_short), listen='php{0}-two-fpm.sock'.format(php_short),
@@ -552,37 +552,39 @@ def post_pref(self, apt_packages, packages, upgrade=False):
listengroup='www-data', openbasedir=True) listengroup='www-data', openbasedir=True)
WOTemplate.deploy(self, WOTemplate.deploy(self,
'/etc/php/{0}/fpm/pool.d/www-two.conf'.format( '/etc/php/{0}/fpm/pool.d/www-two.conf'.format(
php_version), php_version[0]),
'php-pool.mustache', data) 'php-pool.mustache', data)
# Generate /etc/php/x.x/fpm/pool.d/debug.conf # Generate /etc/php/x.x/fpm/pool.d/debug.conf
WOFileUtils.copyfile(self, WOFileUtils.copyfile(self,
"/etc/php/{0}/fpm/pool.d/www.conf".format( "/etc/php/{0}/fpm/pool.d/www.conf".format(
php_version), php_version[0]),
"/etc/php/{0}/fpm/pool.d/debug.conf" "/etc/php/{0}/fpm/pool.d/debug.conf"
.format(php_version)) .format(php_version[0]))
WOFileUtils.searchreplace(self, WOFileUtils.searchreplace(self,
"/etc/php/{0}/fpm/pool.d/" "/etc/php/{0}/fpm/pool.d/"
"debug.conf".format(php_version), "debug.conf".format(php_version[0]),
"[www-php{0}]".format(php_short), "[www-php{0}]".format(php_short),
"[debug]") "[debug]")
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read( config.read(
'/etc/php/{0}/fpm/pool.d/debug.conf'.format(php_version)) '/etc/php/{0}/fpm/pool.d/debug.conf'.format(php_version[0]))
config['debug']['listen'] = '127.0.0.1:91{0}'.format(php_short) config['debug']['listen'] = '127.0.0.1:91{0}'.format(php_short)
config['debug']['rlimit_core'] = 'unlimited' config['debug']['rlimit_core'] = 'unlimited'
config['debug']['slowlog'] = '/var/log/php/{0}/slow.log'.format( config['debug']['slowlog'] = '/var/log/php/{0}/slow.log'.format(
php_version) php_version[0])
config['debug']['request_slowlog_timeout'] = '10s' config['debug']['request_slowlog_timeout'] = '10s'
with open('/etc/php/{0}/fpm/pool.d/debug.conf'.format(php_version), with open('/etc/php/{0}/fpm/pool.d/debug.conf'
.format(php_version[0]),
encoding='utf-8', mode='w') as confifile: encoding='utf-8', mode='w') as confifile:
Log.debug(self, Log.debug(self,
"writting PHP configuration into " "writting PHP configuration into "
"/etc/php/{0}/fpm/pool.d/debug.conf" "/etc/php/{0}/fpm/pool.d/debug.conf"
.format(php_version)) .format(php_version[0]))
config.write(confifile) config.write(confifile)
with open("/etc/php/{0}/fpm/pool.d/debug.conf".format(php_version), with open("/etc/php/{0}/fpm/pool.d/debug.conf"
.format(php_version[0]),
encoding='utf-8', mode='a') as myfile: encoding='utf-8', mode='a') as myfile:
myfile.write("php_admin_value[xdebug.profiler_output_dir] " myfile.write("php_admin_value[xdebug.profiler_output_dir] "
"= /tmp/ \nphp_admin_value[xdebug.profiler_" "= /tmp/ \nphp_admin_value[xdebug.profiler_"
@@ -594,10 +596,10 @@ def post_pref(self, apt_packages, packages, upgrade=False):
# Disable xdebug # Disable xdebug
if not WOShellExec.cmd_exec(self, "grep -q \';zend_extension\'" if not WOShellExec.cmd_exec(self, "grep -q \';zend_extension\'"
" /etc/php/{0}/mods-available/" " /etc/php/{0}/mods-available/"
"xdebug.ini".format(php_version)): "xdebug.ini".format(php_version[0])):
WOFileUtils.searchreplace(self, "/etc/php/{0}/" WOFileUtils.searchreplace(self, "/etc/php/{0}/"
"mods-available/" "mods-available/"
"xdebug.ini".format(php_version), "xdebug.ini".format(php_version[0]),
"zend_extension", "zend_extension",
";zend_extension") ";zend_extension")
@@ -650,7 +652,8 @@ def post_pref(self, apt_packages, packages, upgrade=False):
# check service restart or rollback configuration # check service restart or rollback configuration
if not WOService.restart_service(self, if not WOService.restart_service(self,
'php{0}-fpm'.format(php_version)): 'php{0}-fpm'
.format(php_version[0])):
WOGit.rollback(self, ["/etc/php"], msg="Rollback PHP") WOGit.rollback(self, ["/etc/php"], msg="Rollback PHP")
else: else:
WOGit.add(self, ["/etc/php"], msg="Adding PHP into Git") WOGit.add(self, ["/etc/php"], msg="Adding PHP into Git")