Merge pull request #558 from WordOps/updating-configuration

Add site alias and refactor php stack
This commit is contained in:
VirtuBox
2023-08-12 15:47:35 +02:00
committed by GitHub
7 changed files with 114 additions and 164 deletions

View File

@@ -9,6 +9,7 @@ from pynginxconfig import NginxConfig
from wo.core.aptget import WOAptGet from wo.core.aptget import WOAptGet
from wo.core.logging import Log from wo.core.logging import Log
from wo.core.shellexec import WOShellExec from wo.core.shellexec import WOShellExec
from wo.core.variables import WOVar
def wo_info_hook(app): def wo_info_hook(app):
@@ -27,28 +28,17 @@ class WOInfoController(CementBaseController):
dict(help='Get MySQL configuration information', dict(help='Get MySQL configuration information',
action='store_true')), action='store_true')),
(['--php'], (['--php'],
dict(help='Get PHP 7.2 configuration information', dict(help='Get PHP configuration information',
action='store_true')),
(['--php73'],
dict(help='Get PHP 7.3 configuration information',
action='store_true')),
(['--php74'],
dict(help='Get PHP 7.4 configuration information',
action='store_true')),
(['--php80'],
dict(help='Get PHP 8.0 configuration information',
action='store_true')),
(['--php81'],
dict(help='Get PHP 8.1 configuration information',
action='store_true')),
(['--php82'],
dict(help='Get PHP 8.2 configuration information',
action='store_true')), action='store_true')),
(['--nginx'], (['--nginx'],
dict(help='Get Nginx configuration information', dict(help='Get Nginx configuration information',
action='store_true')), action='store_true')),
] ]
usage = "wo info [options]" usage = "wo info [options]"
for php_version, php_number in WOVar.wo_php_versions.items():
arguments.append(([f'--{php_version}'],
dict(help=f'Get PHP {php_number} configuration information',
action='store_true')))
@expose(hide=True) @expose(hide=True)
def info_nginx(self): def info_nginx(self):

View File

