Open CP-Tadeo opened 1 month ago
You have added a few overlapping different things to configure the virtual environment which we need to fix first.
Instead of:
WSGIDaemonProcess capacity_management python-home=/home/ec2-user/capacity_management/myenv python-path=/home/ec2-user/capacity_management/myenv/lib64/python3.7/site-packages
use:
WSGIDaemonProcess capacity_management python-home=/home/ec2-user/capacity_management/myenv python-path=/var/www/html/capacity_management
This does not add site-packages
to python-path
and instead uses python-path
to set the location of your Python project code. Do see note about location about that below though.
You don't need any of the following in the WSGI script file.
# Specify the path to the virtual environment
#venv_path = '/var/www/html/capacity_management/myenv'
venv_path = '/home/ec2-user/capacity_management/myenv'
# Use the virtual environment's Python interpreter
sys.path.insert(0, os.path.join(venv_path, 'lib', 'python3.7', 'site-packages'))
# Activate the virtual environment
activate_env = os.path.join(venv_path, 'bin', 'activate_this.py')
with open(activate_env) as f:
exec(f.read(), {'__file__': activate_env})
This is handled by the WSGIDaemonProcess
options for python-home
.
Also don't use:
# Add the project directory to the Python path
sys.path.insert(0, '/var/www/html/capacity_management')
Rely on the python-path
setting on WSGIDaemonProcess
instead.
For good measure, after:
WSGIPythonHome "/home/ec2-user/capacity_management/myenv"
add:
WSGIRestrictEmbedded On
This disables mod_wsgi for Apache worker processes and only allows Python interpreter usable by mod_wsgi daemon processes.
I don't believe these issues in themselves should be the cause of the problem though.
Also check that you don't have a wsgi.load
file somewhere in the Apache configuration files placed there by a system package for mod_wsgi which is loading a mod_wsgi.so
from Apache modules directory. In other words, you need to ensure not loading system package for mod_wsgi since you are using mod_wsgi installed to the virtual environment. Use a2dismod
or other appropriate Apache system command to disable use of system package for mod_wsgi by Apache if necessary. That said, if you don't have system package for mod_wsgi installed, it can still be valid that you have manually created wsgi.load
and enabled use of it if with contents of:
LoadModule wsgi_module "/home/ec2-user/capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so"
WSGIPythonHome "/home/ec2-user/capacity_management/myenv"
Next check that the user home directory /home/ec2-user
is accessible to the Apache user.
By default various Linux systems have the home directory with permissions drwx------
. You want it to be drwxr-xr-x
. If it doesn't have r-x
for others, Apache user will not be able to load anything from the home directory.
Also be aware that it is bad practice to place your Python project code under /var/www/html
as it appears you might since you are adding /var/www/html/capacity_management
to Python path. By placing source code under that parent directory, it puts it in a location where depending on other Apache configuration could mean that users could download your source code.
After making these changes make sure you do a full stop of the Apache server and restart it. Not a reload. That or restart the whole VM. This is to ensure that Apache has no cached loading of an old mod_wsgi module in memory.
Finally, don't use Anaconda Python if you are. Use standard Python distro supplied with Linux system. The Anaconda Python distribution doesn't always work as they keep breaking the ability for it to be embedded.
Thank you for pointing out the overlapping configurations!
I have now modified the files accordingly:
virtual environment config: LoadModule wsgi_module "/home/ec2-user/capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so" WSGIPythonHome "/home/ec2-user/capacity_management/myenv" WSGIRestrictEmbedded On
<VirtualHost *:80> ServerName capacity_management ServerAlias www.capacity_management
DocumentRoot /var/www/html/capacity_management
WSGIDaemonProcess capacity_management python-home=/home/ec2-user/capacity_management/myenv python-path=/var/www/html/capacity_management
WSGIScriptAlias / /var/www/html/capacity_management/main.wsgi
<Directory /var/www/html/capacity_management>
Options +ExecCGI +FollowSymlinks
AllowOverride None
AddHandler wsgi-script .wsgi
WSGIProcessGroup capacity_management
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Require all granted
</Directory>
ErrorLog /var/log/httpd/error_log
CustomLog /var/log/httpd/access_log combined
main.wsgi is just now this:
import os import sys import logging
logging.basicConfig(stream=sys.stderr)
I also checked the permissions, and it looks like Apache user has access to the directories. But after all these changes, after restarting (sudo systemctl restart httpd) the error remains the same.
Regarding your point about having a system package for mod_wsgi installed, I checked using rpm -qa | grep mod_wsgi, and it returned that I have python3-mod_wsgi-3.4-12.amzn2.0.3.x86_64 installed. Would that be the system package for mod_wsgi that you are referring to, or not?
Yes that is the system package for mod_wsgi and given that it is for Python 3.4, if there were a separate LoadModule
directive somewhere in the Apache configuration which was loading it, you could see the exact error you are seeing.
In other words, you cannot load multiple versions of Apache modules. Thus you must load the correct mod_wsgi module for the Python version you need.
Thus, double check your Apache configuration directory for any other LoadModule
directives related to mod_wsgi that may conflict.
For many Linux systems they often have mods-available
directory with .load
files for modules. These are then symlinked into the mods-enabled
directory. So make sure you don't have a wsgi.load
file in those places. If you have that file in mods-available
and you didn't place it there manually, and it is symlinked into mods-enabled
, try running:
a2dismod wsgi
and restart Apache. Note that the command to disable the loading of the system package mod_wsgi may different depending on your Linux distribution.
Best thing to do is actually uninstall the whole system package for mod_wsgi if that isn't what you are using.
Would it also be possible that this error shhows up if Apache does not have access to the directory where the Python files are? I know you made this point earlier but I just wanted to ask if I got that right
Yes, because although the mod_wsgi dynamically loaded module file is loaded from the Apache parent process, which runs as root
and thus can always be loaded, the call into the module to initialize it is only done in the forked processes after root
privileges have been dropped and everything runs as the Apache user.
Home directories for users on some Linux distributions are not readable/accessible to any other users, such as the user that Apache runs as, so the Python distribution files cannot therefore be found.
This means you may need to do:
chmod go+rx /home/ec2-user
Although that is still dependent on all directories down to where the Python virtual environment is located, plus Python project code, are also being readable/accessible.
If you don't want to change permissions on the user directory, the alternative is to create the Python virtual environment and host project code in a directory under /usr/local
(or /var/www
, but not /var/www/html
) where there are usually no inherited restrictions on access.
Do be careful though that if setting up the Python virtual environment and project code areas as root
user, that the root
user is not using a umask
of 0700
because if it is, then access permissions on directories and files will not allow access to group and other even if created under /usr/local
.
After a bit of looking again, running outside of my virtual environment I checked again for the installed mod_wsgi using rpm -qa | grep mod_wsgi, and it looks like I have two of them: python2-mod_wsgi-3.4-12.amzn2.0.3.x86_64 python3-mod_wsgi-3.4-12.amzn2.0.3.x86_64
Is it possible these are the ones causing the error? Although I am not sure myself which ones Apache uses. I tried to look for the files and I found one that mentions which mod_wsgi it uses.
It all comes down to whether or not they are loading into Apache or not. Find the root directory for the Apache configuration and run in that directory:
grep -r LoadModule .
and see where you can find a LoadModule
directive which mentions wsgi
in name. Post the output here so I can check.
I ran that line and I think it shows the conflicts, but I am not sure because there are many lines.
These were the output:
./.bash_history:LoadModule wsgi_module "/home/ec2-user/capacity_management/myenv /lib64/python3.7/site-packages/mod_wsgi/server/mod_wsgi-py37.cpython-37m-x86_64- linux-gnu.so"
Binary file ./.nvm/versions/node/v16.0.0/bin/node matches
Binary file ./Katie/env/lib/python3.11/site-packages/triton/_C/libtriton.so matc hes
Binary file ./Katie/env/lib/python3.11/site-packages/torch/lib/libtorch_cpu.so m atches
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule version_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_version.so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule mpm_prefork_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_mpm_prefo rk.so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule mpm_event_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_mpm_event.s o'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule mpm_worker_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_mpm_worker .so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule mpm_prefork_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_mpm_prefo rk.so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule http2_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_http2.so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule access_compat_module '${MOD_WSGI_MODULES_DIRECTORY}/modaccess compat.so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule unixd_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_unixd.so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule authn_core_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_authn_core .so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule authz_core_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_authz_core .so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule authz_host_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_authz_host .so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule mime_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_mime.so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule rewrite_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_rewrite.so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule alias_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_alias.so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule dir_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_dir.so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule env_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_env.so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule headers_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_headers.so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule filter_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_filter.so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule autoindex_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_autoindex.s o'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule reqtimeout_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_reqtimeout .so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule deflate_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_deflate.so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule auth_basic_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_auth_basic .so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule auth_digest_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_auth_dige st.so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule authz_user_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_authz_user .so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule proxy_module ${MOD_WSGI_MODULES_DIRECTORY}/mod_proxy.so
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule proxy_http_module ${MOD_WSGI_MODULES_DIRECTORY}/mod_proxy_http. so
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule wsgi_module '%(mod_wsgi_so)s'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule status_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_status.so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule cgid_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_cgid.so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule cgi_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_cgi.so'
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule log_config_module ${MOD_WSGI_MODULES_DIRECTORY}/mod_log_config. so
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py:LoadModule ssl_module ${MOD_WSGI_MODULES_DIRECTORY}/mod_ssl.so
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py: print('LoadModule wsgi_module "%s"' % module_path)
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py: print('LoadModule wsgi_module "%s"' % module_path)
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/init .py: print('LoadModule wsgi_module "%s"' % target)
Binary file ./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/s erver/pycache/init.cpython-37.pyc matches
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi-4.9.4.dist-in fo/METADATA: LoadModule wsgi_module /usr/local/lib/python2.7/site-packages/mo d_wsgi/server/mod_wsgi-py27.so
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi-4.9.4.dist-in fo/METADATA: LoadModule wsgi_module modules/mod_wsgi-py27.so
./capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi-4.9.4.dist-in fo/METADATA:Apache modules directory first and the LoadModule
directive refe rences
You are not in the system Apache configuration directory. You want the directory containing the config files where you have been adding your customisations for Apache. If it is /etc/apache2
directory for example you want to do:
cd /etc/apache2
grep -r LoadModule .
Oh ok my bad.
The root directory for them would be /etc/httpd/ in my scenario, and these were the results:
./conf.d/capacity_management.conf:#LoadModule wsgi_module "/home/ec2-user/capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so"
./conf/httpd.conf:# have to place corresponding LoadModule' lines at this location so the ./conf/httpd.conf:# LoadModule foo_module modules/mod_foo.so ./conf/httpd.conf.rpmsave.bak:# have to place corresponding
LoadModule' lines at this location so the
./conf/httpd.conf.rpmsave.bak:# LoadModule foo_module modules/mod_foo.so
./conf.modules.d/10-h2.conf:LoadModule http2_module modules/mod_http2.so
./conf.modules.d/10-proxy_h2.conf:LoadModule proxy_http2_module modules/mod_proxy_http2.so
./conf.modules.d/00-base.conf:LoadModule access_compat_module modules/mod_access_compat.so
./conf.modules.d/00-base.conf:LoadModule actions_module modules/mod_actions.so
./conf.modules.d/00-base.conf:LoadModule alias_module modules/mod_alias.so
./conf.modules.d/00-base.conf:LoadModule allowmethods_module modules/mod_allowmethods.so
./conf.modules.d/00-base.conf:LoadModule auth_basic_module modules/mod_auth_basic.so
./conf.modules.d/00-base.conf:LoadModule auth_digest_module modules/mod_auth_digest.so
./conf.modules.d/00-base.conf:LoadModule authn_anon_module modules/mod_authn_anon.so
./conf.modules.d/00-base.conf:LoadModule authn_core_module modules/mod_authn_core.so
./conf.modules.d/00-base.conf:LoadModule authn_dbd_module modules/mod_authn_dbd.so
./conf.modules.d/00-base.conf:LoadModule authn_dbm_module modules/mod_authn_dbm.so
./conf.modules.d/00-base.conf:LoadModule authn_file_module modules/mod_authn_file.so
./conf.modules.d/00-base.conf:LoadModule authn_socache_module modules/mod_authn_socache.so
./conf.modules.d/00-base.conf:LoadModule authz_core_module modules/mod_authz_core.so
./conf.modules.d/00-base.conf:LoadModule authz_dbd_module modules/mod_authz_dbd.so
./conf.modules.d/00-base.conf:LoadModule authz_dbm_module modules/mod_authz_dbm.so
./conf.modules.d/00-base.conf:LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
./conf.modules.d/00-base.conf:LoadModule authz_host_module modules/mod_authz_host.so
./conf.modules.d/00-base.conf:LoadModule authz_owner_module modules/mod_authz_owner.so
./conf.modules.d/00-base.conf:LoadModule authz_user_module modules/mod_authz_user.so
./conf.modules.d/00-base.conf:LoadModule autoindex_module modules/mod_autoindex.so
./conf.modules.d/00-base.conf:LoadModule cache_module modules/mod_cache.so
./conf.modules.d/00-base.conf:LoadModule cache_disk_module modules/mod_cache_disk.so
./conf.modules.d/00-base.conf:LoadModule cache_socache_module modules/mod_cache_socache.so
./conf.modules.d/00-base.conf:LoadModule data_module modules/mod_data.so
./conf.modules.d/00-base.conf:LoadModule dbd_module modules/mod_dbd.so
./conf.modules.d/00-base.conf:LoadModule deflate_module modules/mod_deflate.so
./conf.modules.d/00-base.conf:LoadModule dir_module modules/mod_dir.so
./conf.modules.d/00-base.conf:LoadModule dumpio_module modules/mod_dumpio.so
./conf.modules.d/00-base.conf:LoadModule echo_module modules/mod_echo.so
./conf.modules.d/00-base.conf:LoadModule env_module modules/mod_env.so
./conf.modules.d/00-base.conf:LoadModule expires_module modules/mod_expires.so
./conf.modules.d/00-base.conf:LoadModule ext_filter_module modules/mod_ext_filter.so
./conf.modules.d/00-base.conf:LoadModule filter_module modules/mod_filter.so
./conf.modules.d/00-base.conf:LoadModule headers_module modules/mod_headers.so
./conf.modules.d/00-base.conf:LoadModule include_module modules/mod_include.so
./conf.modules.d/00-base.conf:LoadModule info_module modules/mod_info.so
./conf.modules.d/00-base.conf:LoadModule log_config_module modules/mod_log_config.so
./conf.modules.d/00-base.conf:LoadModule logio_module modules/mod_logio.so
./conf.modules.d/00-base.conf:LoadModule macro_module modules/mod_macro.so
./conf.modules.d/00-base.conf:LoadModule mime_magic_module modules/mod_mime_magic.so
./conf.modules.d/00-base.conf:LoadModule mime_module modules/mod_mime.so
./conf.modules.d/00-base.conf:LoadModule negotiation_module modules/mod_negotiation.so
./conf.modules.d/00-base.conf:LoadModule remoteip_module modules/mod_remoteip.so
./conf.modules.d/00-base.conf:LoadModule reqtimeout_module modules/mod_reqtimeout.so
./conf.modules.d/00-base.conf:LoadModule request_module modules/mod_request.so
./conf.modules.d/00-base.conf:LoadModule rewrite_module modules/mod_rewrite.so
./conf.modules.d/00-base.conf:LoadModule setenvif_module modules/mod_setenvif.so
./conf.modules.d/00-base.conf:LoadModule slotmem_plain_module modules/mod_slotmem_plain.so
./conf.modules.d/00-base.conf:LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
./conf.modules.d/00-base.conf:LoadModule socache_dbm_module modules/mod_socache_dbm.so
./conf.modules.d/00-base.conf:LoadModule socache_memcache_module modules/mod_socache_memcache.so
./conf.modules.d/00-base.conf:LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
./conf.modules.d/00-base.conf:LoadModule status_module modules/mod_status.so
./conf.modules.d/00-base.conf:LoadModule substitute_module modules/mod_substitute.so
./conf.modules.d/00-base.conf:LoadModule suexec_module modules/mod_suexec.so
./conf.modules.d/00-base.conf:LoadModule unique_id_module modules/mod_unique_id.so
./conf.modules.d/00-base.conf:LoadModule unixd_module modules/mod_unixd.so
./conf.modules.d/00-base.conf:LoadModule userdir_module modules/mod_userdir.so
./conf.modules.d/00-base.conf:LoadModule version_module modules/mod_version.so
./conf.modules.d/00-base.conf:LoadModule vhost_alias_module modules/mod_vhost_alias.so
./conf.modules.d/00-base.conf:LoadModule watchdog_module modules/mod_watchdog.so
./conf.modules.d/00-dav.conf:LoadModule dav_module modules/mod_dav.so
./conf.modules.d/00-dav.conf:LoadModule dav_fs_module modules/mod_dav_fs.so
./conf.modules.d/00-dav.conf:LoadModule dav_lock_module modules/mod_dav_lock.so
./conf.modules.d/00-lua.conf:LoadModule lua_module modules/mod_lua.so
./conf.modules.d/00-mpm.conf:# one of the following LoadModule lines. See the httpd.service(8) man
./conf.modules.d/00-mpm.conf:LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
./conf.modules.d/00-mpm.conf:#LoadModule mpm_worker_module modules/mod_mpm_worker.so
./conf.modules.d/00-mpm.conf:#LoadModule mpm_event_module modules/mod_mpm_event.so
./conf.modules.d/00-optional.conf:#LoadModule asis_module modules/mod_asis.so
./conf.modules.d/00-optional.conf:#LoadModule buffer_module modules/mod_buffer.so
./conf.modules.d/00-optional.conf:#LoadModule heartbeat_module modules/mod_heartbeat.so
./conf.modules.d/00-optional.conf:#LoadModule heartmonitor_module modules/mod_heartmonitor.so
./conf.modules.d/00-optional.conf:#LoadModule usertrack_module modules/mod_usertrack.so
./conf.modules.d/00-optional.conf:#LoadModule dialup_module modules/mod_dialup.so
./conf.modules.d/00-optional.conf:#LoadModule charset_lite_module modules/mod_charset_lite.so
./conf.modules.d/00-optional.conf:#LoadModule log_debug_module modules/mod_log_debug.so
./conf.modules.d/00-optional.conf:#LoadModule log_forensic_module modules/mod_log_forensic.so
./conf.modules.d/00-optional.conf:#LoadModule ratelimit_module modules/mod_ratelimit.so
./conf.modules.d/00-optional.conf:#LoadModule reflector_module modules/mod_reflector.so
./conf.modules.d/00-optional.conf:#LoadModule sed_module modules/mod_sed.so
./conf.modules.d/00-optional.conf:#LoadModule speling_module modules/mod_speling.so
./conf.modules.d/00-proxy.conf:LoadModule proxy_module modules/mod_proxy.so
./conf.modules.d/00-proxy.conf:LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so
./conf.modules.d/00-proxy.conf:LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
./conf.modules.d/00-proxy.conf:LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so
./conf.modules.d/00-proxy.conf:LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so
./conf.modules.d/00-proxy.conf:LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
./conf.modules.d/00-proxy.conf:LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
./conf.modules.d/00-proxy.conf:LoadModule proxy_connect_module modules/mod_proxy_connect.so
./conf.modules.d/00-proxy.conf:LoadModule proxy_express_module modules/mod_proxy_express.so
./conf.modules.d/00-proxy.conf:LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
./conf.modules.d/00-proxy.conf:LoadModule proxy_fdpass_module modules/mod_proxy_fdpass.so
./conf.modules.d/00-proxy.conf:LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
./conf.modules.d/00-proxy.conf:LoadModule proxy_http_module modules/mod_proxy_http.so
./conf.modules.d/00-proxy.conf:LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so
./conf.modules.d/00-proxy.conf:LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
./conf.modules.d/00-proxy.conf:LoadModule proxy_uwsgi_module modules/mod_proxy_uwsgi.so
./conf.modules.d/00-proxy.conf:LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
./conf.modules.d/00-systemd.conf:LoadModule systemd_module modules/mod_systemd.so
./conf.modules.d/01-cgi.conf: LoadModule cgid_module modules/mod_cgid.so
./conf.modules.d/01-cgi.conf: LoadModule cgid_module modules/mod_cgid.so
./conf.modules.d/01-cgi.conf: LoadModule cgi_module modules/mod_cgi.so
./conf.modules.d/10-wsgi-python3.conf: LoadModule wsgi_module modules/mod_wsgi_python3.so
./conf.modules.d/10-wsgi.conf:LoadModule wsgi_module modules/mod_wsgi.so
If you can't uninstall the two system packages for mod_wsgi, you must at least comment out these two lines:
./conf.modules.d/10-wsgi-python3.conf: LoadModule wsgi_module modules/mod_wsgi_python3.so
./conf.modules.d/10-wsgi.conf:LoadModule wsgi_module modules/mod_wsgi.so
They conflict with each other for a start and is wrong for both to be there.
They also conflict with the LoadModule
line you added to use mod_wsgi from the Python virtual environment.
I tried that and oh wow, I think that actually removed the initial FatalError problem?
Now however there is a new error:
[Tue Jul 09 23:08:45.562177 2024] [wsgi:error] [pid 2287] [remote 180.190.141.58:19697] mod_wsgi (pid=2287): Target WSGI script '/var/www/html/capacity_management/main.wsgi' does not contain WSGI application 'application'.
Related to main.wsgi.
That is because you commented out the line:
#from app import app as application
and thus there is no application
object.
Oh, thank you for pointing that out, now the Apache server is finally up and running!
I have a question, since the cause of the error seems to be the LoadModule lines in 10-wsgi-python3.conf and 10-wsgi.conf. So does this mean I can keep only one uncommented in (either in 10-wsgi-python3.conf or 10-wsgi.conf), and the application would still work? Because my understanding was it seems that LoadModule was loading mod_wsgi.so from multiple places.
You had three LoadModule
lines.
The two put there by the two system packages for mod_wsgi, and the one you added pointing at mod_wsgi installed into the virtual environment.
You MUST only have one active LoadModule for mod_wsgi.
Since you built mod_wsgi by running pip install
, you should uninstall the two system mod_wsgi packages. If you do that the conf.modules.d/10-wsgi-python3.conf
and conf.modules.d/10-wsgi.conf
files should be removed as they are part of the system packages.
This would leave just the one you added manually, which is the only one you want to be active.
LoadModule wsgi_module "/home/ec2-user/capacity_management/myenv/lib64/python3.7/site-packages/mod_wsgi/server/mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so"
WSGIPythonHome "/home/ec2-user/capacity_management/myenv"
If you can't work out how to uninstall the two mod_wsgi system packages, you must keep contents of both those files commented out. Do be aware though that updating the system may cause the packages to be updated and the files reverted to the originals, loosing the edit you add to comment out the lines. Thus is better to uninstall the packages if you can.
Oh ok, that makes sense. looks like Ill have to work on that soon.
Would it be ok to ask about another problem? Because at this point I am setting up the ssl/tls certificate for my website, but somehow apache isnt reading it and i am not sure why, when the directories are correct. Can you give me some tips on this?
Create a separate issue if have different question. Post details in that new issue of how you have VirtualHost
definitions setup. A common mistake is people assuming they can use an IP address for ServerName
in the VirtualHost
rather than a fully qualified domain name (FQDN). So isn't so much that SSL configuration isn't used, but that the VirtualHost
is never matched and used for the host.
Hello, this is my first time using Apache, as well as Amazon Linux 2, and while I have been trying to configure it for days, I am stuck in this error for days now. I tried doing multiple configurations but to no avail, the errors are still the same. I looked into previous threads and it seems they found a solution but I cant seem to find a solution for my problem.
Here are some of the config files and their contents:
apache config
My main.wsgi:
running mod_wsgi-express module-config:
I am not sure what to do next. Any help regarding this would be greatly appreciated!