GrahamDumpleton / mod_wsgi

Source code for Apache/mod_wsgi.
Apache License 2.0
1.02k stars 268 forks source link

'module' object has no attribute 'getuid' #222

Closed janekpel closed 6 years ago

janekpel commented 7 years ago

Hi, I'm trying to run mod_wsgi on Windows Server.

I installed Apache: Server version: Apache/2.4.23 (Win64) Server built: Jul 9 2016 11:59:00 and Python 3.4.4

Like it was written here https://github.com/GrahamDumpleton/mod_wsgi/blob/develop/README.rst i run pip install mod_wsgi and modified httpd.conf.

The server starts. But when I run python manage.py runmodwsgi I get an error:

C:\octo-master>python manage.py runmodwsgi Successfully ran command. Traceback (most recent call last): File "manage.py", line 22, in execute_from_command_line(sys.argv) File "C:\Python34\lib\site-packages\django\core\management__init__.py", line 363, in execute_from_command_line utility.execute() File "C:\Python34\lib\site-packages\django\core\management__init.py", line 355, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Python34\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv self.execute(*args, *cmd_options) File "C:\Python34\lib\site-packages\django\core\management\base.py", line 330, in execute output = self.handle(args, **options) File "C:\Python34\lib\site-packages\mod_wsgi\server\management\commands\runmod wsgi.py", line 120, in handle 'start-server', args, options) File "C:\Python34\lib\site-packages\mod_wsgi\server\init__.py", line 2625, i n _cmd_setup_server options['port'], os.getuid()) AttributeError: 'module' object has no attribute 'getuid'

Could you help me with this?

GrahamDumpleton commented 7 years ago

It is not possible to use the mod_wsgi-express start-server or the Django management command integration on Windows.

On Windows you should run:

mod-wsgi-express module-config

Take the output from that and add it to your Apache configuration in order to load mod_wsgi module into Apache.

Then configure Apache/mod_wsgi for your specific WSGI application. For Django you can find details at:

Be aware that on Windows you cannot use daemon mode of mod_wsgi.

janekpel commented 7 years ago

Thank you for the replay. i did the mod-wsgi-express module-config before and modified the configuration file (httpd.conf). The sevrev is starting and when I check with httpd -M I get that mod_wsgi was loaded:

C:\Users\Administrator>httpd -M Loaded Modules: core_module (static) win32_module (static) mpm_winnt_module (static) http_module (static) so_module (static) access_compat_module (shared) actions_module (shared) alias_module (shared) allowmethods_module (shared) asis_module (shared) auth_basic_module (shared) authn_core_module (shared) authn_file_module (shared) authz_core_module (shared) authz_groupfile_module (shared) authz_host_module (shared) authz_user_module (shared) autoindex_module (shared) cgi_module (shared) dir_module (shared) env_module (shared) include_module (shared) isapi_module (shared) log_config_module (shared) mime_module (shared) negotiation_module (shared) setenvif_module (shared) wsgi_module (shared)

I guess the last sentence

Be aware that on Windows you cannot use daemon mode of mod_wsgi.

is the clue. Thant you for help.

wondie commented 7 years ago

Thank you for the great work GrahamDumpleton. I had exactly the same issue. It would be nice to include it in the documentation that mod_wsgi-express start-server doesn't work for windows.

When I used mod-wsgi-express module-config, I got the following output.

LoadModule wsgi_module "c:/xampp/htdocs/envs/lib/site-packages/mod_wsgi/server/mod_wsgiNone"
WSGIPythonHome "c:/xampp/htdocs/envs"

I also checked the mod_wsgi.so file in server directory and it no there. Is there a download link for mod_wsgi.so compatable with mod_wsgi 4.5.18?

GrahamDumpleton commented 7 years ago

Try:

LoadModule wsgi_module "c:/xampp/htdocs/envs/lib/site-packages/mod_wsgi/server/mod_wsgi.pyd"
WSGIPythonHome "c:/xampp/htdocs/envs"

For Python 2.7, it is sometimes generating the extension on the path wrong. I have tried on numerous occasions to try and get people who experience the issue to help me debug it, but no luck in getting any help still.

Do note that you should not use Python 2.7 if you can avoid it, use Python 3.6. The chances of Python 2.7 not working are very high because it isn't possible to get a recent Apache 2.4 distribution which is compiled for VC9 compiler. There is no guarantee that VC 9 mod_wsgi module will work with Apache 2.4 compiled with VC14.

wondie commented 7 years ago

Thank you for the quick response. I tried the setting you suggested but apache failed to start.

I am ready to help you debug the issue please.

Unfortunately, I have no choice but to use Python 2.7 as GeoDjango dependencies are mostly based on 2.7.

GrahamDumpleton commented 7 years ago

The debugging relates to the extension as generated by module-config. Fixing that will not resolve issue that Apache will not start.

Anyway, to verify the extension, what is in the directory:

c:/xampp/htdocs/envs/lib/site-packages/mod_wsgi/server

Also what Apache distro are you using?

Are you starting it as a service?

Is Python installed for all users and not just yourself?

If running as a service, will the user the service runs as have access to the directory where the mod_wsgi module is located?

wondie commented 7 years ago

Oh ok. Below is the files in the server path. image I am using xampp 3.2.2 with Apache 2.4.26