@@ -32,19 +32,7 @@ class WOSiteCreateController(CementBaseController):
(['--html'], (['--html'],
dict(help="create html site", action='store_true')), dict(help="create html site", action='store_true')),
(['--php'], (['--php'],
dict(help="create php 7.2 site", action='store_true')), dict(help="create php site", action='store_true')),
(['--php72'],
dict(help="create php 7.2 site", action='store_true')),
(['--php73'],
dict(help="create php 7.3 site", action='store_true')),
(['--php74'],
dict(help="create php 7.4 site", action='store_true')),
(['--php80'],
dict(help="create php 8.0 site", action='store_true')),
(['--php81'],
dict(help="create php 8.1 site", action='store_true')),
(['--php82'],
dict(help="create php 8.2 site", action='store_true')),
(['--mysql'], (['--mysql'],
dict(help="create mysql site", action='store_true')), dict(help="create mysql site", action='store_true')),
(['--wp'], (['--wp'],
@@ -73,6 +61,9 @@ class WOSiteCreateController(CementBaseController):
dict(help="create WordPress single/multi site " dict(help="create WordPress single/multi site "
"with redis cache", "with redis cache",
action='store_true')), action='store_true')),
(['--alias'],
dict(help="domain name to redirect to",
action='store', nargs='?')),
(['-le', '--letsencrypt'], (['-le', '--letsencrypt'],
dict(help="configure letsencrypt ssl for the site", dict(help="configure letsencrypt ssl for the site",
action='store' or 'store_const', action='store' or 'store_const',
@@ -107,6 +98,10 @@ class WOSiteCreateController(CementBaseController):
"without installing WordPress", "without installing WordPress",
action='store_true')), action='store_true')),
] ]
for php_version, php_number in WOVar.wo_php_versions.items():
arguments.append(([f'--{php_version}'],
dict(help=f'Create PHP {php_number} site',
action='store_true')))
@expose(hide=True) @expose(hide=True)
def default(self): def default(self):
@@ -129,10 +124,17 @@ class WOSiteCreateController(CementBaseController):
proxyinfo = proxyinfo.split(':') proxyinfo = proxyinfo.split(':')
host = proxyinfo[0].strip() host = proxyinfo[0].strip()
port = '80' if len(proxyinfo) < 2 else proxyinfo[1].strip() port = '80' if len(proxyinfo) < 2 else proxyinfo[1].strip()
elif stype is None and not pargs.proxy: elif stype is None and not pargs.proxy and not pargs.alias:
stype, cache = 'html', 'basic' stype, cache = 'html', 'basic'
elif stype is None and pargs.alias:
stype, cache = 'alias', ''
alias_name = pargs.alias.strip()
if not alias_name:
Log.error(self, "Please provide alias name")
elif stype and pargs.proxy: elif stype and pargs.proxy:
Log.error(self, "proxy should not be used with other site types") Log.error(self, "proxy should not be used with other site types")
elif stype and pargs.alias:
Log.error(self, "alias should not be used with other site types")
if not pargs.site_name: if not pargs.site_name:
try: try:
@@ -173,6 +175,16 @@ class WOSiteCreateController(CementBaseController):
data['port'] = port data['port'] = port
data['basic'] = True data['basic'] = True
if stype == 'alias':
data = dict(
site_name=wo_domain, www_domain=wo_www_domain,
static=True, basic=False, wp=False,
wpfc=False, wpsc=False, wprocket=False, wpce=False,
multisite=False, wpsubdir=False, webroot=wo_site_webroot)
data['alias'] = True
data['alias_name'] = alias_name
data['basic'] = True
if (pargs.php72 or pargs.php73 or pargs.php74 or if (pargs.php72 or pargs.php73 or pargs.php74 or
pargs.php80 or pargs.php81 or pargs.php82): pargs.php80 or pargs.php81 or pargs.php82):
data = dict( data = dict(
@@ -218,57 +230,27 @@ class WOSiteCreateController(CementBaseController):
else: else:
pass pass
data['php73'] = False # Initialize all PHP versions to False
data['php74'] = False for version in WOVar.wo_php_versions:
data['php72'] = False data[version] = False
data['php80'] = False
data['php81'] = False
data['php82'] = False
if data and pargs.php73:
data['php73'] = True
data['wo_php'] = 'php73'
elif data and pargs.php74:
data['php74'] = True
data['wo_php'] = 'php74'
elif data and pargs.php72:
data['php72'] = True
data['wo_php'] = 'php72'
elif data and pargs.php80:
data['php80'] = True
data['wo_php'] = 'php80'
elif data and pargs.php81:
data['php81'] = True
data['wo_php'] = 'php81'
elif data and pargs.php82:
data['php82'] = True
data['wo_php'] = 'php82'
# Check for PHP versions in pargs
for pargs_version, version in WOVar.wo_php_versions.items():
if data and getattr(pargs, pargs_version, False):
data[pargs_version] = True
data['wo_php'] = pargs_version
php_version = version
break
else: else:
if self.app.config.has_section('php'): if self.app.config.has_section('php'):
config_php_ver = self.app.config.get( config_php_ver = self.app.config.get('php', 'version')
'php', 'version')
if config_php_ver == '7.2': for wo_key, php_ver in WOVar.wo_php_versions.items():
data['php72'] = True if php_ver == config_php_ver:
data['wo_php'] = 'php72' data[wo_key] = True
elif config_php_ver == '7.3': data['wo_php'] = wo_key
data['php73'] = True php_version = php_ver
data['wo_php'] = 'php73' break
elif config_php_ver == '7.4':
data['php74'] = True
data['wo_php'] = 'php74'
elif config_php_ver == '8.0':
data['php80'] = True
data['wo_php'] = 'php80'
elif config_php_ver == '8.1':
data['php81'] = True
data['wo_php'] = 'php81'
elif config_php_ver == '8.2':
data['php82'] = True
data['wo_php'] = 'php82'
else:
data['php73'] = True
data['wo_php'] = 'php73'
if ((not pargs.wpfc) and (not pargs.wpsc) and if ((not pargs.wpfc) and (not pargs.wpsc) and
(not pargs.wprocket) and (not pargs.wprocket) and
@@ -331,18 +313,26 @@ class WOSiteCreateController(CementBaseController):
" http://{0}".format(wo_domain)) " http://{0}".format(wo_domain))
return return
if data['php72']: if 'alias' in data.keys() and data['alias']:
php_version = "7.2" addNewSite(self, wo_domain, stype, cache, wo_site_webroot)
elif data['php74']: # Service Nginx Reload
php_version = "7.4" if not WOService.reload_service(self, 'nginx'):
elif data['php80']: Log.info(self, Log.FAIL +
php_version = "8.0" "There was a serious error encountered...")
elif data['php81']: Log.info(self, Log.FAIL + "Cleaning up afterwards...")
php_version = "8.1" doCleanupAction(self, domain=wo_domain)
elif data['php82']: deleteSiteInfo(self, wo_domain)
php_version = "8.2" Log.error(self, "service nginx reload failed. "
else: "check issues with `nginx -t` command")
php_version = "7.3" Log.error(self, "Check the log for details: "
"`tail /var/log/wo/wordops.log` "
"and please try again")
if wo_auth and len(wo_auth):
for msg in wo_auth:
Log.info(self, Log.ENDC + msg, log=False)
Log.info(self, "Successfully created site"
" http://{0}".format(wo_domain))
return
addNewSite(self, wo_domain, stype, cache, wo_site_webroot, addNewSite(self, wo_domain, stype, cache, wo_site_webroot,
php_version=php_version) php_version=php_version)

View File

@@ -41,18 +41,6 @@ class WOSiteUpdateController(CementBaseController):
dict(help="update to html site", action='store_true')), dict(help="update to html site", action='store_true')),
(['--php'], (['--php'],
dict(help="update to php site", action='store_true')), dict(help="update to php site", action='store_true')),
(['--php72'],
dict(help="update to php72 site", action='store_true')),
(['--php73'],
dict(help="update to php73 site", action='store_true')),
(['--php74'],
dict(help="update to php74 site", action='store_true')),
(['--php80'],
dict(help="update to php80 site", action='store_true')),
(['--php81'],
dict(help="update to php81 site", action='store_true')),
(['--php82'],
dict(help="update to php82 site", action='store_true')),
(['--mysql'], (['--mysql'],
dict(help="update to mysql site", action='store_true')), dict(help="update to mysql site", action='store_true')),
(['--wp'], (['--wp'],
@@ -104,6 +92,10 @@ class WOSiteUpdateController(CementBaseController):
(['--all'], (['--all'],
dict(help="update all sites", action='store_true')), dict(help="update all sites", action='store_true')),
] ]
for php_version, php_number in WOVar.wo_php_versions.items():
arguments.append(([f'--{php_version}'],
dict(help=f'Update site to PHP {php_number}',
action='store_true')))
@expose(help="Update site type or cache") @expose(help="Update site type or cache")
def default(self): def default(self):

