Problem description
A good Django project that uses Python manage.py runserver can work normally. However, when the project is deployed to Apache using MOD_WSGI, it cannot be connected to MySQL. Always error: "Internal Server error", check the log information, in addition to "Can ' t connect MySQL" or not even on MySQL.
Tracking issuesDjango Test
Run the project in debug mode and debug off mode, respectively, with no exceptions, enough to prove that the project itself is configured with no errors.
Python Code test
Run the Python manage.py shell, import the MYSQLDB, and test with the driver code without exception. There is no error in explaining the driver version or anything.
View Source
Modify the parameter information of the connection database directly in django/admin/db/backend/mysql/base.py, and print the incoming parameter information in the _init.py in MySQLdb.
The python manage.py runserver debug mode is identical to the information printed on the off.
The information printed on the Apache access page does not differ from the information above.
So you can conclude that there is nothing wrong with project components and configurations.
Find answers
After a series of problem tracking, query network without fruit. Think of Mod_wsgi the goods, and then according to this to search for the conclusion Apache configured system user Apache/apache does not have permission to access the default Mysql.sock configuration file path. Let's change this permission, but it's not going to change. Then start the following attempt:
Directly modify the Apache configuration file in the user and group as root, compare the system root has the highest permissions, there is no access to the things he cannot. The result is an error when restarting Apache, which does not allow the root user to be used.
It is also modified to Mysql/mysql, because Mysql/mysql is the system user we used when we installed MySQL. Reboot without any effect, still can ' t connect MySQL
Think again, the general project production environment will not put the Web and DB configured on a server instead of a different machine on the MySQL configuration. Sure enough, this will be normal access.
Apache MOD_WSGI does not connect to MySQL after deploying a Django project