CentOS 配置php环境

本文详细介绍了如何在CentOS系统中安装Apache、MariaDB和PHP。在安装过程中,对Apache的配置文件进行了修改,启用了Apache服务,并安装了MariaDB的替代品。针对安装PHP后遇到的权限问题,文章给出了解决方案,即通过添加skip-grant-tables到mysqld配置来临时禁用权限检查。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一.安装apache

1.安装apache

yum install httpd

2.修改配置文件

vi /etc/httpd/conf/httpd.conf

将#ServerName www.example.com:80前面的#去掉
修改为ServerName localhost:80

3.添加端口,刷新配置,并查看确认

firewall-cmd --permanent --zone=public --add-port=80/tcp 
firewall-cmd --reload 
 firewall-cmd --permanent --zone=public --list-ports

4.开启apache服务

systemctl start httpd.service

二.安装mariadb

由于mysql从CentOS7开始收费了,因此只能用它的分支mariadb
1.安装

yum -y install mariadb-server

2.开启

systemctl start mariadb

3.确认

systemctl status mariadb

4.初始化

mysql_secure_installation

5.开启3306端口
参考
https://blog.youkuaiyun.com/yesterday_lover/article/details/117440973

6.本地测试

mysql -u root -p

7.远程测试:

mysql -u root -h 192.168.1.155 -p

三.安装php

1.安装

yum install php php-devel

2.测试

cd /var/www/html/
touch index.php && vi index.php

复制粘贴如下:

<?php phpinfo(); ?>

保存并退出:wq
3.打开地址访问

问题集:

再php+mariadb套餐中出现

Access denied for user ‘“root”’@‘localhost’ (using password: YES)

解决方法:

vi /etc/my.cnf.d/server.cnf 

在[mysqld]的下面添加skip-grant-tables

#this is only for the mysqld standalone daemon
[mysqld]
skip-grant-tables
重启mariadb

systemctl restart mariadb
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值