Change document root folder of Apache web server on Linux - linux

My PC is windows 8.1 and Linux mint 16 dual boot pc.I created Local web server on Linux Mint.It's document root is "/var/www".But all my projects are located on a NTFS partion which i mount to linux and use(/media/randika/HardDisk/Works/Lab).I need to make a symbolic link to projects folder or change document root of Apache server.How can i do it?`
My 000-default.conf file located in sites-available folder
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Just change inside your Virtualhost
DocumentRoot /var/www
to
DocumentRoot /media/randika/HardDisk/Works/Lab
and add the rights on the new directory
<Directory "/media/randika/HardDisk/Works/Lab">
Order Allow,Deny
Allow from all
Options Indexes
AllowOverride AuthConfig
</Directory>
And restart Apache for reload the configuration

Fixed it.when mounting a partition, linux automatically sets permissions for all files and directories in that partition.Permissions cannot change after mounted.Therefore Unmounted the partition,changed umask value to 022 in etc/fstab and created a symbolic link.Everything works fine.

Related

Mod_wsgi daemon mode not reloading web page templates

I cannot reload django templates by touching the wsgi.py script located in my django application root/application name.
The script and project are located under /var/www, so I need sudo to execute touch.
I am running production apache2 server running a django website with mod_wsgi in daemon mode. I can collectstatics and make migrations, access database (without permission issues). I can also change the DEBUG flag in the settings. If I touch wsgi.py, it will put the production site into debug as expected, but the htmls are not loaded. Likewise I can update the static files, collectstatics, or modify the underlying models and see the changes live. Likewise I can use the commented code to retrieve what Daemon mode the swerver is running in. Its only the templates causing an issue. The settings file, wsgi.py, statics and python scripts are responded as expected.
Has anyone got any idea how to debug this?
virtualenv python3.8.12 apache2.4
mod_wsgi compiled for python3.8.12
wsgi.py
import os
import sys
from django.core.wsgi import get_wsgi_application
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../")))
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../")))
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../app/")))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mb.settings')
application = get_wsgi_application()
#def application(environ, start_response):
# status = '200 OK'
# if not environ['mod_wsgi.process_group']:
# output = u'EMBEDDED MODE'
# else:
# output = u'DAEMON MODE'
# response_headers = [('Content-Type', 'text/plain'),
# ('Content-Length', str(len(output)))]
# start_response(status, response_headers)
# return [output.encode('UTF-8')]
apache2 site config
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName app
ServerAdmin webmaster#localhost
ServerName ------removed for posting-----
ServerAlias -----removed for posting------
DocumentRoot /var/www/vhosts/mb
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
<Directory /var/www/vhosts/mb>
Order allow,deny
Allow from all
Require all granted
</Directory>
Alias /static /var/www/vhosts/mb/static
<Directory /var/www/vhosts/mb/static>
Require all granted
</Directory>
<Directory /var/www/vhosts/mb/mb>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess mb python-path=/var/www/vhosts/mb python-home=/var/www/vhosts/mb/pyenv
WSGIProcessGroup mb
WSGIScriptAlias / /var/www/vhosts/mb/mb/wsgi.py
WSGIApplicationGroup %{GLOBAL}
</VirtualHost>
For some reason, I did an scp copy into the directory with a new html and not a git push. The result? I used a recursive copy on scp with the -r flag. This created a subdirectory automatically. It confused the daemon. Removing this subdirectory fixed the issue, and touch worked fine.

mkcert certificate not works on local ip adress

I'm trying to convert my app to PWA and I need to use https on localhost on my raspberrypi 4 and can be reached using 192.168.0.2 on LAN
Certificate seems to be not valid and I don't understand what I'm missing.
All command are executed as root user and all steps are from GitHub official page
mkcert -install
mkcert 192.168.80.2
Using the local CA at "/root/.local/share/mkcert" ✨
Created a new certificate valid for the following names �
- "192.168.0.2"
The certificate is at "./192.168.0.2.pem" and the key at "./192.168.0.2-key.pem" ✅
mv 192.168.0.2-key.pem /etc/apache2/ssl/192.168.0.2-key.pem
mv 192.168.0.2.pem /etc/apache2/ssl/192.168.0.2.pem
ls -l /etc/apache2/sites-enabled
lrwxrwxrwx 1 root root 29 Jul 21 16:34 hiker.conf -> ../sites-available/hiker.conf
sites-available/hiker.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName 192.168.0.2
ServerAdmin webmaster#localhost
DocumentRoot /var/www
Alias /hiker /var/www/hiker/public
<Directory /var/www/hiker/public>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerName 192.168.0.2
ServerAdmin webmaster#localsite.test
DocumentRoot /var/www
Alias /hiker /var/www/hiker/public
<Directory /var/www/hiker/public>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/localsite-error.log
CustomLog ${APACHE_LOG_DIR}/localsite-access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/192.168.0.2.pem
SSLCertificateKeyFile /etc/apache2/ssl/192.168.0.2-key.pem
</VirtualHost>
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
apachectl configtest
Syntax OK
service apache2 restart
I found the solution thank to #SteffenUllrich.
I order to import CA into windows 10 follow steps described here "make-computer-trust-certificate-authority"
I can now make tests to convert my app to PWA

