LMAP = Linux + MySQL + Apache2 + Python
Linux发行版本的选择
Ubuntu太多不必要的软件,更且不够稳定
ArchLinux的wiki写的好,但是万一哪天滚挂了,真的挂了
CentOS的软件版本太低,很多软件特性无法使用
选用Debian,apt-get和新立德包管理工具要方便的多
MySQL
MySQL的安装
sudo apt-get install mysql-client mysql-server
使用UTF-8编码
打开文件
/etc/mysql/my.cnf
在文件末尾添加
[mysqld]
init_connect = ‘SET collation_connection = utf8_general_ci,NAMES utf8’
collation_server = utf8_general_ci
character_set_client = utf8
character_set_server = utf8
MySQL的启动
mysql -u root -p
Apache2
Apache2的安装
sudo apt-get install apache2
Apache2的几个常用指令
service apache start
service apache stop
service apache restart
service apache reload
安装mod_wsgi模块
如果是Python2
sudo apt-get install libapache2-mod-wsgi-py
如果是Python3
sudo apt-get install libapache2-mod-wsgi-py3
如果同时安装了两个版本的模块,则Apache会优先使用针对python2.x的版本。
Apache2配置文件
/etc/apache2/
├── apache2.conf
├── conf-available
├── conf-enabled
├── envvars
├── magic
├── mods-available
├── mods-enabled
├── ports.conf
├── sites-available
└── sites-enabled
其中apache2.conf是主配置文件,具体的说明文件可以参考该文件。
配置虚拟主机
vim /etc/apache2/sites-available/testsite.conf
添加文件内容
<VirtualHost *:80>
ServerName www.testsite.com
DocumentRoot /home/Sean/Workspace/WebSite/testsite
<Directory /home/Sean/Workspace/WebSite/testsite/testsite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/Sean/Workspace/WebSite/testsite/testsite/wsgi.py
Alias /static/ /home/Sean/Workspace/WebSite/testsite/static
</VirtualHost>
WSGIPythonPath /home/Sean/Workspace/WebSite/testsite
然后运行下面两条命令,启用该站点
a2ensite firstsite.conf
service apache reload
Python选择问题
Python3是趋势,但是目前国内大部分教程、示例代码都是基于Python2的,所以自己选择
384

被折叠的 条评论
为什么被折叠?



