Let's integrate Django and apache (httpd) on Mac! !!

environment

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

This synopsis

--Python settings

--Installation around mod_wsgi

--apache settings

Python 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. ..

Installation around mod_wsgi

pip install mod-wsgi-httpd

pip install mod_wsgi

Please install around mod_wsgi with!

This guy is responsible for connecting apache and Django.

apache settings

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.

At the end

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

Let's integrate Django and apache (httpd) on Mac! !!
How to integrate Apache httpd 2.4 and Tomcat 9 on Cent OS 8
Integrate Apache and Tomcat
Run the flask app on Cloud9 and Apache Httpd
Python3 + Django ~ Mac ~ with Apache
Install Django on your Mac
Catalina on Mac and pyenv
MQTT on Raspberry Pi and Mac
HTTPS with Django and Let's Encrypt
Integrate Modelica and Python on Windows
Notes on building Python and pyenv on Mac
CentOS 6.4 with Python 2.7.3 with Apache with mod_wsgi and Django
How to install Apache (httpd) on CentOS7
How to install Apache (httpd) on CentOS8
Replacing rmtrash on Mac and replacing rm on Linux
Web server construction with Apache 2.4 (httpd 2.4.43) + PHP 7.4 on Linux ―― 4. Security (chown and firewalld)
Source compile Apache2.4 (httpd 2.4.43) + PHP7.4 on Linux and build a Web server ―― 1. Apache introduction
Source compile Apache2.4 (httpd 2.4.43) + PHP7.4 on Linux and build a Web server --2 PHP introduction
Manage Django images and static assets on Ubuntu
Run django applications on Windows + Apache + mod_wsgi + services.
Zsh and prezto installation work log on Mac
Remove old pyenv environment on Mac and update
Try importing MLB data on Mac and Python
python on mac
Let's summarize Apache
Install Python3 on Mac and build environment [Definitive Edition]
Build a Django development environment using pyenv-virtualenv on Mac
Apache + Django + Shibboleth on Windows Server 2016 Related Articles Summary
Publish your Django app on Amazon Linux + Apache + mod_wsgi
Build Apache HTTP Server and Wildfly on Oracle Linux 8
Installing Python 3 on Mac and checking basic operation Part 1
Let's make a Mac app with Tkinter and py2app
Install django on python + anaconda and start the server