首页 文章

mysqli没有在apache下连接

提问于
浏览
3

我有一个基于codeigniter的php应用程序,我有一个数据库位于远程主机上,安装了所需的数据库,设置了正确的mysql权限,并且mysql端口打开用于远程连接,但是,当我运行应用程序时,它不起作用它返回500错误代码 .

当我解决问题时,它会给出以下错误

消息:mysqli :: real_connect():( HY000 / 2003):无法连接到'192.168.6.13'上的MySQL服务器(13)

到目前为止我尝试了什么:

1)确保正确设置所有权限 .

2)确保不存在网络相关问题,例如阻塞的端口/主机

3)确保安装并启用了mysqli .

4)创建一个连接测试PHP脚本并从命令行运行它,它工作得很好 .

5)有趣的部分是当我从命令行运行应用程序时,它作为root用户和作为 su -s /bin/sh apache -c "php index.php". 的apache用户正常工作

参数我有:

1)php版本是PHP 5.4.16

2)操作系统版本:网络和数据库上的CentOS Linux版本7.2.1511(核心版)

3)Web服务器版Apache / 2.4.6(CentOS)

4)mysql Ver 14.14

5)我在ssl下运行我的应用程序,下面是我的配置

<VirtualHost *:443>

        #### Gloabl config
     DocumentRoot /var/www/bein
     DirectoryIndex index.php
     ServerName beinmob.com
     ServerAlias www.beinmob.com
        #### change basic URL to /index.php/POS_Admin/Session
     RewriteEngine  on
     RewriteRule ^/?$  index.php/POS_Admin/Session [R]
        #### change url to alias for web services
     Alias /web-services /var/www/bein/index.php
     Alias /POS_Admin /var/www/bein/
        #### Basic Authentication for /web-services url
        <Location /POS_Admin>
                RewriteEngine on
                # Hide the application and system directories by redirecting the request to index.php
                RewriteBase /index.php
                RewriteRule ^(application|system|\.svn) index.php/$1 [L]
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteRule ^(.*)$ index.php/$1 [QSA,L]
        </Location>
        <Location /web-services>
                AuthName bein
                AuthType Basic
                AuthUserFile /etc/httpd/conf.d/beinServicePass
                Require valid-user
        </Location>
        #### SSL configuration
        SSLEngine on
        SSLCertificateFile /etc/httpd/cert/certs/www_beinmob_com.crt
        SSLCertificateKeyFile /etc/httpd/cert/certs/www_beinmob_com.key
        SSLCertificateChainFile /etc/httpd/cert/certs/DigiCertCA.crt
</VirtualHost>

3 回答

  • 2

    检查this它应该可以解决您的问题 .

    Update because the link may become dead if that page moves or is deleted

    以root身份登录并执行操作

    setsebool -P httpd_can_network_connect=1
    
  • 0

    您必须结帐,如果您可以从终端访问myslq服务器:

    mysql -u youruser -h 192.168.0.3 -p
    

    看看你是否可以登录

    看来你没有apache的问题 . mysql服务器默认服务端口: 3306 和apache 80 http,443 https(例如 . 某些应用程序,如ispconfig运行在8080和几个应用程序服务器tomcat 81 ......)但似乎不是你的情况

  • 0

    为您的数据库创建权限 .

    enter image description here

    输入任何用户名

    主机必须是%

    并输入任何密码

    之后在db配置文件中使用此权限 . 确保您将获得对远程主机db的访问权限

相关问题