原文链接:https://blog.csdn.net/li3839/article/details/80644669
安装Apache
yum -y install httpd //安装httpd systemctl start httpd.service //启动httpd服务 systemctl enable httpd.service //设置开机启动
安装PHP
yum -y install php //安装php systemctl restart httpd.service//重启apache服务 touch /var/www/html/phpinfo.php//创建一个php文件 vi /var/www/html/phpinfo.php//进行编辑插入<?php phpinfo(); ?> IP+/phpinfo.php访问网页
安装MariaDB
yum install mariadb-server mariadb//安装mariadb systemctl start mariadb//启动数据裤 systemctl enable mariadb//设置开机启动 mysql -u root -p//没有密码回车登陆
将PHP与MySQL连接
yum search php yum -y install php-mysql
重启apache服务
systemctl restart httpd.service
测试
vi /var/www/html/mysql.php//创建MySQL.php文件 将下方代码插入进去 <?php header("Content-type:text/html;charset=utf-8"); echo '开始mysql数据库连接.<br>'; $con = mysql_connect("localhost","root"); if($con){ echo '连接mysql数据库成功.<br>'; }else{ die('连接mysql数据库失败:' . mysql_error()); } mysql_close($con); echo '关闭mysql数据库连接.';