one sub domain is working but simliar content subdmain in different IP is not working

Contents are similar in both subdomains. But one domain is working but the other is not working.
Apache host files.
merchant.clouspos.lk (This is working)
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerName merchant.cloudpos.lk
ServerAlias merchant.cloudpos.lk
ServerAdmin webmaster#et.lk
RedirectMatch 301 /ipgresponse_dfecVfBuvsdRkY24(.*) /main.html#/paymentprocessing$1
DocumentRoot /var/www/merchant/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
merchant2.cloudpos.lk (This is redirct to different site)
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerName merchant2.cloudpos.lk
ServerAlias merchant2.cloudpos.lk
ServerAdmin webmaster#et.lk
RedirectMatch 301 /ipgresponse_dfecVfBuvsdRkY24(.*) /main.html#/paymentprocessing$1
DocumentRoot /var/www/merchant2/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
Please provide a solution for this issue? Source code is same in both subdomains.

This site can’t be reached after installing WSL2 and apache2

I updated my WSL1 to WSL2 and install
ubuntu 20.04,
Apache2 and
php8
Now visiting localhost will display the Apache2 Ubuntu Default Page
Next I create a conf file on /etc/apache2/sites-available/items.test.conf containing
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName items.test
ServerAdmin admin#items.test
DocumentRoot /mnt/c/www/path/to/public
<Directory /mnt/c/www/path/to/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
run sudo a2ensite items.test.conf and sudo service apache2 reload. Next open host with notepad with administrator, and added 127.0.0.1 items.test
Visiting the site locally items.test give me this message
This site can’t be reached
What am I missing in this, spend 24hrs tweaking and no luck
After digging another few hours I found the answer, update host file with such a like:
127.0.0.1 test.tld
::1 test.tld
Source: https://github.com/microsoft/WSL/issues/4347

Apache points to wrong vhost conf file

I have a fresh VPS on Ubuntu 18. Have installed only PHP and Apache. Created only a one vhost config:
<VirtualHost *:80>
ServerName vp123.ovh.net
DocumentRoot /var/www/app
</VirtualHost>
After apache realod, the domain is pointing to default folder /var/www/html instead of my /var/www/app
000-default.conf is default:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
apache2ctl -S outputs:
VirtualHost configuration:
*:80 is a NameVirtualHost
default server vp123.ovh.net (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost vp123.ovh.net (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost vp123.ovh.net (/etc/apache2/sites-enabled/vp123.ovh.net.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
When pointing a new domain to this server - works perfect. But this "default domain" is always pointing to default folder. Disabling 000-default.conf helps but I don't want do that.
The virtual host defined at 000-default.conf doesn't have a ServerName directive so it inherits the value from its parent container (in this case the main server settings) and I presume such directive also has vp123.ovh.net as value. Thus Apache considers the first virtual host matches.
A ServerName should be specified inside each <VirtualHost> block. If it is absent, the ServerName from the "main" server configuration will be inherited.
Since you want to use that name elsewhere a possible solution is to set a explicit value that doesn't interfere, e.g.:
<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www/html
</VirtualHost>
Apache selects the virtual host as described in the documentation.
Considering the vhost selection process your options are:
Disable the default vHost, you don't need it.
Really. Why would you want to keep it?
Change the default vHost declaration to <VirtualHost *>. Therefore making the other vHost the default for requests targeted at port 80.
Add your servers ip address to your vhost declaration. (<VirtualHost 1.2.3.4:80>) It will then take precedence over the default vhost *:80 for requests targeted at that IP-address. Note that requests to other to other IPs of your server will still be served by the *:80-vHost.
Set DocumentRoot /var/www/app inside your default vHost. This will require you to make configuration changes in multiple vHost each time and thus increases the chance of making mistakes.

Resources