How to Serve Django Application With Apache2 and Mod WSGI - django

I want to serve my Django applications using Apache2 and the mod_wsgi module. I have setup an Apache virtualhost at /etc/apache2/sites-available/mysite.confand I have made some configuration changes to WSGI at home/username/development/mysite/mysite/wsgi.py However, when I navigate to mydomain.com, I am being presented with the 500 Internal Server Error: The server encountered an internal error or misconfiguration and was unable to complete your request.. I am very new to server development and have never used Apache2 before so I am unsure as to where I have gone wrong in my configuration. Below you will find my virtualhost configuration file as well as my WSGI file. Additionally, I have provided the structure layout of my project directory in case this helps. Any help is greatly appreciated.
directory structure
>> home
>> username
>> development
>> mysite
>> mysite
>> settings.py
>> wsgi.py
>> website
>> static
>> manage.py
>> venv
mysite.conf
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot /home/username/development/mysite
WSGIScriptAlias / /home/username/development/mysite/mysite/wsgi.py
WSGIDaemonProcess mydomain.com processes=2 threads=15 display-name=%{GROUP} python-home=/home/username/development/venv/lib/python3.5
WSGIProcessGroup mydomain.com
<directory /home/username/development/mysite>
AllowOverride all
Require all granted
Options FollowSymlinks
</directory>
Alias /static/ /home/username/development/mysite/website/static/
<Directory /home/username/development/mysite/website/static>
Require all granted
</Directory>
</VirtualHost>
wsgi.py
import os
import time
import traceback
import signal
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('/home/username/development/mysite')
# adjust the Python version in the line below as needed
sys.path.append('/home/username/development/venv/lib/python3.5/site-packages')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
try:
application = get_wsgi_application()
except Exception:
# Error loading applications
if 'mod_wsgi' in sys.modules:
traceback.print_exc()
os.kill(os.getpid(), signal.SIGINT)
time.sleep(2.5)
error.log
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/pdo_mysql.so' - /usr/lib/php/20151012/pdo_mysql.so: undefined symbol: mysqlnd_connect in Unknown on line 0
[Mon Aug 05 06:25:02.417656 2019] [wsgi:warn] [pid 11931] mod_wsgi: Compiled for Python/3.5.1+.
[Mon Aug 05 06:25:02.417679 2019] [wsgi:warn] [pid 11931] mod_wsgi: Runtime using Python/3.5.2.
[Mon Aug 05 06:25:02.418568 2019] [mpm_prefork:notice] [pid 11931] AH00163: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Mon Aug 05 06:25:02.418590 2019] [core:notice] [pid 11931] AH00094: Command line: '/usr/sbin/apache2'
[Mon Aug 05 10:09:39.950527 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] mod_wsgi (pid=23705): Target WSGI script '/home/username/development/mysite/mysite/wsgi.py' cannot be loaded as Python module.
[Mon Aug 05 10:09:39.950606 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] mod_wsgi (pid=23705): Exception occurred processing WSGI script '/home/username/development/mysite/mysite/wsgi.py'.
[Mon Aug 05 10:09:39.951482 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] Traceback (most recent call last):
[Mon Aug 05 10:09:39.951546 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/mysite/mysite/wsgi.py", line 16, in <module>
[Mon Aug 05 10:09:39.951552 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] application = get_wsgi_application()
[Mon Aug 05 10:09:39.951564 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/venv/lib/python3.5/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Mon Aug 05 10:09:39.951569 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] django.setup(set_prefix=False)
[Mon Aug 05 10:09:39.951577 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/venv/lib/python3.5/site-packages/django/__init__.py", line 19, in setup
[Mon Aug 05 10:09:39.951597 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Mon Aug 05 10:09:39.951607 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/venv/lib/python3.5/site-packages/django/conf/__init__.py", line 79, in __getattr__
[Mon Aug 05 10:09:39.951612 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] self._setup(name)
[Mon Aug 05 10:09:39.951619 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/venv/lib/python3.5/site-packages/django/conf/__init__.py", line 66, in _setup
[Mon Aug 05 10:09:39.951623 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] self._wrapped = Settings(settings_module)
[Mon Aug 05 10:09:39.951630 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/venv/lib/python3.5/site-packages/django/conf/__init__.py", line 157, in __init__
[Mon Aug 05 10:09:39.951634 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] mod = importlib.import_module(self.SETTINGS_MODULE)
[Mon Aug 05 10:09:39.951640 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/venv/lib/python3.5/importlib/__init__.py", line 126, in import_module
[Mon Aug 05 10:09:39.951644 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] return _bootstrap._gcd_import(name[level:], package, level)
[Mon Aug 05 10:09:39.951651 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Mon Aug 05 10:09:39.951657 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Mon Aug 05 10:09:39.951664 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
[Mon Aug 05 10:09:39.951671 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
[Mon Aug 05 10:09:39.951678 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Mon Aug 05 10:09:39.951696 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Mon Aug 05 10:09:39.951704 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
[Mon Aug 05 10:09:39.951725 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] ImportError: No module named 'mysite'
[Mon Aug 05 10:52:33.048933 2019] [mpm_prefork:notice] [pid 11931] AH00169: caught SIGTERM, shutting down
mysite.conf edit
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot /home/username/development/mysite
WSGIScriptAlias / /home/username/development/mysite/mysite/wsgi.py
WSGIDaemonProcess mydomain.com python-home=/home/username/development/venv python-path=/home/username/developement/mysite
WSGIProcessGroup mydomain.com
<directory /home/username/development/mysite>
AllowOverride all
Require all granted
Options FollowSymlinks
</directory>
Alias /static/ /home/username/development/mysite/website/static/
<Directory /home/username/development/mysite/website/static>
Require all granted
</Directory>
</VirtualHost>

Related

How do I set up my Django Website using Apache and WSGI

I've joined the unhappy ranks of people who have tried to set up a Django website served by Apache (on Amazon-linux EC2).
I have successfully configured Apache and compiled mod_wsgi against Python3.4 using a virtualenv (at /home/ec2-user/web-dev) largely following instructions at https://gist.github.com/tanuka72/79ae58b16be4ac3fafe0 and the mod_wsgi docs).
However, I get an Internal Server Error when loading the Django test app.
Looking at the logs, it seems that multiple versions of Python are somehow being called during the processing (see the change from /home/ec2-user/web-dev/lib64/python3.4 to /usr/lib64/python3.7). Also it seems that mod_wsgi cannot be imported (whilst 'import mod_wsgi' works fine from a python prompt in the ec2 terminal).
[Thu Jan 19 15:19:27.329376 2023] [wsgi:error] [pid 9955] [remote 81.109.251.90:61582] mod_wsgi (pid=9955): Failed to exec Python script file '/var/www/test/test_site/test_site/wsgi.py'.
[Thu Jan 19 15:19:27.329445 2023] [wsgi:error] [pid 9955] [remote 81.109.251.90:61582] mod_wsgi (pid=9955): Exception occurred processing WSGI script '/var/www/test/test_site/test_site/wsgi.py'.
[Thu Jan 19 15:19:27.330049 2023] [wsgi:error] [pid 9955] [remote 81.109.251.90:61582] Traceback (most recent call last):
[Thu Jan 19 15:19:27.330088 2023] [wsgi:error] [pid 9955] [remote 81.109.251.90:61582] File "/var/www/test/test_site/test_site/wsgi.py", line 25, in <module>
[Thu Jan 19 15:19:27.330093 2023] [wsgi:error] [pid 9955] [remote 81.109.251.90:61582] application = get_wsgi_application()
[Thu Jan 19 15:19:27.330108 2023] [wsgi:error] [pid 9955] [remote 81.109.251.90:61582] File "/home/ec2-user/web-dev/lib64/python3.4/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Thu Jan 19 15:19:27.330112 2023] [wsgi:error] [pid 9955] [remote 81.109.251.90:61582] django.setup(set_prefix=False)
[Thu Jan 19 15:19:27.330117 2023] [wsgi:error] [pid 9955] [remote 81.109.251.90:61582] File "/home/ec2-user/web-dev/lib64/python3.4/site-packages/django/__init__.py", line 24, in setup
[Thu Jan 19 15:19:27.330121 2023] [wsgi:error] [pid 9955] [remote 81.109.251.90:61582] apps.populate(settings.INSTALLED_APPS)
[Thu Jan 19 15:19:27.330126 2023] [wsgi:error] [pid 9955] [remote 81.109.251.90:61582] File "/home/ec2-user/web-dev/lib64/python3.4/site-packages/django/apps/registry.py", line 89, in populate
[Thu Jan 19 15:19:27.330129 2023] [wsgi:error] [pid 9955] [remote 81.109.251.90:61582] app_config = AppConfig.create(entry)
[Thu Jan 19 15:19:27.330134 2023] [wsgi:error] [pid 9955] [remote 81.109.251.90:61582] File "/home/ec2-user/web-dev/lib64/python3.4/site-packages/django/apps/config.py", line 123, in create
[Thu Jan 19 15:19:27.330137 2023] [wsgi:error] [pid 9955] [remote 81.109.251.90:61582] import_module(entry)
[Thu Jan 19 15:19:27.330142 2023] [wsgi:error] [pid 9955] [remote 81.109.251.90:61582] File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module
[Thu Jan 19 15:19:27.330146 2023] [wsgi:error] [pid 9955] [remote 81.109.251.90:61582] return _bootstrap._gcd_import(name[level:], package, level)
[Thu Jan 19 15:19:27.330151 2023] [wsgi:error] [pid 9955] [remote 81.109.251.90:61582] File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
[Thu Jan 19 15:19:27.330156 2023] [wsgi:error] [pid 9955] [remote 81.109.251.90:61582] File "<frozen importlib._bootstrap>", line 983, in _find_and_load
[Thu Jan 19 15:19:27.330161 2023] [wsgi:error] [pid 9955] [remote 81.109.251.90:61582] File "<frozen importlib._bootstrap>", line 962, in _find_and_load_unlocked
[Thu Jan 19 15:19:27.330176 2023] [wsgi:error] [pid 9955] [remote 81.109.251.90:61582] ModuleNotFoundError: No module named 'mod_wsgi.server'; 'mod_wsgi' is not a package
To debug this, I wanted to see which version of python was being called. Overriding wsgi.py to remove the call to Django's get_wsgi_application prevents the error. The URL shows the results of the application function below:
# In test_site/test_site/wsgi.py:
# ...
python_home = '/home/ec2-user/web-dev'
activator = python_home + '/bin/activate_this.py'
with open(activator) as f:
exec(f.read(), {'__file__': activator})
import os
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('/var/www/test/test_site')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_site.settings')
#application = get_wsgi_application()
def application(environ, start_response):
status = '200 OK'
msg = f"sys.path: {sys.path} | sys.prefix: {sys.prefix} | sys.executable: {sys.executable} | Python version {sys.version}"
output = str.encode(msg)
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
The function has a confusing output in the browser:
sys.path: ['/home/ec2-user/web-dev/lib64/python3.4/site-packages', '/home/ec2-user/web-dev/lib/python3.4/site-packages', '/var/www/test/test_site/test_site/wsgi.py', '/usr/lib64/python37.zip', '/usr/lib64/python3.7', '/usr/lib64/python3.7/lib-dynload', '/var/www/test/test_site', '/var/www/test/test_site', '/var/www/test/test_site'] | sys.prefix: /home/ec2-user/web-dev | sys.executable: /home/ec2-user/web-dev/bin/python | Python version 3.7.15 (default, Oct 31 2022, 22:44:31)
[GCC 7.3.1 20180712 (Red Hat 7.3.1-15)]
There are more folders in the PYTHONPATH than I expected, and also Python 3.7 appears to be running instead of 3.4. Interestingly this shows that mod_wsgi is working.
For reference, my httpd.conf file is updated to include:
WSGIScriptAlias / /var/www/test/test_site/test_site/wsgi.py
WSGIPythonPath /var/www/test:/home/ec2-user/web-dev/lib/python3.4/site-packages:/home/ec2-user/web-dev/lib64/python3.4/site-packages
<Directory /var/www/test/test_site/test_site>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
What can I do to get this Django app to load? This is only step one - before I try my own website, and adding a database too - it was only supposed to take a few hours. It has been a few days!

Two Django websites on Windows Apache

I am trying to host two Django websites on Windows (so no WSGIdaemonprocess). When I did host only one of them it worked perfectly. Now it still works (main path "/" named magazyn). But the second one (path "/awizacje" named awizacje) throws an Internal Server Error. Full error message in Apache logs looks like this:
C:\A\34\s\Modules\_decimal\libmpdec\context.c:57: warning: mpd_setminalloc: ignoring request to set MPD_MINALLOC a second time
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] mod_wsgi (pid=6268): Failed to exec Python script file 'C:/var/www2/awizacje/rootkat/awizacje/wsgi.py'.
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] mod_wsgi (pid=6268): Exception occurred processing WSGI script 'C:/var/www2/awizacje/rootkat/awizacje/wsgi.py'.
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] Traceback (most recent call last):\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "C:/var/www2/awizacje/rootkat/awizacje/wsgi.py", line 19, in <module>\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] application = get_wsgi_application()\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "C:\\var\\www\\magazyn\\env39\\Lib\\site-packages\\django\\core\\wsgi.py", line 12, in get_wsgi_application\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] django.setup(set_prefix=False)\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "C:\\var\\www\\magazyn\\env39\\Lib\\site-packages\\django\\__init__.py", line 19, in setup\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "C:\\var\\www\\magazyn\\env39\\Lib\\site-packages\\django\\conf\\__init__.py", line 76, in __getattr__\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] self._setup(name)\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "C:\\var\\www\\magazyn\\env39\\Lib\\site-packages\\django\\conf\\__init__.py", line 63, in _setup\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] self._wrapped = Settings(settings_module)\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "C:\\var\\www\\magazyn\\env39\\Lib\\site-packages\\django\\conf\\__init__.py", line 142, in __init__\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] mod = importlib.import_module(self.SETTINGS_MODULE)\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "C:\\Python39\\lib\\importlib\\__init__.py", line 127, in import_module\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] return _bootstrap._gcd_import(name[level:], package, level)\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "<frozen importlib._bootstrap>", line 1030, in _gcd_import\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "<frozen importlib._bootstrap>", line 1007, in _find_and_load\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "<frozen importlib._bootstrap>", line 1030, in _gcd_import\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "<frozen importlib._bootstrap>", line 1007, in _find_and_load\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] ModuleNotFoundError: No module named 'awizacje'\r
My httpd.conf looks like this:
WSGIPythonHome "C:/var/www/magazyn/env39"
WSGIPythonPath "C:/var/www/magazyn/venv/Lib/site-packages;C:/var/www/magazyn/rootkat/"
ServerName www.magazyn-stolarz.pl
LoadFile "C:/Python39/python39.dll"
LoadModule wsgi_module "C:/var/www/magazyn/env39/lib/site-packages/mod_wsgi/server/mod_wsgi.cp39-win_amd64.pyd"
WSGIScriptAlias /awizacje "C:/var/www2/awizacje/rootkat/awizacje/wsgi.py"
WSGIScriptAlias / "C:/var/www/magazyn/rootkat/magazyn/wsgi.py"
<Directory "C:/var/www/magazyn/rootkat/magazyn/">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static "C:/var/www/static/"
<Directory "C:/var/www/static/">
Require all granted
</Directory>
<Directory "C:/var/www2/awizacje/rootkat/awizacje/">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /statica "C:/var/www2/static/"
<Directory "C:/var/www2/static/">
Require all granted
</Directory>
My wsgi.py settings in 'awizacje' project:
"""
WSGI config for magazyn project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
"""
import os
import sys
import site
from django.core.wsgi import get_wsgi_application
#os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'awizacje.settings')
os.environ["DJANGO_SETTINGS_MODULE"] = "awizacje.settings"
application = get_wsgi_application()
site.addsitedir('C:/var/www2/awizacje/venv/Lib/site-packages')
sys.path.append('C:/var/www2/awizacje')
sys.path.append('C:/var/www2/awizacje/rootkat')
What am I doing wrong? I sadly can't use Linux which would be pretty straightforward.
It looks like what I was missing was appending directories BEFORE get_wsgi_application() command in wsgi.py
"""
WSGI config for magazyn project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
"""
import os
import sys
import site
from django.core.wsgi import get_wsgi_application
#os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'awizacje.settings')
os.environ["DJANGO_SETTINGS_MODULE"] = "awizacje.settings"
application = get_wsgi_application()
site.addsitedir('C:/var/www2/awizacje/venv/Lib/site-packages')
sys.path.append('C:/var/www2/awizacje')
sys.path.append('C:/var/www2/awizacje/rootkat')

