apache/scripts/install_apache.php
2023-11-28 00:15:10 +01:00

63 lines
2.2 KiB
PHP

<?php
use PhangoApp\LeviathanUtils\Linux;
include('leviathanutils/vendor/autoload.php');
$linux_distro=Linux::get_linux_distro();
$conf_vhosts="IncludeOptional vhosts.d/*.conf";
Linux::json_log('Installing Apache server', $error=0, $status=0, $progress=0, $no_progress=1);
$redhat_package='mod_ssl openssl tar socat policycoreutils-python-utils wget';
$linux_package=['debian' => 'apache2 logrotate socat curl', 'ubuntu' => 'apache2 logrotate socat curl', '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/ && sudo mkdir -p /etc/apache2/vhosts.d/extra/"]];
$create_dirs['ubuntu']=$create_dirs['debian'];
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);
}
$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'];
Linux::exec($create_vhost_file);
//Modifying apache configuration
Linux::json_log('Modifying Apache configuration...', $error=0, $status=0, $progress=0, $no_progress=1);
$sed_apache=['debian' => ['ServerTokens OS', "ServerTokens Prod", '/etc/apache2/conf-enabled/security.conf']];
$sed_apache['ubuntu']=$sed_apache['debian'];
Linux::sed($sed_apache);
//Activating modules for apache.
$activate_modules=['debian' => ["sudo a2enmod ssl rewrite proxy proxy_fcgi"]];
$activate_modules['ubuntu']=$create_vhost_file['debian'];
Linux::exec($activate_modules);
//Restart apache
$linux_service=['debian' => 'apache2', 'ubuntu' => 'apache2', 'fedora' => 'httpd', 'almalinux' => 'httpd', 'rocky' => 'httpd', 'arch' => 'apache'];
Linux::systemd_service('restart', $linux_service);
Linux::json_log('Apache server installed successfully!', $error=0, $status=0, $progress=100, $no_progress=0);