Apache MOD_WSGI does not connect to MySQL after deploying a Django project

Source: Internet
Author: User

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.

    1. The python manage.py runserver debug mode is identical to the information printed on the off.

    2. 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:

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

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

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.