Pay attention to those passing by:
Install python3-pip -------------sudo apt-get install python3-pip
Install virtual environment and virtual environment management pack
sudo pip3 install virtualenv (If you report an error, you need to install pip as well)
sudo pip3 virtualenvwrapper
Add in ~/.bashrc
export WORKON_HOME=~/Envs
source /usr/local/bin/virtualenvwrapper.sh (If there is no virtualenvwrapper.sh, create this file in this directory)
source .bashrc
Create a virtual environment: mkvirtualenv ShangOnline –p /usr/bin/python3
The package that the installation project depends on in the virtual environment (mysqlclient will have a problem, you need to install the following package first)
We can export the corresponding information of the windows virtual environment installation package through pip freeze> requirements.txt to move to ubuntu
pip3 install -r requirements.txt mysqlclient will report an error during the installation process, follow the two steps below
sudo apt-get install libmysqlclient-dev
pip install mysqlclient
database:
sudo apt-get install mysql-server
Enter the database to create your own account and assign all permissions, and refresh permissions, bind 0.0.0.0 in the configuration file
Create the database shangonline we use in ubuntu, and transfer the data in the windows database to ubuntu through Navicat of windows
Drag our project folder into our virtual environment, enter the project python manage.py runserver to ensure that the project can be pulled up
Install uwsgi-------pip3 install uwsgi
Test uwsgi---------uwsgi --http :8000 --module ShangOnline.wsgi
Installation and configuration nginx------sudo apt-get install nginx
After the installation is complete, the nginx service will be started automatically. When we directly access the ubuntu ip in the external windows browser, we will enter the nginx environment interface
Create a new folder config-------new sol_nginx.conf in the project root directory
upstream django {
server 127.0.0.1:8000; # for a web port socket (we'll use this first)
}
server {
listen 80;
server_name your ip address; # substitute your machine's IP address or FQDN
charset utf-8;
client_max_body_size 75M; # adjust to taste
location /media {
alias /home/ly/ShangOnline/static/media; # points to django's media directory
}
location /static {
alias /home/ly/ShangOnline/static; # points to the static directory of django
}
location / {
uwsgi_pass django;
include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
}
}
7. Add the configuration file to the startup configuration file of nginx
sudo cp /home/ly/ShangOnline/config/sol_nginx.conf /etc/nginx/conf.d/
8. Pull all required static files to the same directory
In the setting file of django, add the following line of content:
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
Run command
python manage.py collectstatic
9. Run nginx
sudo /usr/sbin/nginx
It should be noted here that it must be started directly with nginx command, do not start nginx with systemctl, otherwise there will be permission problems
10. Start uwsgi through the configuration file
Create a new uwsgi.ini configuration file with the following content:
[ uwsgi]
chdir = /home/ly/ShangOnline/
module = ShangOnline.wsgi
master = true
processes = 10
socket = 127.0.0.1:8000
vacuum = true
virtualenv = /home/ly/Envs/ShangOnline
logto = /tmp/mylog.log
******Note:
chdir: Indicates the directory that needs to be manipulated, that is, the directory of the project
module: The path of the wsgi file
processes: number of processes
virtualenv: the directory of the virtual environment
workon ShangOnline
uwsgi -i /home/ly/ShangOnline/config/uwsgi.ini &
10. access
http://your ip address/
Recommended Posts