Apache with django and wordpress, wsgi error loading wordpress

I have two sites, site-one is a django app and site-two is a wordpress site.
I have two .conf files inside /etc/apache2/sites-available:
site-one.com.conf
<VirtualHost *:80>
ServerAdmin adminmail#gmail.com
ServerName site-one.com
ServerAlias www.site-one.com
DocumentRoot /var/www/site-one.com/public_html
ErrorLog ${APACHE_LOG_DIR}/site-one.com.error.log
CustomLog ${APACHE_LOG_DIR}/site-one.com.access.log combined
Alias /static /var/www/site-one.com/public_html/static
<Directory /var/www/site-one.com/public_html/static>
Require all granted
</Directory>
<Directory /var/www/site-one.com/public_html/MyApp>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /var/www/site-one.com/public_html/MyApp/wsgi.py
WSGIDaemonProcess django_app python-path=/var/www/site-one.com/public_html
WSGIProcessGroup django_app
</VirtualHost>
site-two.com.conf
<VirtualHost *:80>
ServerAdmin adminmail#gmail.com
ServerName site-two.com
ServerAlias www.site-two.com
DocumentRoot /var/www/site-two.com/public_html
ErrorLog ${APACHE_LOG_DIR}/site-two.com.error.log
CustomLog ${APACHE_LOG_DIR}/site-two.com.access.log combined
</VirtualHost>
The site-one.com is 100% working but when I load site-two.com I get this error:
Internal Server Error The server encountered an internal error or
misconfiguration and was unable to complete your request.
The site-two.com.error.log shows this:
[Mon Nov 02 09:09:48.629460 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] mod_wsgi (pid=2396): Failed to exec Python script file '/var/www/site-one.com/public_html/MyApp/wsgi.py'.
[Mon Nov 02 09:09:48.631915 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] mod_wsgi (pid=2396): Exception occurred processing WSGI script '/var/www/site-one.com/public_html/MyApp/wsgi.py'.
[Mon Nov 02 09:09:48.632702 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] Traceback (most recent call last):
[Mon Nov 02 09:09:48.632776 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "/var/www/site-one.com/public_html/MyApp/wsgi.py", line 16, in <module>
[Mon Nov 02 09:09:48.632784 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] application = get_wsgi_application()
[Mon Nov 02 09:09:48.632794 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "/usr/local/lib/python3.8/dist-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Mon Nov 02 09:09:48.632799 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] django.setup(set_prefix=False)
[Mon Nov 02 09:09:48.632808 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "/usr/local/lib/python3.8/dist-packages/django/__init__.py", line 19, in setup
[Mon Nov 02 09:09:48.632813 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Mon Nov 02 09:09:48.632822 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "/usr/local/lib/python3.8/dist-packages/django/conf/__init__.py", line 83, in __getattr__
[Mon Nov 02 09:09:48.632827 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] self._setup(name)
[Mon Nov 02 09:09:48.632835 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "/usr/local/lib/python3.8/dist-packages/django/conf/__init__.py", line 70, in _setup
[Mon Nov 02 09:09:48.632840 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] self._wrapped = Settings(settings_module)
[Mon Nov 02 09:09:48.632849 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "/usr/local/lib/python3.8/dist-packages/django/conf/__init__.py", line 177, in __init__
[Mon Nov 02 09:09:48.632854 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] mod = importlib.import_module(self.SETTINGS_MODULE)
[Mon Nov 02 09:09:48.632862 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
[Mon Nov 02 09:09:48.632867 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] return _bootstrap._gcd_import(name[level:], package, level)
[Mon Nov 02 09:09:48.632875 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
[Mon Nov 02 09:09:48.632884 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "<frozen importlib._bootstrap>", line 991, in _find_and_load
[Mon Nov 02 09:09:48.632893 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
[Mon Nov 02 09:09:48.632902 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[Mon Nov 02 09:09:48.632910 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
[Mon Nov 02 09:09:48.632919 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "<frozen importlib._bootstrap>", line 991, in _find_and_load
[Mon Nov 02 09:09:48.632928 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
[Mon Nov 02 09:09:48.632948 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] ModuleNotFoundError: No module named 'MyApp'
I am not an expert on apache config files so I can't understand why WSGI is called when I'm requesting site-two.
How can I solve this problem?
The site-one.com.eror.log file is empty by the way

HTTP 500 error - Target WSGI script cannot be loaded as Python module

I got the above error while using bitnami django.
All settings done according doc:
https://docs.bitnami.com/virtual-machine/components/django/#production
python version: Python 3.6.4 :: Anaconda, Inc.
django version: 2.0.2-3
wsgi.py:
import os,sys
sys.path.append('/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject')
os.environ.setdefault("PYTHON_EGG_CACHE", "/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/egg_cache")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MyProject.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
httpd-app.conf:
<IfDefine !IS_DJANGOSTACK_LOADED>
Define IS_DJANGOSTACK_LOADED
WSGIDaemonProcess wsgi-djangostack processes=2 threads=15 display-name=%{GROUP}
</IfDefine>
<Directory "/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject">
Options +MultiViews
AllowOverride All
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
WSGIProcessGroup wsgi-djangostack
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
Alias /MyProject/static "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/contrib/admin/static"
WSGIScriptAlias /MyProject '/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject/wsgi.py'
httpd-prefix.conf:
# Include file
Include "/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/conf/httpd-app.conf"
corresponding url added to /Applications/djangostack-2.0.2-3/apache2/conf/bitnami/bitnami-apps-prefix.conf file
But when I'm trying to access app via browser I've got error in log:
[Fri Jun 22 16:37:20.873873 2018] [wsgi:error] [pid 29099] [remote ::1:62098] mod_wsgi (pid=29099): Target WSGI script '/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject/wsgi.py' cannot be loaded as Python module.
[Fri Jun 22 16:37:20.874027 2018] [wsgi:error] [pid 29099] [remote ::1:62098] mod_wsgi (pid=29099): Exception occurred processing WSGI script '/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject/wsgi.py'.
[Fri Jun 22 16:37:20.875482 2018] [wsgi:error] [pid 29099] [remote ::1:62098] Traceback (most recent call last):
[Fri Jun 22 16:37:20.875554 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject/wsgi.py", line 17, in <module>
[Fri Jun 22 16:37:20.875568 2018] [wsgi:error] [pid 29099] [remote ::1:62098] application = get_wsgi_application()
[Fri Jun 22 16:37:20.875584 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/core/wsgi.py", line 12, in get_wsgi_application
[Fri Jun 22 16:37:20.875594 2018] [wsgi:error] [pid 29099] [remote ::1:62098] django.setup(set_prefix=False)
[Fri Jun 22 16:37:20.875608 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/__init__.py", line 24, in setup
[Fri Jun 22 16:37:20.875618 2018] [wsgi:error] [pid 29099] [remote ::1:62098] apps.populate(settings.INSTALLED_APPS)
[Fri Jun 22 16:37:20.875631 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/apps/registry.py", line 89, in populate
[Fri Jun 22 16:37:20.875641 2018] [wsgi:error] [pid 29099] [remote ::1:62098] app_config = AppConfig.create(entry)
[Fri Jun 22 16:37:20.875654 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/apps/config.py", line 90, in create
[Fri Jun 22 16:37:20.875664 2018] [wsgi:error] [pid 29099] [remote ::1:62098] module = import_module(entry)
[Fri Jun 22 16:37:20.875677 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
[Fri Jun 22 16:37:20.875687 2018] [wsgi:error] [pid 29099] [remote ::1:62098] return _bootstrap._gcd_import(name[level:], package, level)
[Fri Jun 22 16:37:20.875700 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[Fri Jun 22 16:37:20.875728 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[Fri Jun 22 16:37:20.875736 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
[Fri Jun 22 16:37:20.875752 2018] [wsgi:error] [pid 29099] [remote ::1:62098] ModuleNotFoundError: No module named 'widget_tweaks'
I have installed widget_tweaks using:
pip3 install django-widget-tweaks
But when I stop Apache and run app using command
python3 manage.py runserver localhost:8080
the app works perfectly fine.
My urls.py under /Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject look like:
from django.contrib import admin
from django.urls import path, include,re_path
urlpatterns = [
path('', include('APP.urls')),
re_path(r'^admin/', admin.site.urls, name='admin'),
]
So I assume error within Apache configuration. Any help or advises will be appreciated!
Thank you Jota for providing one of the solution.
Solution 1:
For Mac OS, when I execute /Applications/djangostack-2.0.2-3/use_djangostack, I enter Bitnami console.
I just had to install all the necessary modules and custom project ran successfully using apache.
Solution 2:
In case you don't wanna use bitnami console,
1) Install mod_wsgi using pip, preferably into a Python virtual environment. Ensure pip is for the version of Python you want to use.
pip install mod_wsgi
2) Display the config to add to Apache configuration file to load this mod_wsgi by running:
mod_wsgi-express module-config
3) Take the output of above command to display config and add to Apache configuration. (httpd.conf file)
4) restart the apache using ctlscript.sh file. In my case the command looked like:
/Applications/djangostack-2.0.2-3/ctlscript.sh restart apache
5) After restarting, my custom project ran successfully.
Regards,
Amey Kelekar

ImproperlyConfigured: Error loading psycopg2 module: No module named cffi

I developed a platform with django + wsgi + pypy + postgresql + postgis, everything works fine in development environment, but in production it sends error 500 and in the apache log it says ImproperlyConfigured: Error loading psycopg2 module: No module named cffi
my config apache:
<VirtualHost *:80>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIScriptAlias / /home/user/plataform/project/project/wsgi.py
WSGIDaemonProcess project python-path=/home/user/plataform/project:/home/user/env/site-packages
WSGIProcessGroup project
WSGIPassAuthorization On
<Directory /home/user/plataform/project/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /media /home/user/plataform/project/media/
Alias /static /home/user/plataform/project/static/
<Directory /home/user/plataform/project/static>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /home/user/plataform/project/media>
Require all granted
</Directory>
my pip freeze
cffi==1.6.0
Django==1.11.7
django-cors-headers==2.1.0
django-filter==1.1.0
djangorestframework==3.7.3
greenlet==0.4.9
Markdown==2.6.9
olefile==0.44
Pillow==4.3.0
psycopg2cffi==2.7.7
python-stdnum==1.7
pytz==2017.3
readline==6.2.4.1
six==1.11.0
uWSGI==2.0.15
Log Apache:
[Tue Dec 12 11:15:49.727998 2017] [wsgi:warn] [pid 4975:tid 139854422423424] mod_wsgi: Compiled for Python/2.7.11.
[Tue Dec 12 11:15:49.728151 2017] [wsgi:warn] [pid 4975:tid 139854422423424] mod_wsgi: Runtime using Python/2.7.12.
[Tue Dec 12 11:15:49.729853 2017] [mpm_event:notice] [pid 4975:tid 139854422423424] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/2.7.12 configured -- resuming normal operations
[Tue Dec 12 11:15:49.729893 2017] [core:notice] [pid 4975:tid 139854422423424] AH00094: Command line: '/usr/sbin/apache2'
[Tue Dec 12 11:15:59.608678 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] mod_wsgi (pid=4978): Target WSGI script '/home/user/plataform/project/project/wsgi.py' cannot be loaded as Python module.
[Tue Dec 12 11:15:59.608785 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] mod_wsgi (pid=4978): Exception occurred processing WSGI script '/home/user/plataform/project/project/wsgi.py'.
[Tue Dec 12 11:15:59.608821 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] Traceback (most recent call last):
[Tue Dec 12 11:15:59.608859 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/plataform/project/project/wsgi.py", line 16, in <module>
[Tue Dec 12 11:15:59.608957 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] application = get_wsgi_application()
[Tue Dec 12 11:15:59.608974 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Tue Dec 12 11:15:59.609017 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] django.setup(set_prefix=False)
[Tue Dec 12 11:15:59.609032 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/__init__.py", line 27, in setup
[Tue Dec 12 11:15:59.609090 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] apps.populate(settings.INSTALLED_APPS)
[Tue Dec 12 11:15:59.609112 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/apps/registry.py", line 108, in populate
[Tue Dec 12 11:15:59.609256 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] app_config.import_models()
[Tue Dec 12 11:15:59.609277 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/apps/config.py", line 202, in import_models
[Tue Dec 12 11:15:59.609366 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] self.models_module = import_module(models_module_name)
[Tue Dec 12 11:15:59.609389 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Tue Dec 12 11:15:59.609451 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] __import__(name)
[Tue Dec 12 11:15:59.609465 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/contrib/auth/models.py", line 4, in <module>
[Tue Dec 12 11:15:59.609580 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
[Tue Dec 12 11:15:59.609593 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
[Tue Dec 12 11:15:59.609671 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] class AbstractBaseUser(models.Model):
[Tue Dec 12 11:15:59.609686 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/models/base.py", line 124, in __new__
[Tue Dec 12 11:15:59.610123 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] new_class.add_to_class('_meta', Options(meta, app_label))
[Tue Dec 12 11:15:59.610139 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/models/base.py", line 325, in add_to_class
[Tue Dec 12 11:15:59.610194 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] value.contribute_to_class(cls, name)
[Tue Dec 12 11:15:59.610216 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/models/options.py", line 214, in contribute_to_class
[Tue Dec 12 11:15:59.610429 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
[Tue Dec 12 11:15:59.610446 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/__init__.py", line 33, in __getattr__
[Tue Dec 12 11:15:59.610507 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] return getattr(connections[DEFAULT_DB_ALIAS], item)
[Tue Dec 12 11:15:59.610521 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/utils.py", line 211, in __getitem__
[Tue Dec 12 11:15:59.610608 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] backend = load_backend(db['ENGINE'])
[Tue Dec 12 11:15:59.610621 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/utils.py", line 115, in load_backend
[Tue Dec 12 11:15:59.610637 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] return import_module('%s.base' % backend_name)
[Tue Dec 12 11:15:59.610646 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Tue Dec 12 11:15:59.610660 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] __import__(name)
[Tue Dec 12 11:15:59.610668 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 2, in <module>
[Tue Dec 12 11:15:59.610706 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] from django.db.backends.postgresql.base import (
[Tue Dec 12 11:15:59.610733 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/backends/postgresql/base.py", line 25, in <module>
[Tue Dec 12 11:15:59.610870 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
[Tue Dec 12 11:15:59.610901 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] ImproperlyConfigured: Error loading psycopg2 module: No module named cffi
I made a clean installation of pypy and created a new virtual environment, then changed the conf. of apache for this
<VirtualHost *:80>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIScriptAlias / /home/user/plataform/project/project/wsgi.py
WSGIDaemonProcess project python-path=/home/user/plataform/project:/home/user/env/site-packages
WSGIProcessGroup project
WSGIPassAuthorization On
<Directory /home/user/plataform/project/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /media/ /home/user/plataform/project/media
Alias /static/ /home/user/plataform/project/static
<Directory /home/user/plataform/project/static>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /home/user/plataform/project/media>
Require all granted
</Directory>
</Virtualhost>
and everything worked well