LAMP環(huán)境搭建(Linux+Apache+Mariadb+PHP)
實(shí)現(xiàn)環(huán)境
3A云服務(wù)器:CentOS7.9
客戶端:Windows 10
環(huán)境配置
關(guān)閉防火墻
systemctl stop firewalld
systemctl disable firewalld
關(guān)閉selinux
vi /etc/selinux/config
SELINUX=disabled
配置yum源(需要能夠連接外網(wǎng))
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
安裝所需服務(wù)
安裝httpd(Apache)
yum install httpd
安裝php和Mariadb
yum -y install php php-mysql
yum -y install mariadb mariadb-servermysql-devel
修改相關(guān)配置文件
修改httpd配置文件
vi /etc/httpd/conf/httpd.conf
在/var/www/html/下創(chuàng)建測(cè)試網(wǎng)頁(yè)
vi /var/www/html./index.php
重啟httpd服務(wù)
systemctl restart httpd
測(cè)試
啟動(dòng)Mariadb
systemctl start mariadb.service
檢查監(jiān)聽(tīng)端口是否打開(kāi)
登錄MySQL并刪除空賬號(hào)
delete from mysql.user where user='';(MySQL中要加分號(hào))
添加管理員和密碼
update mysql.user set password=password('12345') where user='root';
grant all on *.* to 'root'@'%' identified by '12345';
flush privileges;
重啟Mariadb服務(wù)
systemctl restart mariadb.service
修改測(cè)試網(wǎng)頁(yè),測(cè)試PHP和Mariadb的連接
vi /var/www/html/index.php
?????? $link=mysqli_connect('本機(jī)IP地址','MySQL賬號(hào)','密碼');
?????? if($link)
????????????? echo "^_^ ok^_^";
?????? else
????????????? echo "T_Tnot ok T_T";
?>
以上測(cè)試環(huán)境均在3A云服務(wù)器上搭建