LAMP环境搭建(Linux+Apache+Mariadb+PHP)
实现环境
3A云服务器:CentOS7.9
客户端:Windows 10
环境配置
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
关闭selinux
vi /etc/selinux/config
SELINUX=disabled
配置yum源(需要能够连接外网)
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.bak
wget -O CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
安装epel源
wget -O epel.repohttp://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache
安装所需服务
安装httpd(Apache)
yum install httpd
安装php和Mariadb
yum -y install php php-mysql
yum -y install mariadb mariadb-servermysql-devel
修改相关配置文件
修改httpd配置文件
vi /etc/httpd/conf/httpd.conf
在/var/www/html/下创建测试网页
vi /var/www/html./index.php
重启httpd服务
systemctl restart httpd
测试
启动Mariadb
systemctl start mariadb.service
检查监听端口是否打开
登录MySQL并删除空账号
delete from mysql.user where user='';(MySQL中要加分号)
添加管理员和密码
update mysql.user set password=password('12345') where user='root';
grant all on *.* to 'root'@'%' identified by '12345';
flush privileges;
重启Mariadb服务
systemctl restart mariadb.service
修改测试网页,测试PHP和Mariadb的连接
vi /var/www/html/index.php
$link=mysqli_connect('本机IP地址','MySQL账号','密码');
if($link)
echo "^_^ ok^_^";
else
echo "T_Tnot ok T_T";
?>
以上测试环境均在3A云服务器上搭建