快速构建LAMP网站平台

1.1 问题

(配置前提须要yum已经安装,而且能够使用)
本例要求基于Linux主机快速构建LAMP动态网站平台,并确保能够支撑PHP应用及数据库,完成下列任务:php

1)安装LAMP平台各组件,启动LAMP平台html

软件包:httpd、mariadb-server、mariadb、php、php-mysql
系统服务:httpd、mariadb

2)编写测试网页,确保LAMP平台可用mysql

访问 http://虚拟机地址/test1.php ,能显示PHP环境信息
访问 http://虚拟机地址/test2.php ,能报告数据库链接状态信息

1.2 方案

在CentOS7系统中开启Web/FTP等网络服务应用时,可能会收到默认配置的防火墙、SELinux等安全防御策略影响。为了不干扰,学习过程当中建议禁止这些保护机制。linux

关闭防火墙策略:sql

[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 步骤

实现此案例须要按照以下步骤进行。vim

步骤一:安装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
<?php
phpinfo();                                              //显示PHP环境信息
?>

经过Firefox浏览器访问 http://127.0.0.1/test1.php ,能够看到PHP环境信息,如图-1所示。
快速构建LAMP网站平台

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网站平台

相关文章
相关标签/搜索