Yes I have enabled it to run as service by checking it here. image

But I couldn't see it in the Windows Services.

Python is installed for all users. It is located in C:/Python27 and I always install programs for all users.

Yes, the user has access.

GrahamDumpleton commented 7 years ago

What is the exact error that Apache logs due to failing to start up?

wondie commented 7 years ago

I get this on xampp log.


10:40:22 AM  [Apache]   Attempting to start Apache app...
10:40:22 AM  [Apache]   Status change detected: running
10:40:23 AM  [Apache]   Status change detected: stopped
10:40:23 AM  [Apache]   Error: Apache shutdown unexpectedly.
10:40:23 AM  [Apache]   This may be due to a blocked port, missing dependencies, 
10:40:23 AM  [Apache]   improper privileges, a crash, or a shutdown by another method.
10:40:23 AM  [Apache]   Press the Logs button to view error logs and check
10:40:23 AM  [Apache]   the Windows Event Viewer for more clues
10:40:23 AM  [Apache]   If you need more help, copy and post this
10:40:23 AM  [Apache]   entire log window on the forums

I couldn't find anything in Windows Event Viewer.

Is my configuration ok? I have wsgi.conf which is linked in httpd.conf.

wsgi.conf


WSGIPythonHome "c:/xampp/htdocs/envs"
WSGIScriptAlias /portal_api "c:/xampp/htdocs/envs/portal_api/portal_api/wsgi.py"
WSGIApplicationGroup %{GLOBAL}

WSGIPythonPath "c:/xampp/htdocs/envs/portal_api"

<Directory "c:/xampp/htdocs/envs/portal_api/portal_api/">
    <Files wsgi.py>
        Order deny,allow
        Require all granted
    </Files>
</Directory>

Alias /static/ c:/xampp/htdocs/envs/portal_api/web_map/static/
<Directory "c:/xampp/htdocs/envs/portal_api/web_map/static/">
    Order deny,allow
    Allow from all
    Require all granted
</Directory>

At the end of httpd.conf

LoadModule wsgi_module "c:/xampp/htdocs/envs/lib/site-packages/mod_wsgi/server/mod_wsgi.pyd"
Include c:/xampp/htdocs/envs/apache/wsgi.conf
GrahamDumpleton commented 7 years ago

If you run the command line Python and do:

import sys
print(sys.prefix)

what do you get?

The value of WSGIPythonHome does look a bit strange as it is supposed to be the root directory of the Python virtual environment if using one.

Also, where is the Python 2.7 DLL installed?

You can try adding:

LoadFile c:/some/path/PYTHON27.DLL

before the LoadModule.

Just work out what actual path of Python 2.7 DLL is and use that path.

wondie commented 7 years ago

I gotC:\xampp\htdocs\envs Yes the path is the root of Python virtual environment - virtualenv I couldn't find PYTHON27.DLL in both C:\xampp\htdocs\envs folder or C:/Python27 folder.

wondie commented 7 years ago

Of course, the path C:\xampp\htdocs\envs appears when virtualenv is activated. Otherwise, I get C:/Python27

GrahamDumpleton commented 7 years ago

The DLL may be in the Windows system directories.

Do you happen to know of any tools you can run on mod_wsgi.pyd to see what libraries it is linking and where they are coming from? In other words, dependency walker.

wondie commented 7 years ago

I got python27.dll in C:/Windows/SysWOW64/python27.dll Then I add the code as you have suggested: LoadFile C:/Windows/SysWOW64/python27.dll However, apache couldn't still start. I opened mod_wsgi.pyd with dependency walker and got the following. image

It looks like mod_wsgi.pyd tries to load python27.dll from the same directory where mod_wsgi.pyd is located.

GrahamDumpleton commented 7 years ago

The error about different CPU types is a worry.

It is important that you have 64 bit versions of Compiler tool chain, Python and Apache. If there is a mix of 32 and 64 bit it can fail.

Using LoadFile should avoid problems with Python27.DLL not being found on normal search path.

The LIBHTTPD.DLL and LIBAPR*.DLL shouldn't matter as Apache has already loaded them and so should be resolved.

Is MSVCR90.DLL on the system. Missing compiler runtime libraries like that have also been an issue in the past.

wondie commented 7 years ago

Both Python and Apache are 32bit.

msvcr90.dll is avaialble here. image And C:/xampp/mailtodisk folder. Is it enough?

GrahamDumpleton commented 7 years ago

Does your system have Ws2_32.lib.

wondie commented 7 years ago

I found the following. image The full paths of the last ones are: C:\Users\Wondim\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\WinSDK\Lib\x64 and C:\Users\Wondim\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\WinSDK\Lib

GrahamDumpleton commented 7 years ago

I can only suggest at this point using the Apache distro from ApacheLounge. It is the only one I know for sure works. Any time see people have problems usually always been with other distros.

wondie commented 7 years ago

Thank you very much for the help! I will try and see if I can even install ApacheLounge copy in a production server. Is the django builtin apache good enough for production?

GrahamDumpleton commented 7 years ago

No, the Django development server is not regarded as suitable for production systems. It is single process and single threaded, so can only handle one request at a time.

wondie commented 7 years ago

Thank you very much!