在CentOS7上部署LAMP平台
什么是LAMP?
一种成熟的动态企业网站服务器模式。
Apache在最前端,负责处理来自留来起的Web访问请求。
部署步骤
步骤一:安装LAMP平台各组件
1)安装好软件httpd、mariadb-server、mariadb、php、php-mysql
[root@centos7 ~]# yum -y install httpd mariadb-server mariadb php php-mysql
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-93.el7.centos 将被 安装
---> 软件包 mariadb.x86_64.1.5.5.65-1.el7 将被 安装
---> 软件包 mariadb-server.x86_64.1.5.5.65-1.el7 将被 安装
---> 软件包 php.x86_64.0.5.4.16-48.el7 将被 安装
---> 软件包 php-mysql.x86_64.0.5.4.16-48.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=======================================================================================================================
Package 架构 版本 源 大小
=======================================================================================================================
正在安装:
httpd x86_64 2.4.6-93.el7.centos sss 2.7 M
mariadb x86_64 1:5.5.65-1.el7 sss 8.7 M
mariadb-server x86_64 1:5.5.65-1.el7 sss 11 M
php x86_64 5.4.16-48.el7 sss 1.4 M
php-mysql x86_64 5.4.16-48.el7 sss 102 k
事务概要
=======================================================================================================================
安装 5 软件包
总下载量:24 M
安装大小:121 M
Downloading packages:
-----------------------------------------------------------------------------------------------------------------------
总计 13 MB/s | 24 MB 00:00:01
正在安装 : httpd-2.4.6-93.el7.centos.x86_64 1/5
.......
已安装:
httpd.x86_64 0:2.4.6-93.el7.centos mariadb.x86_64 1:5.5.65-1.el7 mariadb-server.x86_64 1:5.5.65-1.el7
php.x86_64 0:5.4.16-48.el7 php-mysql.x86_64 0:5.4.16-48.el7
完毕!
[root@centos7 ~]#
2)确认安装结果
[root@centos7 ~]# yum list httpd mariadb-server mariadb php php-mysql
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
已安装的软件包
httpd.x86_64 2.4.6-93.el7.centos @sss
mariadb.x86_64 1:5.5.65-1.el7 @sss
mariadb-server.x86_64 1:5.5.65-1.el7 @sss
php.x86_64 5.4.16-48.el7 @sss
php-mysql.x86_64 5.4.16-48.el7 @sss
[root@centos7 ~]#
步骤二:启用LAMP网站平台
1)开启系统服务httpd、mariadb,将上述服务设置为开机自运行
主要包括:Web服务httpd、数据库服务mariadb。PHP网页解析的功能由httpd服务在需要时调用相应的模块文件实现,无对应服务。
[root@centos7~]# systemctl restart httpd mariadb //起服务
[root@centos7~]# systemctl enable httpd mariadb //设置开机自启
2)关闭防火墙服务、关闭SELinux保护机制
关闭防火墙策略:
[root@centos7~]# systemctl stop firewalld //立即停止防火墙
[root@centos7~]# systemctl disable firewalld //以后开机不再启动防火墙
关闭SELinux保护机制:
[root@centos7 ~]# setenforce 0 //立即切换为宽松模式
[root@centos7 ~]# getenforce //确认结果
Permissive
[root@centos7 ~]# vim /etc/selinux/config //设置SELinux以后开机不再强制生效
SELINUX=permissive //宽松模式
步骤三:测试LAMP网站平台
1)测试PHP网页解析
- 编写网页 /var/www/html/test1.php
[root@centos7 ~]# vim /var/www/html/test1.php
<?php
phpinfo(); //用来显示PHP环境信息
?>
- 在CentOS上使用Firefox访问 http://虚拟机地址/test1.php ,能显示PHP环境信息
2)测试PHP访问数据库
- 编写网页 /var/www/html/test2.php
在Web服务器的网页目录下新建另一个测试网页 test2.php,其中本机的mariadb数据库服务未做配置时,管理员账号为root、密码为空。
[root@centos7 ~]# vim /var/www/html/test2.php
<?php
$link=mysql_connect('localhost','root','');
if($link) echo "Success !!"; //成功则显示 Success !!
else echo "Failure !!"; //失败则显示 Failure !!
mysql_close(); //关闭数据库连接
?>
- 访问 http://虚拟机地址/test2.php ,能报告数据库连接状态信息
通过Firefox浏览器访问 http://127.0.0.1/test2.php ,可以看到数据库连接的反馈信息,正常结果页面应显示"Success !!"。
根据上述操作后,LAMP平台已经部署完毕.