View File

@@ -11,7 +11,7 @@ from wo.core.logging import Log
def addNewSite(self, site, stype, cache, path, def addNewSite(self, site, stype, cache, path,
enabled=True, ssl=False, fs='ext4', db='mysql', enabled=True, ssl=False, fs='ext4', db='mysql',
db_name=None, db_user=None, db_password=None, db_name=None, db_user=None, db_password=None,
db_host='localhost', hhvm=0, php_version='7.2'): db_host='localhost', hhvm=0, php_version='8.1'):
""" """
Add New Site record information into the wo database. Add New Site record information into the wo database.
""" """

View File

@@ -41,18 +41,6 @@ class WOStackController(CementBaseController):
dict(help='Install Nginx stack', action='store_true')), dict(help='Install Nginx stack', action='store_true')),
(['--php'], (['--php'],
dict(help='Install PHP 7.2 stack', action='store_true')), dict(help='Install PHP 7.2 stack', action='store_true')),
(['--php72'],
dict(help='Install PHP 7.2 stack', action='store_true')),
(['--php73'],
dict(help='Install PHP 7.3 stack', action='store_true')),
(['--php74'],
dict(help='Install PHP 7.4 stack', action='store_true')),
(['--php80'],
dict(help='Install PHP 8.0 stack', action='store_true')),
(['--php81'],
dict(help='Install PHP 8.1 stack', action='store_true')),
(['--php82'],
dict(help='Install PHP 8.2 stack', action='store_true')),
(['--mysql'], (['--mysql'],
dict(help='Install MySQL stack', action='store_true')), dict(help='Install MySQL stack', action='store_true')),
(['--mariadb'], (['--mariadb'],
@@ -106,6 +94,11 @@ class WOStackController(CementBaseController):
dict(help='Force install/remove/purge without prompt', dict(help='Force install/remove/purge without prompt',
action='store_true')), action='store_true')),
] ]
for php_version, php_number in WOVar.wo_php_versions.items():
arguments.append(([f'--{php_version}'],
dict(help=f'Install PHP {php_number} stack',
action='store_true')))
usage = "wo stack (command) [options]" usage = "wo stack (command) [options]"
@expose(hide=True) @expose(hide=True)

