环境:httpd2.4+php5.4+mariadb5.5
检查环境
[root@localhost]# rpm -qa | grep php
php-common-5.4.16-43.el7_4.x86_64
php-mysql-5.4.16-43.el7_4.x86_64
php-cli-5.4.16-43.el7_4.x86_64
php-pdo-5.4.16-43.el7_4.x86_64
php-5.4.16-43.el7_4.x86_64
[root@localhost html]# rpm -qa | grep httpd
httpd-tools-2.4.6-67.el7.centos.6.x86_64
httpd-2.4.6-67.el7.centos.6.x86_64
[root@localhost]# rpm -qa | grep mariadb
mariadb-server-5.5.56-2.el7.x86_64
mariadb-libs-5.5.56-2.el7.x86_64
mariadb-5.5.56-2.el7.x86_64
一定要注意软件包的版本,平台以及依赖
启动服务:
[root@localhost /]# systemctl start httpd
[root@localhost /]# systemctl start mariadb
新建几个文件用来测试
1,检测httpd是否能用
index.html
test!
然后虚拟机外部访问centos的ip地址
如果出现无法访问
注意iptables开启80端口(firewalld不在此讨论)
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
iptables-save
2,检测数据库 mariadb 是否可用
[root@localhost html]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
3,测试整个web环境是否能用,重点检测php调用数据库
/var/www/html下新建indsex.php
<?php
echo phpinfo();
然后外部浏览器访问centosip/index.php
在php信息能否找到mysql
如果找不到
yum install php-mysql
4,/var/www/html下新建dbtest.php
<?php
$con = mysqli_connect("localhost","root","dbpassword","test");
if(!$con){
die("failed".mysqli_error());
}else{
echo "db connect success";
}
然后虚拟机外部用浏览器访问ip/con.php
- TMD用mysql_connect写了很多次都是http error 500
- 换成mysqli立马ok
网友评论