PHP 学习中遇到的坑

Apache重启时报警:

AH00112: Warning: DocumentRoot [/usr/local/apache/docs/dummy-host.example.com] does not exist

AH00112: Warning: DocumentRoot [/usr/local/apache/docs/dummy-host2.example.com] does not exist

问题原因:

Apache在配置虚拟主机时会在配置文件中(httpd.conf)开启虚拟主机的配置文件;

将“ #Include /etc/httpd/extra/httpd-vhosts.conf ”前面的“#”去掉;

而“httpd-vhosts.conf ”中会有两个配置虚拟主机的例子:


  ServerAdmin [email protected]
   DocumentRoot "/usr/local/apache/docs/dummy-host.example.com"
   ServerName dummy-host.example.com
   ServerAlias www.dummy-host.example.com
   ErrorLog "logs/dummy-host.example.com-error_log"
   CustomLog "logs/dummy-host.example.com-access_log" common


   ServerAdmin [email protected]
   DocumentRoot "/usr/local/apache/docs/dummy-host2.example.com"
   ServerName dummy-host2.example.com
   ErrorLog "logs/dummy-host2.example.com-error_log"
   CustomLog "logs/dummy-host2.example.com-access_log" common

这样Apache在启动时就会去寻找以上两个不存在的文件夹,就会报错。

解决方法:
方法二:将“httpd-vhosts.conf ”中的例子注释掉;

#
  #    ServerAdmin [email protected]
  #    DocumentRoot "/usr/local/apache/docs/dummy-host2.example.com"
  #    ServerName dummy-host2.example.com
  #   ErrorLog "logs/dummy-host2.example.com-error_log"
  #    CustomLog "logs/dummy-host2.example.com-access_log" common
  #

问题

$link = mysqli_connect('192.168.0.102','root','123456','my_database');

把192.168.0.102换成127.0.0.1就OK
错误代码是1130,ERROR 1130: Host xxx.xxx.xxx.xxx is not allowed to connect to this MySQL server 是无法给远程连接的用户权限问题

解决方法

在mysql命令行输入
GRANT ALL PRIVILEGES ON *.* TO '数据库用户名'@'%' IDENTIFIED BY '数据库密码' WITH GRANT OPTION;
看到Query OK, 0 rows affected, 1 warning (0.01 sec) 表示OK了

问题

Yii2 Gii http://localhost/blogDemo2/backend/web/index.php?r=gii没问题
http://192.168.0.102/blogDemo2/backend/web/index.php?r=gii就报错
Forbidden code 403 You are not allowed to access this page

解决方法

在main.php增加

'modules' => [
        'gii' => [
            'class' => 'yii\gii\Module',
            'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.102'],
            
        ],
    ],

你可能感兴趣的:(PHP 学习中遇到的坑)