LAMP环境搭建与配置

LAMP环境搭建与配置
LAMP=Linux+Apache+Mysql+PHP组成一个环境来运行php的脚本与语言通常是网站
关闭相关服务
LAMP环境搭建与配置
安装并配置阿帕奇
LAMP环境搭建与配置
安装并配置mariadb
LAMP环境搭建与配置
[email protected] ~]# mysql_secure_installation #初始化数据库(之后会进入一系列初始化的配置)
Set root password? [Y/n] y #是否设置root用户密码,输入y并回车或直接回车New password: #设置root用户密码Re-enter new password: #再次输入设置的密码Remove anonymous users? [Y/n] y #是否删除匿名用户
Disallow root login remotely? [Y/n] y #是否禁止root远程登陆
Remove test database and access to it? [Y/n] #是否删除test数据库
Reload privilege tables now? [Y/n] #是否重新加载权限表
初始化MariaDB完成,接下来测试登录
All done! If you’ve completed all of the above steps, your MariaDBinstallation should now be secure. Thanks for using MariaDB!
测试
LAMP环境搭建与配置
进入数据库:mysql -u root -p
之后先创建库:create database master1;
使用数据库:use master1;
然后创建表:create table master1.dump_to_slave(id int);
给表插入数据:insert into master1.dump_to_slave values(10);
给root用户授予访问数据库的权限:GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘(访问密码)’;

刷新数据库 flush privileges;
LAMP环境搭建与配置
安装mod_wsgi
并检查查mod_wsgi.so是否存在
yum install mod_wsgi -y
ls /etc/httpd/modules/mod_wsgi.so
LAMP环境搭建与配置
配置Apache支持Wsgivim /etc/httpd/conf/httpd.con
f插入如下两条命令
第一条命令指模块装载的路径
第二条命令指我从test这经过端口映射出/var/www/test.wsgi的内容
LAMP环境搭建与配置
添加wsgi应用代码
创建test.wsgi
LAMP环境搭建与配置
下载MySQLdb模块
LAMP环境搭建与配置
测试是否下载完成
LAMP环境搭建与配置
在linux操作界面中输入python,然后输入模块名字,下面没有报错则代表成功
编辑/var/www/test.wsgi,并重启服务
import MySQLdb
db=MySQLdb.connect(“主机的ip”,“允许让问数据的用户”,“密码”,“数据库的库名”)
cursor=db.cursor()
cursor.execute(“select id from dump_to_slave limit 1”)
data=cursor.fetchone()
def application(environ, start_response):
status = ‘200 OK’
output = ‘Hello World! %s’ % data
response_headers = [(‘Content-type’, ‘text/plain’),(‘Content-Length’, str(len(output)))]
start_response(status, response_headers)
return [output]LAMP环境搭建与配置
测试,这里出现了一个500的错误

LAMP环境搭建与配置
经检查是由于在编写test.wsgi的时候密码写错导致的,再次编写并重启服务后正常
LAMP环境搭建与配置
可以使用flask,它是一个使用python编写的轻量级web应用程序框架,其WSGI工具箱采用werkzeug(路由模块),模板引擎则使用jinjia2