CentOS7 to deploy the Django project on Apache2.4

Source: Internet
Author: User

Because of the need to write a website, considering and not writing other languages, the direct use of Python, speaking of the framework of Python, is the famous Django.

The version of the project is Python 2.7,django is the python on the 1.8,windows development machine is 2.7.12, the server is 2.7.5, the version as long as the difference is not too large.

The Apache version of the server is apache/2.4.6, and the database uses mariadb5.5.52

After the project is finished, the document format is as follows

                  

On the Internet to view a lot of information, writing is not very full, write this article, help everyone.

First, I put the file in Apache's default directory, named Buglist.

1 /var/www/html

To modify a file

1 vim/var/www/html/buglist/buglist/wsgi.py
1 Import OS2 3From Os.path ImportJoin,dirname, Abspath4 5Project_dir =dirname(dirname(Abspath (__file__)))6 Import SYS7Sys.path.insert (0, Project_dir)8 9 Ten From django.core.wsgi import get_wsgi_application One  AOs.environ.setdefault ("Django_settings_module","buglist.settings") -  -  theapplication = Get_wsgi_application ()
1 vim/var/www/html/buglist/buglist/settings.py
1 allowed_hosts = [www.example.com',]   ----Add your own domain name
1Staticfiles_finders = (2               'Django.contrib.staticfiles.finders.FileSystemFinder',3               'Django.contrib.staticfiles.finders.AppDirectoriesFinder',4#'Django.contrib.staticfiles.finders.DefaultStorageFinder',5 )6Staticfiles_dirs = ('/var/www/html/buglist/static/css',-----Here to change the previous relative path to an absolute path7               '/var/www/html/buglist/static/bootstrap',8                '/var/www/html/buglist/static/images',9                '/var/www/html/buglist/static/js',Ten)

Execute command

1 python manage.py  collectstatics   ---to handle static files

At this point, the static files will be copied to the static below, the following will go to modify our Apache server configuration file

You need to install the MOD_WSGI command as follows

1 Yum Install Mod_wsgi
1 vim/etc/httpd/conf/httpd.conf
1LoadModule wsgi_module modules/mod_wsgi.so---add <virtualhost *: the>2DocumentRoot"/var/www/html/buglist"3Wsgiscriptalias/"/var/www/html/buglist/buglist/wsgi.py"4alias/static//var/www/html/buglist/static/---cannot be quoted5<Directory/var/www/html/buglist/static>6 Require All granted7</Directory>8<directory"/var/www/html/buglist">9 allowoverride AllTen Require All granted One</Directory> A</VirtualHost>

Restart the server and you'll see it's done.

If the server debugging is not a problem, remember to setting inside the debug to close

CentOS7 to deploy the Django project on Apache2.4

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.