source activate meihuazhuan
cd /root/meihuazhuang/django/DjangoBlog
python manage.py runserver 0.0.0.0:8000
浏览器打开: http://123.207.166.127:8000/ 就可以看到效果了
centos7+Apache+mysql+Django+python3
Conda create meihuazhuan
Source activate meihuazhuan
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
List item
yum repolist all | grep mysql
之后会显示可安装的版本列表,默认安装版本为5.7
vi /etc/yum.repos.d/mysql-community.repo
打开repo文件,将其中的5.7版本的enabled=1改为enabled=0以及8.0版本的enabled=0改为enabled=1,结果如下
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
yum repolist enabled | grep mysql
yum install -y mysql-community-server
注意,此过程很漫长,需要良好网络
systemctl start mysqld
systemctl enable mysqld
systemctl daemon-reload
grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p 初始密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Meihua@123456'
密码强度默认为中等强度,需要由大写字母、小写字母、特殊符号、数字组成
可以先修改密码强度再修改密码
set global validate_password_length=4;
(最小值是4,默认为8)
set global validate_password_policy=0
选择0(LOW),1(MEDIUM),2(STRONG)其中一种,选择2需要提供密码字典文件
之后修改密码便可以使用简单密码
source activate meihuazhuan
在此环境安装 Django 相关模块
注意:使用pip安装的内容都需要在虚拟环境下安装,否则将默认安装在CentOS自带的Python2相关环境中
pip install django pymysql
安装python相关包需要用到python中的pip命令,比如我项目中需要的包有:
pip install Django
pip install PyMySQL
pip install Scrapy
pip install beautifulsoup4
pip install bs4
pip install lxml
pip install numpy
pip install requests
pip install simplejson
pip install urllib3
yum install httpd httpd-devel -y
pip install mod_wsgi
注意:这里需要在配置的虚拟环境中安装,不要在外部使用yum install mod_wsgi安装,这将会使mod_wsgi模块默认安装在CentOS7自带的Python2中
mod_wsgi-express install-module
结果(根据虚拟目录名称不同,这里结果也略有不同,但大致相同)
LoadModule wsgi_module "/usr/lib64/httpd/modules/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"
WSGIPythonHome "/var/www/html/.py3env"
vi /etc/httpd/conf/httpd.conf
在最后添加
LoadModule wsgi_module "/usr/lib64/httpd/modules/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so"
vi /etc/httpd/conf.d/django.conf
systemctl restart httpd
systemctl enable httpd
Cd ~/meihuazhuang
Git clone https://github.com/liangliangyy/DjangoBlog.git
进入到工程中
sudo su root
cd project/django-restframework-demo/tutorial
python manage.py runserver 0.0.0.0:80 &
参考:
https://blog.csdn.net/w18211679321/article/details/83004286 https://blog.csdn.net/a394268045/article/details/79288718 https://github.com/liangliangyy/DjangoBlog