Linux三大主流网站构建平台,第二十三期 Linux的LAMP网站平台构建

在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

phpinfo(); //显示PHP环境信息

?>

通过Firefox浏览器访问 http://127.0.0.1/test1.php ,可以看到PHP环境信息

42ab572347369a13ee510cd7c4e98a31.png

2)测试PHP网页解析及数据库连接

在Web服务器的网页目录下新建另一个测试网页 test2.php,其中本机的mariadb数据库服务未做配置时,管理员账号为root、密码为空。

[root@svr7 ~]# vim /var/www/html/test2.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 !!"

dc6d1ba83337b9bd1b91adc2d165f103.png

谢谢大家

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值