View File

@@ -33,18 +33,6 @@ class WOStackUpgradeController(CementBaseController):
dict(help='Upgrade Nginx stack', action='store_true')), dict(help='Upgrade Nginx stack', action='store_true')),
(['--php'], (['--php'],
dict(help='Upgrade PHP 7.2 stack', action='store_true')), dict(help='Upgrade PHP 7.2 stack', action='store_true')),
(['--php72'],
dict(help='Upgrade PHP 7.2 stack', action='store_true')),
(['--php73'],
dict(help='Upgrade PHP 7.3 stack', action='store_true')),
(['--php74'],
dict(help='Upgrade PHP 7.4 stack', action='store_true')),
(['--php80'],
dict(help='Upgrade PHP 8.0 stack', action='store_true')),
(['--php81'],
dict(help='Upgrade PHP 8.1 stack', action='store_true')),
(['--php82'],
dict(help='Upgrade PHP 8.2 stack', action='store_true')),
(['--mysql'], (['--mysql'],
dict(help='Upgrade MySQL stack', action='store_true')), dict(help='Upgrade MySQL stack', action='store_true')),
(['--mariadb'], (['--mariadb'],
@@ -77,6 +65,10 @@ class WOStackUpgradeController(CementBaseController):
dict(help="Force Packages upgrade without any prompt", dict(help="Force Packages upgrade without any prompt",
action='store_true')), action='store_true')),
] ]
for php_version, php_number in WOVar.wo_php_versions.items():
arguments.append(([f'--{php_version}'],
dict(help=f'Upgrade PHP {php_number} stack',
action='store_true')))
@expose(hide=True) @expose(hide=True)
def default(self, disp_msg=False): def default(self, disp_msg=False):
@@ -102,7 +94,11 @@ class WOStackUpgradeController(CementBaseController):
pargs.mysql = True pargs.mysql = True
if pargs.php: if pargs.php:
pargs.php81 = True if self.app.config.has_section('php'):
config_php_ver = self.app.config.get(
'php', 'version')
current_php = config_php_ver.replace(".", "")
setattr(self.app.pargs, 'php{0}'.format(current_php), True)
if pargs.all: if pargs.all:
pargs.web = True pargs.web = True
@@ -145,41 +141,23 @@ class WOStackUpgradeController(CementBaseController):
else: else:
Log.info(self, "Nginx Stable is not already installed") Log.info(self, "Nginx Stable is not already installed")
# php 7.2 wo_vars = {
if pargs.php72: 'php72': WOVar.wo_php72,
if WOAptGet.is_installed(self, 'php7.2-fpm'): 'php73': WOVar.wo_php73,
apt_packages = apt_packages + WOVar.wo_php72 + \ 'php74': WOVar.wo_php74,
WOVar.wo_php_extra 'php80': WOVar.wo_php80,
'php81': WOVar.wo_php81,
'php82': WOVar.wo_php82,
}
# php 7.3 for parg_version, version in WOVar.wo_php_versions.items():
if pargs.php73: if getattr(pargs, parg_version, False):
if WOAptGet.is_installed(self, 'php7.3-fpm'): Log.debug(self, f"Setting apt_packages variable for PHP {version}")
apt_packages = apt_packages + WOVar.wo_php73 + \ if WOAptGet.is_installed(self, f'php{version}-fpm'):
WOVar.wo_php_extra apt_packages = apt_packages + wo_vars[parg_version] + WOVar.wo_php_extra
else:
# php 7.4 Log.debug(self, f"PHP {version} not installed")
if pargs.php74: Log.info(self, f"PHP {version} not installed")
if WOAptGet.is_installed(self, 'php7.4-fpm'):
apt_packages = apt_packages + WOVar.wo_php74 + \
WOVar.wo_php_extra
# php 8.0
if pargs.php80:
if WOAptGet.is_installed(self, 'php8.0-fpm'):
apt_packages = apt_packages + WOVar.wo_php80 + \
WOVar.wo_php_extra
# php 8.1
if pargs.php81:
if WOAptGet.is_installed(self, 'php8.1-fpm'):
apt_packages = apt_packages + WOVar.wo_php81 + \
WOVar.wo_php_extra
# php 8.2
if pargs.php82:
if WOAptGet.is_installed(self, 'php8.2-fpm'):
apt_packages = apt_packages + WOVar.wo_php82 + \
WOVar.wo_php_extra
# mysql # mysql
if pargs.mysql: if pargs.mysql:

