Deploy the django project on ubuntu18

I have been researching this matter for the past few days, and finally successfully deployed it. I would like to share some experience and pitfalls here, hoping to help those in need.

First of all, I recommend a software: xftp, which is very easy to use in my personal test. If you are not very familiar with git and want to upload the files on the local windows to the cloud server, you can use it, and the interface is very clear, which is of great help to the subsequent deployment. Including the git used by the up master mentioned later, I use xftp, which can be replaced by personal testing, and can also be deployed normally.

The cloud server I use is Alibaba Cloud, and the system is ubuntu18. The local is windows10, and the local operating environment of django is python3.7. Because ubuntu18 is installed with python3.6 by default, the version of python needs to be updated first. For specific methods, please refer to my other article Ubuntu18 updates python3.7_XFIRR's blog-CSDN blog. After the update is completed, create a soft link to deploy . If you have any doubts about building a virtual environment after installing python3.7, you can refer to Chapter 37 of the django2.0 tutorial on the up master on station B (and then type a line of code), which has detailed operation steps. But because it takes a long time, when you refer to it, you should pay attention to some commands that can no longer be used, especially the part about updating python3.7, you must pay attention.

After setting up the python3.7 environment, you can start to install the mysql database. For a detailed tutorial, you can refer to Deploying Django to Alibaba Cloud Server Tutorial_Wanqing's Blog-CSDN Blog_django Deploying to Cloud Server , but I personally do not recommend referring to the parts about uwsgi and nginx in the article. It may be a long time and prone to problems.

Fill in some pits of mysql installation here. My mysqlclient installation is to activate the virtual environment first and then install it (the command is source bin/activate, remember to cd to the corresponding directory in advance).

The first is the command pip3 install mysqlclient, please execute this command before use: apt-get install libmysqlclient-dev, otherwise it will prompt that it cannot be installed, and a large section of red text will appear.

If the following error still occurs after using the above command,

    MySQLdb/_mysql.c:46:10: fatal error: Python.h: No such file or directory
    #include "Python.h"
    ^~~~~~~~~~
    compilation terminated.
    error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
    [end of output]

You can execute the command apt-get install python3.x-dev. I used this command after activating the virtual environment. The x represents the version you are using. For example, if I am python3.7, then the x is 7.

After installing mysql, you can start to install uwsgi and nginx. For the tutorial here, you can also refer to the 39th video of the video of the up master of station b just above. According to the method of the up master, it can be used normally.

Finally fill a django pit:

I want to upload the file to the database after the deployment is successful, but the prompt:

 The reason for this problem is that the user does not have permission to write. You can refer to this article for how to modify file permissions in linux: Detailed explanation of Ubuntu file permissions_AnneMOMO's blog-CSDN blog_ubuntu folder permissions

You can use chmod -R 777 xx/ to batch modify the permissions of files under the folder

After using the method of this article, I can see:

 After that, there is no problem running the django program.

If you have any questions, please correct me.

Guess you like

Origin blog.csdn.net/XFIRR/article/details/124465669