1. Linux
1.1. Installation
1.1.1. Debian 8
-
Enter the following commands at a Command Line.
sudo apt-get install apache2 sudo apt-get install apache2-mpm-prefork # dpkg -l | grep -i "apache"
1.1.2. Debian 9 & 10
-
Enter the following commands at a Command Line.
sudo apt-get install apache2 # sudo apachectl -V # dpkg -l | grep -i "apache" # . /etc/apache2/envvars # apache2 -t -D DUMP_MODULES | grep ssl # $(which apache2) -L | grep SSL
1.2. Configuration
-
Enter the following commands at a Command Line.
sudo cp -a /etc/apache2/apache2.conf /etc/apache2/apache2.conf.org
1.3. SSL Configuration
-
See https://www.server-world.info/en/note?os=Debian_10&p=httpd&f=8.
-
Enter the following commands at a Command Line.
# Secure Apache server.
ls -al /etc/apache2/conf-enabled/security.conf
sudo cp -a /etc/apache2/conf-available/security.conf /etc/apache2/conf-available/security.conf.org
sudo sed -i "s/^ServerTokens.*/ServerTokens Prod/" /etc/apache2/conf-available/security.conf
sudo sed -i "s/^ServerSignature.*/ServerSignature Off/" /etc/apache2/conf-available/security.conf
cat << 'EOF' | sed -e "s/^ //" | sudo tee --append /etc/apache2/conf-available/security.conf
Header always append X-Frame-Options SAMEORIGIN
Header always set X-XSS-Protection: "1; mode=block"
Header always set X-Content-Type-Options: "nosniff"
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
Header always edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure
EOF
sudo diff /etc/apache2/conf-available/security.conf.org /etc/apache2/conf-available/security.conf
# Secure Apache server.
ls -al /etc/apache2/mods-enabled/ssl.conf
sudo cp -a /etc/apache2/mods-available/ssl.conf /etc/apache2/mods-available/ssl.conf.org
sudo sed -i "s/\tSSLCipherSuite .*/\tSSLCipherSuite HIGH:\!aNULL:\!MD5/" /etc/apache2/mods-available/ssl.conf
sudo sed -i "s/\tSSLProtocol .*/\tSSLProtocol -all +TLSv1.2/" /etc/apache2/mods-available/ssl.conf
sudo diff /etc/apache2/mods-available/ssl.conf.org /etc/apache2/mods-available/ssl.conf
# Create self signed certificate.
sudo mkdir -p /etc/pki/tls/certs
cd /etc/pki/tls/certs
sudo openssl req -x509 -nodes -newkey rsa:2048 -keyout smru.shoklo-unit.com.key -out smru.shoklo-unit.com.crt
# Type *TH* and press Enter for the country name.
# Type *Tak* and press Enter for the state name.
# Type *Mae Sot* and press Enter for the city name.
# Type *SMRU* and press Enter for the organization name.
# Type *IT* and press Enter for the organizational unit name.
# Type *<hostname>.smru.shoklo-unit.com* and press Enter for the common name.
# Type *smru-it@shoklo-unit.com* and press Enter for the email address.
ls -al
cd -
# Install self signed certificate in Apache.
sudo cp -a /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-available/default-ssl.conf.org
sudo sed -i "s|\tServerAdmin.*|\tServerAdmin smru-it@shoklo-unit.com|" /etc/apache2/sites-available/default-ssl.conf
sudo sed -i "s|\tSSLCertificateFile.*|\tSSLCertificateFile /etc/pki/tls/certs/smru.shoklo-unit.com.crt|" /etc/apache2/sites-available/default-ssl.conf
sudo sed -i "s|\tSSLCertificateKeyFile.*|\tSSLCertificateKeyFile /etc/pki/tls/certs/smru.shoklo-unit.com.key|" /etc/apache2/sites-available/default-ssl.conf
sudo diff /etc/apache2/sites-available/default-ssl.conf.org /etc/apache2/sites-available/default-ssl.conf
# Enable Apache ssl module, which is disabled by default.
sudo a2enmod headers
# Enable Apache headers module, which is disabled by default.
sudo a2enmod ssl
a2ensite default-ssl
sudo systemctl restart apache2
sudo systemctl status apache2
Enter the following commands at a Command Line.
#sudo /etc/init.d/apache2 restart sudo service apache2 restart sudo service apache2 status # sudo systemctl restart apache2
-
Browse to http://localhost.
-
Browse to http://localhost/index.html.
1.4. Disable Apache
Enter the following commands at a Command Line.
sudo service apache2 stop sudo update-rc.d apache2 disable
1.5. Enable Apache
Enter the following commands at a Command Line.
sudo update-rc.d apache2 enable sudo service apache2 start
1.6. Debug Apache
Enter the following commands at a Command Line.
sudo tail -f /var/log/apache2/access.log sudo tail -f /var/log/apache2/error.log
1.7. Name-based virtual hosts
Configuration of virtual host for example.com:
Enter the following commands at a Command Line.
cd /var/www/html sudo mkdir -p example.com/public sudo mkdir -p example.com/log
Contents of the /var/www/html/example.com/public/index.html file.
<html>
<head>
<title>Welcome to Example.com!</title>
</head>
<body>
<h1>Success! The example.com virtual host is working!</h1>
</body>
</html>
Enter the following commands at a Command Line.
cd /etc/apache2/sites-available sudo cp -a 000-default.conf example.com.conf
Important settings in the /etc/apache2/sites-available/example.com.conf file.
ServerName example.com ServerAlias www.example.com 10.0.2.15 DocumentRoot /var/www/html/example.com/public ErrorLog /var/www/html/example.com/log/error.log CustomLog /var/www/html/example.com/log/access.log combined
Enter the following commands at a Command Line.
sudo a2ensite example.com.conf sudo cp -a /etc/hosts /etc/hosts.org
-
Append the following lines to the /etc/hosts file.
127.0.0.1 example.com 127.0.0.1 www.example.com
Enter the following commands at a Command Line.
sudo systemctl restart apache2
-
Browse to http://example.com, http://example.com or http://example.com/index.html.
-
Browse to http://10.0.2.15, http://10.0.2.15 or http://10.0.2.15/index.html.
-
Browse to http://localhost, http://localhost or http://localhost/index.html.
1.8. Markdown
Enter the following commands at a Command Line.
sudo apt-get install apache2-dev libmarkdown2-dev sudo apt-get install autoconf automake build-essential libtool cd /tmp wget http://www.pell.portland.or.us/%7Eorc/Code/discount/discount-2.2.2.tar.bz2 wget https://github.com/hamano/apache-mod-markdown/archive/master.zip su - tar xfj discount-2.2.2.tar.bz2 chown -R root:root discount-2.2.2 cd discount-2.2.2 ./configure.sh make cd /tmp mv discount-2.2.2 include unzip master.zip cd apache-mod-markdown-master autoreconf -f -i ./configure --with-apxs=/usr/bin/apxs2 --with-discount=/tmp make make install exit cd /tmp sudo rm discount-2.2.2.tar.bz2 master.zip sudo rm -rf apache-mod-markdown-master include
Contents of the /etc/apache2/mods-available/markdown.load file.
LoadModule markdown_module /usr/lib/apache2/modules/mod_markdown.so
Enter the following commands at a Command Line.
touch /etc/apache2/mods-available/markdown.conf a2enmod markdown
-
Contents of the /var/www/html/markdown.css file.
h1 { color: red; }
h2 { color: blue; }
pre { background-color: LightGrey !important; }
-
Add the following lines to the <Directory> section in the /etc/apache2/apache2.conf file.
AddHandler markdown .md MarkdownCss /markdown.css
Enter the following commands at a Command Line.
sudo systemctl restart apache2 exit