Apache

6 Notes
+ Auth Types (Oct. 13, 2019, 11:30 p.m.)

# Backward compatibility with apache 2.2 Order allow,deny Allow from all # Forward compatibility with apache 2.4 Require all granted Satisfy Any ----------------------------------------------------------- <IfVersion < 2.4> Allow from all </IfVersion> <IfVersion >= 2.4> Require all granted </IfVersion> -----------------------------------------------------------

+ Installation (Sept. 6, 2017, 9:41 a.m.)

For Debian earlier than Stretch: apt-get install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 libapache2-mod-wsgi-py3 python-pip python-dev build-essential For Debian Stretch: apt-get install apache2 apache2-utils libexpat1 libapache2-mod-wsgi-py3 python-pip python-dev build-essential

+ Password Protect via .htaccess (Feb. 26, 2017, 4:44 p.m.)

1- Create a file named `.htaccess` in the root of website, with this content: AuthName "Deskbit's Support" AuthUserFile /etc/apache2/.htpasswd AuthType Basic require valid-user ----------------------------------------------------- 2- htpasswd -c /etc/apache2/.htpasswd mohsen ----------------------------------------------------- 3- Add this to <Directory> block: <Directory /var/www/support/> Options Indexes FollowSymLinks AllowOverride ALL Require all granted </Directory> ----------------------------------------------------- 4- Restart apache /etc/init.d/apache2 restart -----------------------------------------------------

+ Configs for two different ports on same IP (Sept. 26, 2016, 9:37 p.m.)

NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin mohsen@mohsenhassani.com #ServerName ecc.mohsenhassani.com ServerName 93.118.96.41 ServerAlias ecc.mohsenhassani.com LogLevel warn ErrorLog /home/mohsen/logs/eccgroup_error.log WSGIScriptAlias / /home/mohsen/websites/ecc/ecc/wsgi.py WSGIDaemonProcess ecc python-path=/home/mohsen/websites/ecc:/home/mohsen/virtualenvs/django-1.10/lib/python3.4/site-packages WSGIProcessGroup ecc Alias /static /home/mohsen/websites/ecc/ecc/static <Directory /home/mohsen/websites/ecc/ecc/static> Require all granted </Directory> <Directory /> Require all granted </Directory> </VirtualHost> ------------------------------------------------------------------ Listen 8081 NameVirtualHost *:8081 <VirtualHost *:8081> ServerName 93.118.96.41 ServerAdmin mohsen@mohsenhassani.com ErrorLog /var/log/apache2/freepbx.error.log CustomLog /var/log/apache2/freepbx.access.log combined DocumentRoot /var/www/html <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>

+ Error Check (March 4, 2015, 10:36 a.m.)

sudo systemctl status apache2.service -l # tail -f /var/log/apache2/error.log

+ VirtualHost For Django Sites (March 4, 2015, 9:04 a.m.)

For Centos: 1- yum install mod_wsgi httpd httpd-devel ----------------------------------------------------------------- For Debian: 2- Create a virtual host: sudo nano /etc/apache2/sites-available/mydomain.com.conf OR sudo nano /etc/httpd/conf.d/mydomain.com.conf ----------------------------------------------------------------- 3- Create your new virtual host node which should look something like this: <VirtualHost *:80> ServerName 192.168.92.241 DocumentRoot /srv/mpei WSGIScriptAlias / /srv/mpei/mpei/wsgi.py LogLevel info ErrorLog /var/log/mpei_error.log WSGIDaemonProcess mpei processes=2 threads=15 python-path=/var/www/.virtualenvs/django-1.7/lib/python3.4/site-packages # WSGISocketPrefix /var/run/wsgi Alias /media/ /srv/mpei/mpei/media/ Alias /static/ /srv/mpei/mpei/static/ <Directory /srv/mpei/mpei/static> # For Apache 2.2 Allow from all # For Apache 2.4 Require all granted </Directory> <Directory /srv/mpei/mpei/media> # For Apache 2.2 Allow from all # For Apache 2.4 Require all granted </Directory> <Directory /srv/mpei/mpei> <Files wsgi.py> # For Apache 2.2 Order deny,allow Allow from all # For Apache 2.4 Require all granted </Files> </Directory> </VirtualHost> ----------------------------------------------------------------- 4- Edit the wsgi.py file within the main app of your project: import os import sys # Add the app's directory to the PYTHONPATH sys.path.append('/srv/mpei/') sys.path.append('/srv/mpei/mpei/') os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mpei.settings") # Activate your virtualenv activate_env=os.path.expanduser("/var/www/.virtualenvs/django-1.7/bin/activate_this.py") exec(open(activate_env).read()) # For newer versions of Django, use this: # exec(open(activate_env).read(), {'__file__': activate_env}) from django.core.wsgi import get_wsgi_application application = get_wsgi_application() ----------------------------------------------------------------- 5- Enable the virtual host (For Debian): a2ensite site.mysite.com.conf ----------------------------------------------------------------- 6- If you want to disable a site, you can run a2dissite site.mysite.com.conf ----------------------------------------------------------------- Compiling wsgi_mod If you're using another version of python, you'll need to compile mod_wsgi from source to match your virtual env. 1- Download the latest version from the following website: https://github.com/GrahamDumpleton/mod_wsgi/releases 2- Untar it, CD to the folder, and: sudo ./configure --with-python=/usr/local/bin/python3.6 sudo LD_RUN_PATH=/usr/local/lib make sudo make install It will get replaced by the one, which you had probably installed via Linux package manager, and solves any probable import errors. ----------------------------------------------------------------- Serving the admin files: cd /srv/mpei/mpei/static/ ln -s /var/www/.virtualenvs/django-1.7/lib/python3.4/site-packages/django/contrib/admin/static/admin . ----------------------------------------------------------------- For debuggig use the ErrorLog directive in the above apache config: tail -f /var/log/mpei_error.log ----------------------------------------------------------------- Listen 8000 WSGISocketPrefix /run/wsgi <VirtualHost *:8000> ServerName 192.168.88.50 DocumentRoot /srv/mpei WSGIScriptAlias / /srv/mpei/mpei/wsgi.py LogLevel info ErrorLog /var/log/mpei_error.log WSGIDaemonProcess mpei processes=2 threads=15 python-path=/srv/.virtualenvs/django-1.7/lib/python3.4/site-packages WSGIProcessGroup mpei Alias /media/ /srv/mpei/mpei/media/ Alias /static/ /srv/mpei/mpei/static/ <Directory /srv/mpei/mpei/static> Allow from all </Directory> <Directory /srv/mpei/mpei/media> Allow from all </Directory> <Directory /srv/mpei/mpei> <Files wsgi.py> Require all granted </Files> </Directory> Alias /recordings /var/spool/asterisk/ <Directory /var/spool/asterisk/> Require all granted Options Indexes FollowSymlinks </Directory> </VirtualHost> -----------------------------------------------------------------