This commit is contained in:
Janio Sarmento
2022-01-23 15:14:24 -03:00
parent b4476d3aa7
commit 555269decf
11 changed files with 943 additions and 45 deletions

View File

@@ -229,7 +229,7 @@ def post_pref(self, apt_packages, packages, upgrade=False):
.format(ngxcom),
'wpsubdir.mustache', data)
wo_php_version = ["php72", "php73", "php74"]
wo_php_version = ["php72", "php73", "php74", "php80" "php81"]
for wo_php in wo_php_version:
data = dict(upstream="{0}".format(wo_php),
release=WOVar.wo_version)
@@ -922,6 +922,330 @@ def post_pref(self, apt_packages, packages, upgrade=False):
'upstream.mustache', data, True)
WOConf.nginxcommon(self)
# php8.0 configuration
if set(WOVar.wo_php80).issubset(set(apt_packages)):
WOGit.add(self, ["/etc/php"], msg="Adding PHP into Git")
Log.info(self, "Configuring php8.0-fpm")
ngxroot = '/var/www/'
# Create log directories
if not os.path.exists('/var/log/php/8.0/'):
Log.debug(self, 'Creating directory /var/log/php/8.0/')
os.makedirs('/var/log/php/8.0/')
if not os.path.isfile('/etc/php/8.0/fpm/php.ini.orig'):
WOFileUtils.copyfile(self, '/etc/php/8.0/fpm/php.ini',
'/etc/php/8.0/fpm/php.ini.orig')
# Parse etc/php/8.0/fpm/php.ini
config = configparser.ConfigParser()
Log.debug(self, "configuring php file /etc/php/8.0/"
"fpm/php.ini")
config.read('/etc/php/8.0/fpm/php.ini.orig')
config['PHP']['expose_php'] = 'Off'
config['PHP']['post_max_size'] = '100M'
config['PHP']['upload_max_filesize'] = '100M'
config['PHP']['max_execution_time'] = '300'
config['PHP']['max_input_time'] = '300'
config['PHP']['max_input_vars'] = '20000'
config['Date']['date.timezone'] = WOVar.wo_timezone
config['opcache']['opcache.enable'] = '1'
config['opcache']['opcache.interned_strings_buffer'] = '8'
config['opcache']['opcache.max_accelerated_files'] = '10000'
config['opcache']['opcache.memory_consumption'] = '256'
config['opcache']['opcache.save_comments'] = '1'
config['opcache']['opcache.revalidate_freq'] = '5'
config['opcache']['opcache.consistency_checks'] = '0'
config['opcache']['opcache.validate_timestamps'] = '1'
config['opcache']['opcache.preload_user'] = 'www-data'
with open('/etc/php/8.0/fpm/php.ini',
encoding='utf-8', mode='w') as configfile:
Log.debug(self, "Writting php configuration into "
"/etc/php/8.0/fpm/php.ini")
config.write(configfile)
# Render php-fpm pool template for php8.0
data = dict(pid="/run/php/php8.0-fpm.pid",
error_log="/var/log/php8.0-fpm.log",
include="/etc/php/8.0/fpm/pool.d/*.conf")
WOTemplate.deploy(
self, '/etc/php/8.0/fpm/php-fpm.conf',
'php-fpm.mustache', data)
data = dict(pool='www-php80', listen='php80-fpm.sock',
user='www-data',
group='www-data', listenuser='root',
listengroup='www-data', openbasedir=True)
WOTemplate.deploy(self, '/etc/php/8.0/fpm/pool.d/www.conf',
'php-pool.mustache', data)
data = dict(pool='www-two-php80', listen='php80-two-fpm.sock',
user='www-data',
group='www-data', listenuser='root',
listengroup='www-data', openbasedir=True)
WOTemplate.deploy(self, '/etc/php/8.0/fpm/pool.d/www-two.conf',
'php-pool.mustache', data)
# Generate /etc/php/8.0/fpm/pool.d/debug.conf
WOFileUtils.copyfile(self, "/etc/php/8.0/fpm/pool.d/www.conf",
"/etc/php/8.0/fpm/pool.d/debug.conf")
WOFileUtils.searchreplace(self, "/etc/php/8.0/fpm/pool.d/"
"debug.conf", "[www-php80]", "[debug]")
config = configparser.ConfigParser()
config.read('/etc/php/8.0/fpm/pool.d/debug.conf')
config['debug']['listen'] = '127.0.0.1:9180'
config['debug']['rlimit_core'] = 'unlimited'
config['debug']['slowlog'] = '/var/log/php/8.0/slow.log'
config['debug']['request_slowlog_timeout'] = '10s'
with open('/etc/php/8.0/fpm/pool.d/debug.conf',
encoding='utf-8', mode='w') as confifile:
Log.debug(self, "writting PHP 8.0 configuration into "
"/etc/php/8.0/fpm/pool.d/debug.conf")
config.write(confifile)
with open("/etc/php/8.0/fpm/pool.d/debug.conf",
encoding='utf-8', mode='a') as myfile:
myfile.write(
"php_admin_value[xdebug.profiler_output_dir] "
"= /tmp/ \nphp_admin_value[xdebug.profiler_"
"output_name] = cachegrind.out.%p-%H-%R "
"\nphp_admin_flag[xdebug.profiler_enable"
"_trigger] = on \nphp_admin_flag[xdebug."
"profiler_enable] = off\n")
# Disable xdebug
if not WOShellExec.cmd_exec(
self, "grep -q \';zend_extension\'"
" /etc/php/8.0/mods-available/xdebug.ini"):
WOFileUtils.searchreplace(
self, "/etc/php/8.0/mods-available/"
"xdebug.ini",
"zend_extension", ";zend_extension")
# PHP and Debug pull configuration
if not os.path.exists('{0}22222/htdocs/fpm/status/'
.format(ngxroot)):
Log.debug(self, 'Creating directory '
'{0}22222/htdocs/fpm/status/ '
.format(ngxroot))
os.makedirs('{0}22222/htdocs/fpm/status/'
.format(ngxroot))
open('{0}22222/htdocs/fpm/status/debug80'
.format(ngxroot),
encoding='utf-8', mode='a').close()
open('{0}22222/htdocs/fpm/status/php80'
.format(ngxroot),
encoding='utf-8', mode='a').close()
# Write info.php
if not os.path.exists('{0}22222/htdocs/php/'
.format(ngxroot)):
Log.debug(self, 'Creating directory '
'{0}22222/htdocs/php/ '
.format(ngxroot))
os.makedirs('{0}22222/htdocs/php'
.format(ngxroot))
WOFileUtils.textwrite(
self, "{0}22222/htdocs/php/info.php"
.format(ngxroot), "<?php\nphpinfo();\n?>")
# write opcache clean for php80
if not os.path.exists('{0}22222/htdocs/cache/opcache'
.format(ngxroot)):
os.makedirs('{0}22222/htdocs/cache/opcache'
.format(ngxroot))
WOFileUtils.textwrite(
self, '{0}22222/htdocs/cache/opcache/php80.php'
.format(ngxroot),
'<?php opcache_reset(); ?>')
WOFileUtils.chown(self, "{0}22222/htdocs"
.format(ngxroot),
'www-data',
'www-data', recursive=True)
# enable imagick php extension
WOShellExec.cmd_exec(self, 'phpenmod -v ALL imagick')
# check service restart or rollback configuration
if not WOService.restart_service(self, 'php8.0-fpm'):
WOGit.rollback(self, ["/etc/php"], msg="Rollback PHP")
else:
WOGit.add(self, ["/etc/php"], msg="Adding PHP into Git")
if os.path.exists('/etc/nginx/conf.d/upstream.conf'):
if not WOFileUtils.grepcheck(
self, '/etc/nginx/conf.d/upstream.conf', 'php81'):
data = dict(php="9000", debug="9001",
php7="9070", debug7="9170",
php8="9080", debug8="9180",
release=WOVar.wo_version)
WOTemplate.deploy(
self, '/etc/nginx/conf.d/upstream.conf',
'upstream.mustache', data, True)
WOConf.nginxcommon(self)
# php8.1 configuration
if set(WOVar.wo_php81).issubset(set(apt_packages)):
WOGit.add(self, ["/etc/php"], msg="Adding PHP into Git")
Log.info(self, "Configuring php8.1-fpm")
ngxroot = '/var/www/'
# Create log directories
if not os.path.exists('/var/log/php/8.1/'):
Log.debug(self, 'Creating directory /var/log/php/8.1/')
os.makedirs('/var/log/php/8.1/')
if not os.path.isfile('/etc/php/8.1/fpm/php.ini.orig'):
WOFileUtils.copyfile(self, '/etc/php/8.1/fpm/php.ini',
'/etc/php/8.1/fpm/php.ini.orig')
# Parse etc/php/8.1/fpm/php.ini
config = configparser.ConfigParser()
Log.debug(self, "configuring php file /etc/php/8.1/"
"fpm/php.ini")
config.read('/etc/php/8.1/fpm/php.ini.orig')
config['PHP']['expose_php'] = 'Off'
config['PHP']['post_max_size'] = '100M'
config['PHP']['upload_max_filesize'] = '100M'
config['PHP']['max_execution_time'] = '300'
config['PHP']['max_input_time'] = '300'
config['PHP']['max_input_vars'] = '20000'
config['Date']['date.timezone'] = WOVar.wo_timezone
config['opcache']['opcache.enable'] = '1'
config['opcache']['opcache.interned_strings_buffer'] = '8'
config['opcache']['opcache.max_accelerated_files'] = '10000'
config['opcache']['opcache.memory_consumption'] = '256'
config['opcache']['opcache.save_comments'] = '1'
config['opcache']['opcache.revalidate_freq'] = '5'
config['opcache']['opcache.consistency_checks'] = '0'
config['opcache']['opcache.validate_timestamps'] = '1'
config['opcache']['opcache.preload_user'] = 'www-data'
with open('/etc/php/8.1/fpm/php.ini',
encoding='utf-8', mode='w') as configfile:
Log.debug(self, "Writting php configuration into "
"/etc/php/8.1/fpm/php.ini")
config.write(configfile)
# Render php-fpm pool template for php8.1
data = dict(pid="/run/php/php8.1-fpm.pid",
error_log="/var/log/php8.1-fpm.log",
include="/etc/php/8.1/fpm/pool.d/*.conf")
WOTemplate.deploy(
self, '/etc/php/8.1/fpm/php-fpm.conf',
'php-fpm.mustache', data)
data = dict(pool='www-php81', listen='php81-fpm.sock',
user='www-data',
group='www-data', listenuser='root',
listengroup='www-data', openbasedir=True)
WOTemplate.deploy(self, '/etc/php/8.1/fpm/pool.d/www.conf',
'php-pool.mustache', data)
data = dict(pool='www-two-php81', listen='php81-two-fpm.sock',
user='www-data',
group='www-data', listenuser='root',
listengroup='www-data', openbasedir=True)
WOTemplate.deploy(self, '/etc/php/8.1/fpm/pool.d/www-two.conf',
'php-pool.mustache', data)
# Generate /etc/php/8.1/fpm/pool.d/debug.conf
WOFileUtils.copyfile(self, "/etc/php/8.1/fpm/pool.d/www.conf",
"/etc/php/8.1/fpm/pool.d/debug.conf")
WOFileUtils.searchreplace(self, "/etc/php/8.1/fpm/pool.d/"
"debug.conf", "[www-php81]", "[debug]")
config = configparser.ConfigParser()
config.read('/etc/php/8.1/fpm/pool.d/debug.conf')
config['debug']['listen'] = '127.0.0.1:9181'
config['debug']['rlimit_core'] = 'unlimited'
config['debug']['slowlog'] = '/var/log/php/8.1/slow.log'
config['debug']['request_slowlog_timeout'] = '10s'
with open('/etc/php/8.1/fpm/pool.d/debug.conf',
encoding='utf-8', mode='w') as confifile:
Log.debug(self, "writting PHP 8.1 configuration into "
"/etc/php/8.1/fpm/pool.d/debug.conf")
config.write(confifile)
with open("/etc/php/8.1/fpm/pool.d/debug.conf",
encoding='utf-8', mode='a') as myfile:
myfile.write(
"php_admin_value[xdebug.profiler_output_dir] "
"= /tmp/ \nphp_admin_value[xdebug.profiler_"
"output_name] = cachegrind.out.%p-%H-%R "
"\nphp_admin_flag[xdebug.profiler_enable"
"_trigger] = on \nphp_admin_flag[xdebug."
"profiler_enable] = off\n")
# Disable xdebug
if not WOShellExec.cmd_exec(
self, "grep -q \';zend_extension\'"
" /etc/php/8.1/mods-available/xdebug.ini"):
WOFileUtils.searchreplace(
self, "/etc/php/8.1/mods-available/"
"xdebug.ini",
"zend_extension", ";zend_extension")
# PHP and Debug pull configuration
if not os.path.exists('{0}22222/htdocs/fpm/status/'
.format(ngxroot)):
Log.debug(self, 'Creating directory '
'{0}22222/htdocs/fpm/status/ '
.format(ngxroot))
os.makedirs('{0}22222/htdocs/fpm/status/'
.format(ngxroot))
open('{0}22222/htdocs/fpm/status/debug81'
.format(ngxroot),
encoding='utf-8', mode='a').close()
open('{0}22222/htdocs/fpm/status/php81'
.format(ngxroot),
encoding='utf-8', mode='a').close()
# Write info.php
if not os.path.exists('{0}22222/htdocs/php/'
.format(ngxroot)):
Log.debug(self, 'Creating directory '
'{0}22222/htdocs/php/ '
.format(ngxroot))
os.makedirs('{0}22222/htdocs/php'
.format(ngxroot))
WOFileUtils.textwrite(
self, "{0}22222/htdocs/php/info.php"
.format(ngxroot), "<?php\nphpinfo();\n?>")
# write opcache clean for php81
if not os.path.exists('{0}22222/htdocs/cache/opcache'
.format(ngxroot)):
os.makedirs('{0}22222/htdocs/cache/opcache'
.format(ngxroot))
WOFileUtils.textwrite(
self, '{0}22222/htdocs/cache/opcache/php81.php'
.format(ngxroot),
'<?php opcache_reset(); ?>')
WOFileUtils.chown(self, "{0}22222/htdocs"
.format(ngxroot),
'www-data',
'www-data', recursive=True)
# enable imagick php extension
WOShellExec.cmd_exec(self, 'phpenmod -v ALL imagick')
# check service restart or rollback configuration
if not WOService.restart_service(self, 'php8.1-fpm'):
WOGit.rollback(self, ["/etc/php"], msg="Rollback PHP")
else:
WOGit.add(self, ["/etc/php"], msg="Adding PHP into Git")
if os.path.exists('/etc/nginx/conf.d/upstream.conf'):
if not WOFileUtils.grepcheck(
self, '/etc/nginx/conf.d/upstream.conf', 'php81'):
data = dict(php="9000", debug="9001",
php7="9070", debug7="9170",
php8="9080", debug8="9180",
release=WOVar.wo_version)
WOTemplate.deploy(
self, '/etc/nginx/conf.d/upstream.conf',
'upstream.mustache', data, True)
WOConf.nginxcommon(self)
# create mysql config if it doesn't exist
if "mariadb-server" in apt_packages:
WOGit.add(self, ["/etc/mysql"], msg="Adding MySQL into Git")