(配置前提需要yum已经安装,并且可以使用)
本例要求基于Linux主机快速构建LAMP动态网站平台,并确保可以支撑PHP应用及数据库,完成下列任务:
1)安装LAMP平台各组件,启动LAMP平台
软件包:httpd、mariadb-server、mariadb、php、php-mysql系统服务:httpd、mariadb
2)编写测试网页,确保LAMP平台可用
访问 http://虚拟机地址/test1.php ,能显示PHP环境信息访问 http://虚拟机地址/test2.php ,能报告数据库连接状态信息
1.2 方案
在CentOS7系统中开启Web/FTP等网络服务应用时,可能会收到默认配置的防火墙、SELinux等安全防护策略影响。为了避免干扰,学习过程中建议禁止这些保护机制。
关闭防火墙策略:
[root@svr7 ~]# systemctl ?stop ?firewalld[root@svr7 ~]# systemctl ?disable ?firewalld
关闭SELinux保护机制:
[root@svr7 ~]# setenforce ?0 ?????????????????????//立即切换为宽松模式[root@svr7 ~]# getenforce ?????????????????????//确认结果Permissive[root@svr7 ~]# vim ?/etc/selinux/config ?????????//以后开机不再强制生效SELINUX=permissive ?????????????????????????????????//宽松模式
1.3 步骤
实现此案例需要按照如下步骤进行。
步骤一:安装LAMP平台各组件,启动LAMP平台
1)安装LAMP各组件软件包
主要包括:httpd、mariadb-server、mariadb、php、php-mysql。
[root@svr7 ~]# yum ?-y ?install ?httpd ?mariadb-server ?mariadb ?php ?php-mysql.. ..已安装: ?mariadb.x86_64 1:5.5.52-1.el7 ??????????????????????????????mariadb-server.x86_64 1:5.5.52-1.el7 ???????????????????????php.x86_64 0:5.4.16-42.el7 ?????????????????????????????????php-mysql.x86_64 0:5.4.16-42.el7 ?????????????????????????作为依赖被安装: ?libzip.x86_64 0:0.10.1-8.el7 ???????????????????????????????perl-DBD-MySQL.x86_64 0:4.023-5.el7 ????????????????????????php-cli.x86_64 0:5.4.16-42.el7 ?????????????????????????????php-common.x86_64 0:5.4.16-42.el7 ??????????????????????????php-pdo.x86_64 0:5.4.16-42.el7 ???????????????????????????完毕!
2)启动LAMP组建对应的系统服务
主要包括:Web服务httpd、数据库服务mariadb。PHP网页解析的功能由httpd服务在需要时调用相应的模块文件实现,无对应服务。
[root@svr7 ~]# systemctl ?restart ?httpd ?mariadb ?????????//起服务[root@svr7 ~]# systemctl ?enable ?httpd ?mariadb ?????????//设置开机自启Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
步骤二:编写测试网页,确保LAMP平台可用
1)测试PHP网页解析
在Web服务器的网页目录下新建一个测试网页 test1.php。
[root@svr7 ~]# vim ?/var/www/html/test1.php<?phpphpinfo(); ?????????????????????????????????????????????//显示PHP环境信息?>
通过Firefox浏览器访问 http://127.0.0.1/test1.php ,可以看到PHP环境信息,如图-1所示。
2)测试PHP网页解析及数据库连接
在Web服务器的网页目录下新建另一个测试网页 test2.php,其中本机的mariadb数据库服务未做配置时,管理员账号为root、密码为空。
[root@svr7 ~]# vim ?/var/www/html/test2.php<?php ???$link=mysql_connect(‘localhost‘,‘root‘,‘‘); ???if($link) echo "Success !!"; ????????????????//成功则显示 Success !! ???else echo "Failure !!"; ????????????????????//失败则显示 Failure !! ???mysql_close(); ?????????????????????????????//关闭数据库连接?>
通过Firefox浏览器访问 http://127.0.0.1/test2.php ,可以看到数据库连接的反馈信息,正常结果页面应显示"Success !!",如图-2所示。
快速构建LAMP网站平台
原文地址:http://blog.51cto.com/13445059/2073660