Ubuntu config django+ apache2+ MySQL

Source: Internet
Author: User
Tags chmod install django

# my Ubuntu comes with python3.5, so install python3.6
sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt-get update
sudo apt-get install python3.6
sudo update-alternatives--install/usr/bin/python3 python3/usr/bin/python3.5 1
sudo update-alternatives--install/usr/bin/python3 python3/usr/bin/python3.6 2

You can check the version after loading.

>> python3-v

# Install PIP3

sudo apt install python3-pip

# Install Django
sudo pip3 install Django

You can check the Django version when you're done.

>> Python3

>> Import Django

>> Django. VERSION

# The framework typically uses restful APIs, which need to be installed
Sudo-h PIP3 Install Djangorestframework
Sudo-h PIP3 Install Markdown
Sudo-h PIP3 Install Django-filter

# install MySQL below
sudo apt-get-y install Python3-mysqldb
sudo apt-get-y install mysql-server mysql-client
sudo apt-get-y install Libmysqlclient-dev
Sudo-h PIP3 Install Mysqlclient
Sudo-h apt-get-y Install Python3-pymysql
sudo pip3 install requests

# Configure Database MySQL command
Connect:mysql-u root-p
Create Database:create database name default Charset=utf8;
Create User:create user your username identified by ' your password ';
Grant:grant all privileges the database name. * to your username @ '% ' identified by ' your password ';
Show grants for ' database name ';

The following configuration Apache

# Install Apache & WSGI, disable unneeded virtualhosts
sudo apt-get update
sudo apt-get-y install apache2 libapache2-mod-wsgi-py3
sudo a2enmod wsgi
sudo service apache2 restart
sudo a2dissite 000-default
sudo service apache2 restart

# Add Project User and add yourself to his Group
sudo adduser lmy
sudo usermod--lock lmy
sudo mkdir/home/lmy/grouped
sudo chmod u=rwx,g=srwx,o=x/home/lmy/grouped
sudo chown-r lmy.lmy/home/lmy/

sudo find/home/lmy/grouped/-type f-exec chmod-v ug=rw {} \;
sudo find/home/lmy/grouped/-type d-exec chmod-v u=rwx,g=srwx {} \;

sudo adduser $ (whoami) Lmy
Newgrp Lmy

# Create a New VirtualHost for WSGI Django
sudoedit/etc/apache2/sites-available/project name. conf

<virtualhost *:80>
ServerName www.example.com

Wsgidaemonprocess User name user= user name group= username threads=5 python-path= "/home/username/grouped/project name/"
Wsgiscriptalias//home/User name/grouped/project name/project name/wsgi.py
<directory/home/User name/grouped/project name/>
Wsgiprocessgroup User Name
Wsgiapplicationgroup%{global}
Wsgiscriptreloading on
Require all granted
</Directory>
</VirtualHost>

sudo a2ensite project name
sudo service apache2 restart

Above, it's already configured.

If the server encounters a 500 error

Cat/var/log/apache2/error.log

or Tail-f/var/log/apache2/error.log

# Initialize Database
Sudo-h Python3 manage.py makemigrations
Sudo-h Python3 manage.py Migrate

Ref

http://terokarvinen.com/2017/django-on-apache-with-python-3-on-ubuntu-16-04

https://zxtcode.com/main/37/

http://www.django-rest-framework.org/

https://docs.djangoproject.com/en/1.11/howto/static-files/

Http://www.cnblogs.com/gide/p/6179975.html

Http://www.runoob.com/django/django-first-app.html

Ubuntu config django+ apache2+ MySQL

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.