selfhosted:apache

INSTALLATION

$ sudo apt-get install apache2 php libapache2-mod-php php-common php-mbstring php-xmlrpc php-soap php-apcu php-smbclient php-ldap php-redis php-gd php-xml php-intl php-json php-imagick php-mysql php-cli php-mcrypt php-zip php-curl
$ sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/apache2/apache2.conf

See Common Linux Commands for [start | restart | stop | enable | status] systemctl commands

SETUP

## allow ports 80,443
$ sudo iptables -A INPUT -i lo -j ACCEPT
$ sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
$ sudo iptables -A INPUT -p tcp -m multiport --dports 80,443 -j ACCEPT
$ sudo iptables -A INPUT -j DROP
$ sudo iptables -S
$ /etc/init.d/networking restart
## enable sites
$ sudo chown -R www-data:www-data /var/www/html/${site}/
$ sudo chmod -R 755 /var/www/html/${site}/
$ sudo a2ensite ${site}.conf; sudo a2enmod rewrite; sudo a2enmod headers; sudo a2enmod env; sudo a2enmod dir; sudo a2enmod mime;
## restart service
$ sudo systemctl restart apache2.service

CONFIGURATION

config: /etc/apache2/sites-available/${site}.conf
$ sudo nano ${config}
  < ${config} >
      <VirtualHost *:80>
        DocumentRoot /var/www/html/${site}/
        ServerName localhost
        # ServerAdmin admin@site.com
        # Alias /${site} "/var/www/html/${site}/"
        <Directory /var/www/html/${site}/>
          Options +FollowSymLinks
          AllowOverride All
          Require all granted
          <IfModule mod_dav.c>
            Dav off
          </IfModule>
        </Directory>
        SetEnv HOME /var/www/html/${site}
        SetEnv HTTP_HOME /var/www/html/${site}
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
      </VirtualHost>
  ## -- redirects
  # RedirectMatch ^/$ "/${site}"
  • selfhosted/apache.txt
  • Last modified: 2023/07/02 18:11
  • by hli