Fixes in apache installation
This commit is contained in:
parent
d3d041f569
commit
ce92428dea
1 changed files with 115 additions and 0 deletions
115
scripts/install_apache.py
Normal file
115
scripts/install_apache.py
Normal file
|
|
@ -0,0 +1,115 @@
|
||||||
|
from pastafariutils import linux
|
||||||
|
import distro
|
||||||
|
|
||||||
|
linux_distro=distro.id()
|
||||||
|
|
||||||
|
conf_vhosts="IncludeOptional vhosts.d/*.conf";
|
||||||
|
|
||||||
|
linux.json_log('Installing Apache server', error=0, status=0, progress=0, no_progress=1);
|
||||||
|
|
||||||
|
debian_package='apache2 logrotate socat curl'
|
||||||
|
|
||||||
|
redhat_package='httpd mod_ssl openssl tar socat policycoreutils-python-utils wget';
|
||||||
|
|
||||||
|
linux_package={'debian' : debian_package, 'ubuntu' : debian_package, 'fedora' : redhat_package, 'almalinux' : redhat_package, 'rocky' : redhat_package, 'arch' : 'apache'}
|
||||||
|
|
||||||
|
linux.install_package(linux_package);
|
||||||
|
|
||||||
|
linux.json_log('Create directories for Apache manager...', error=0, status=0, progress=0, no_progress=1);
|
||||||
|
|
||||||
|
create_dirs={'debian' : {"sudo mkdir -p /etc/apache2/vhosts.d/ && sudo mkdir -p /etc/apache2/vhosts.d/{php,extra/proxyphp,extra/proxy}"}};
|
||||||
|
|
||||||
|
create_dirs['ubuntu']=create_dirs['debian'];
|
||||||
|
|
||||||
|
create_dirs['fedora']=["sudo mkdir -p /etc/httpd/vhosts.d/{php,extra/proxyphp,extra/proxy} "];
|
||||||
|
|
||||||
|
create_dirs['almalinux']=create_dirs['fedora'];
|
||||||
|
|
||||||
|
create_dirs['rocky']=create_dirs['fedora'];
|
||||||
|
|
||||||
|
linux.exec(create_dirs);
|
||||||
|
|
||||||
|
#if(!file_put_contents('vhosts.conf', conf_vhosts)) {
|
||||||
|
|
||||||
|
# linux.json_log('Error: cannot create vhosts.conf', error=1, status=1, progress=100, no_progress=0);
|
||||||
|
# exit(1);
|
||||||
|
#}
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
with fopen('vhosts.conf', 'w') as f:
|
||||||
|
f.write(conf_vhosts)
|
||||||
|
except:
|
||||||
|
linux.json_log('Error: cannot create vhosts.conf', error=1, status=1, progress=100, no_progress=0);
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
create_vhost_file={'debian' : ["sudo mv vhosts.conf /etc/apache2/sites-enabled/ && sudo chown root:root /etc/apache2/sites-enabled/vhosts.conf"]};
|
||||||
|
|
||||||
|
create_vhost_file['ubuntu']=create_vhost_file['debian'];
|
||||||
|
|
||||||
|
#echo 'deb blah ... blah' | sudo tee -a /etc/apt/sources.list
|
||||||
|
|
||||||
|
#create_vhost_file['fedora']=["sudo mv vhosts.conf /etc/httpd/conf.d/zzz-vhosts.conf && sudo chown root:root /etc/httpd/conf.d/zzz-vhosts.conf && sudo chmod 644 /etc/httpd/conf.d/zzz-vhosts.conf"];
|
||||||
|
|
||||||
|
create_vhost_file['fedora']=["echo {conf_vhosts} | sudo tee -a /etc/httpd/conf/httpd.conf"];
|
||||||
|
|
||||||
|
create_vhost_file['almalinux']=create_vhost_file['fedora'];
|
||||||
|
|
||||||
|
create_vhost_file['rocky']=create_vhost_file['fedora'];
|
||||||
|
|
||||||
|
linux.exec(create_vhost_file);
|
||||||
|
|
||||||
|
#Modifying apache configuration
|
||||||
|
|
||||||
|
linux.json_log('Modifying Apache configuration...', error=0, status=0, progress=0, no_progress=1);
|
||||||
|
|
||||||
|
if linux_distro=='ubuntu' or linux_distro=='debian':
|
||||||
|
|
||||||
|
sed_apache={'debian' : ['ServerTokens OS', "ServerTokens Prod", '/etc/apache2/conf-enabled/security.conf']}
|
||||||
|
|
||||||
|
sed_apache['ubuntu']=sed_apache['debian'];
|
||||||
|
|
||||||
|
linux.sed(sed_apache)
|
||||||
|
|
||||||
|
# In red hat derivatives is different.
|
||||||
|
|
||||||
|
if linux_distro=='rocky' or linux_distro=='almalinux' or linux_distro=='fedora':
|
||||||
|
|
||||||
|
#echo 'deb blah ... blah' | sudo tee -a /etc/apt/sources.list
|
||||||
|
add_tokens={}
|
||||||
|
|
||||||
|
add_tokens['rocky']=["sudo echo \"ServerTokens Prod\" | sudo tee -a /etc/httpd/conf.d/tokens.conf"]
|
||||||
|
|
||||||
|
add_tokens['almalinux']=add_tokens['rocky']
|
||||||
|
|
||||||
|
add_tokens['fedora']=add_tokens['rocky']
|
||||||
|
|
||||||
|
linux.exec(add_tokens)
|
||||||
|
|
||||||
|
|
||||||
|
#Activating modules for apache/debian.
|
||||||
|
|
||||||
|
if linux_distro=='ubuntu' or linux_distro=='debian':
|
||||||
|
|
||||||
|
activate_modules={'debian' : ["sudo a2enmod ssl rewrite proxy proxy_fcgi headers"]}
|
||||||
|
|
||||||
|
activate_modules['ubuntu']=create_vhost_file['debian'];
|
||||||
|
|
||||||
|
linux.exec(activate_modules)
|
||||||
|
|
||||||
|
|
||||||
|
if linux_distro=='rocky' or linux_distro=='almalinux' or linux_distro=='fedora':
|
||||||
|
|
||||||
|
if linux.shell_command('sudo systemctl status firewalld', 0)==0:
|
||||||
|
|
||||||
|
linux.shell_command("sudo firewall-cmd --add-service=http && sudo firewall-cmd --add-service=http --permanent && sudo firewall-cmd --add-service=https && sudo firewall-cmd --add-service=https --permanent")
|
||||||
|
|
||||||
|
|
||||||
|
#Restart apache
|
||||||
|
|
||||||
|
linux_service={'debian' : 'apache2', 'ubuntu' : 'apache2', 'fedora' : 'httpd', 'almalinux' : 'httpd', 'rocky' : 'httpd', 'arch' : 'httpd'}
|
||||||
|
|
||||||
|
linux.systemd_service('restart', linux_service)
|
||||||
|
|
||||||
|
linux.json_log('Apache server installed successfully!', error=0, status=0, progress=100, no_progress=0)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue