码迷,mamicode.com
首页 > Web开发 > 详细

第二十三期 Linux的LAMP网站平台构建

时间:2018-02-27 21:30:42      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:云计算   达内   Linux   

在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                                  //宽松模式

安装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环境信息
技术分享图片
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 !!"
技术分享图片
谢谢大家

第二十三期 Linux的LAMP网站平台构建

标签:云计算   达内   Linux   

原文地址:http://blog.51cto.com/13556999/2073658

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!