Chipmunk Taro's It was a life I wanted to link django and apache on Mac I was allowed to refer to!
However, there are some areas that I couldn't solve, so I'm posting it in the hope that it will help people in similar circumstances!
This is my first post, but I will try to convey it in an easy-to-understand manner. Lol
--Python settings
--Installation around mod_wsgi
--apache settings
The version of Python I used this time is 3.6.2.
I think any version is fine here.
However,
CONFIGURE_OPTS="--enable-shared" pyenv install 3.6.2
It must be installed with option like.
Toyu
/Users/username/.pyenv/versions/3.6.2/lib/libpython3.6m.dylib
If there is no such file, mod_wsgi.so that will appear later will not be able to refer to python and will throw an error.
If you haven't cleared this and are creating a Django project, install Python using the method above and create the project again. ..
pip install mod-wsgi-httpd
pip install mod_wsgi
Please install around mod_wsgi with!
This guy is responsible for connecting apache and Django.
The Mac comes with apache by default, but it seems to be useless, so install the latest version.
Procedure to install Apache httpd on macOS with Homebrew
Was very easy to understand!
next,
/usr/local/etc/httpd/httpd.conf
I will add code to. This is the most important!
Mr. Taro Shimarisu is also mentioned,
[Introduction to Django] Let's run a server using apache
It is a mistake to add the following to httpd.conf in.
LoadModule /Users/username/.pyenv/versions/anaconda3-4.3.0/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-darwin.so
WSGIScriptAlias / /Users/username/anaconda3/mySite/mySite/wsgi.py
WSGIPythonPath /Users/username/anaconda3/mySite
WSGIPythonPath /Users/username/.pyenv/versions/anaconda3-4.3.0/lib/python3.6/site-packages
<Directory /Users/username/anaconda3/mySite/mySite>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
There are three places where I got caught.
The first is the case where the argument on the first line is insufficient. Correctly,
LoadModule wsgi_module /Users/username/.pyenv/versions/3.6.2/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-darwin.so
There must be an argument wsgi_module, such as.
The second is the case where the fifth line is unnecessary. Comment it out or delete it as follows.
#WSGIPythonPath /Users/e175711/.pyenv/versions/3.6.2/lib/python3.6/site-packages
This is a part that was not pointed out by Mr. Taro Shimarisu!
I wonder if it was necessary only in my own environment.
By the way, if you do not comment out here, when accessing localhost
500 Internal Server Error
I got an error.
The third is the case where the 9th and 10th lines are old. Let's fix it as follows!
<Directory /Users/username/anaconda3/mySite/mySite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
This is a part that was not pointed out by Mr. Taro Shimarisu! The specifications have changed ~
By the way, if you do not modify it, when accessing localhost
403 Forbidden
I got an error.
You can only allow access from a specific IP address here, so please adjust accordingly!
Finally here
sudo brew services restart httpd
Hit and you should be taken to the Django tutorial page!
The reason for restart is to read the modified httpd.conf and reflect it.
Thank you for reading this far! I didn't cover it in this article, but I had a problem that I couldn't access it because I didn't set ALLOWED_HOSTS in the project settings.py, and I stumbled on various other issues. After all it is difficult ~ However, it is still the best when I can solve it by trial and error in my own way. Lol If you find any deficiencies, please let us know!
Recommended Posts