View File

@@ -16,6 +16,11 @@ server {
access_log /var/log/nginx/{{site_name}}.access.log {{^wpredis}}{{^static}}rt_cache{{/static}}{{/wpredis}}{{#wpredis}}rt_cache_redis{{/wpredis}}; access_log /var/log/nginx/{{site_name}}.access.log {{^wpredis}}{{^static}}rt_cache{{/static}}{{/wpredis}}{{#wpredis}}rt_cache_redis{{/wpredis}};
error_log /var/log/nginx/{{site_name}}.error.log; error_log /var/log/nginx/{{site_name}}.error.log;
{{#alias}}
location / {
return 301 https://{{alias_name}}$request_uri;
}
{{/alias}}
{{#proxy}} {{#proxy}}
add_header X-Proxy-Cache $upstream_cache_status; add_header X-Proxy-Cache $upstream_cache_status;
location / { location / {
@@ -23,7 +28,7 @@ server {
proxy_redirect off; proxy_redirect off;
include proxy_params; include proxy_params;
} }
{{#alias}}
# Security settings for better privacy # Security settings for better privacy
# Deny hidden files # Deny hidden files
location ~ /\.(?!well-known\/) { location ~ /\.(?!well-known\/) {
@@ -35,9 +40,11 @@ server {
allow all; allow all;
auth_basic off; auth_basic off;
} }
{{/alias}}
{{/proxy}} {{/proxy}}
{{^proxy}} {{^proxy}}
{{^alias}}
root {{webroot}}/htdocs; root {{webroot}}/htdocs;
index {{^static}}index.php{{/static}} index.html index.htm; index {{^static}}index.php{{/static}} index.html index.htm;
@@ -51,7 +58,7 @@ server {
{{^static}}include {{#basic}}common/{{wo_php}}.conf;{{/basic}}{{#wpfc}}common/wpfc-{{wo_php}}.conf;{{/wpfc}}{{#wpsc}}common/wpsc-{{wo_php}}.conf;{{/wpsc}}{{#wpredis}}common/redis-{{wo_php}}.conf;{{/wpredis}}{{#wprocket}}common/wprocket-{{wo_php}}.conf;{{/wprocket}}{{#wpce}}common/wpce-{{wo_php}}.conf;{{/wpce}} {{^static}}include {{#basic}}common/{{wo_php}}.conf;{{/basic}}{{#wpfc}}common/wpfc-{{wo_php}}.conf;{{/wpfc}}{{#wpsc}}common/wpsc-{{wo_php}}.conf;{{/wpsc}}{{#wpredis}}common/redis-{{wo_php}}.conf;{{/wpredis}}{{#wprocket}}common/wprocket-{{wo_php}}.conf;{{/wprocket}}{{#wpce}}common/wpce-{{wo_php}}.conf;{{/wpce}}
{{#wpsubdir}}include common/wpsubdir.conf;{{/wpsubdir}}{{/static}} {{#wpsubdir}}include common/wpsubdir.conf;{{/wpsubdir}}{{/static}}
{{#wp}}include common/wpcommon-{{wo_php}}.conf;{{/wp}} {{#wp}}include common/wpcommon-{{wo_php}}.conf;{{/wp}}
include common/locations-wo.conf;{{/proxy}} include common/locations-wo.conf;{{/alias}}{{/proxy}}
include {{webroot}}/conf/nginx/*.conf; include {{webroot}}/conf/nginx/*.conf;
} }