This note aims to simplify the route to deploy Django2.X<2 on Ubuntu 16 LTS server. It takes about 4 minutes.python
Before you start your Ubuntu server, you'd better change your ssh port to another one, never use '22'. Because hackers will try many times to access your server. You can switch your ssh port by following scripts:mysql
cd /etc/init.d/ssh ls sudo vim sshd_config # a configuration file like this # in vim mode, type 'i' to insert # annotate the default port setting as '# port 22' # add a new line after 'port 22' as 'port 23442', just an example. # after you've done above things sudo /etc/init.d/ssh restart
sudo apt update sudo apt-get install mysql-server mysql-client
service mysql status service mysql start #restart/stop
mysql -u root -p mysql: create database Django_Database_Name default charset utf8 collate utf8_general_ci; # Set default charset as UTF-8 to prevent error in future
# install virtualenv sudo apt install virtualenv virtualenv Your_Django_App_Root_Name # e.g. Fucker cd Fucker source ./bin/activate # activate virtual-environment
- Deactivate virtual-environment ```bash # in virtual-environment root dir deactivate ```
sudo apt-get install python3 sudo apt-get install python3-pip
pip3 install django uwsgi pillow --user # --user option to prevent Permission Denied Error in future
sudo apt-get install nginx systemctl nginx status # check nginx status sudo apt install curl # test nginx curl 127.0.0.1
source ./bin/activate python3 manage.py makemigrations python3 manage.py migrate python3 manage.py createsuperuser # set username, pwd, email python3 manage.py runserver 0.0.0.0:8000 # then some error might occur
python3 manage.py makemigrations --empty YOUR-APP-NAME python3 manage.py makemigrations python3 manage.py migrate
Django Daemon service configurationnginx
Serve Static files if DEBUG's been set Falsesql
Nginx Configurationdjango