【问题标题】:PHP with MSSQL not installing in centos 7带有 MSSQL 的 PHP 未安装在 centos 7 中
【发布时间】:2016-05-04 12:12:08
【问题描述】:

我想在 CentOS Linux 系统中通过 PHP 连接 MSSQl 服务器。但是遇到错误,

Fatal error: Call to undefined function mssql_connect() in /var/www/h.....

为此,我参考了一些网站并找到了解决方案。但这也行不通。 这里我正在尝试安装 php5-sybase,但出现了一些错误,

yum install php5-sybase
Loaded plugins: fastestmirror, langpacks
apt.sw.be_redhat_el2.1_en_mirrors-rpmforge| 1.9 kB  00:00:00
remi-safe                                 | 2.9 kB  00:00:00


 One of the configured repositories failed (Unknown),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Disable the repository, so yum won't use it by default. Yum will then
        just ignore the repository until you permanently enable it again or use
        --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>

     4. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: rpmforge

如何解决这个问题。

【问题讨论】:

    标签: php sql-server linux centos


    【解决方案1】:

    要在 CentOS 上安装 SQL Server 的 PHP 驱动程序,我建议如下:

    sudo su
    curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo
    exit
    sudo ACCEPT_EULA=Y yum install msodbcsql
    sudo yum install unixODBC-devel
    yum groupinstall "Development Tools"
    sudo pecl install sqlsrv pdo_sqlsrv
    sudo echo "extension= pdo_sqlsrv.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
    sudo echo "extension= sqlsrv.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
    

    现在您应该可以使用如下的简单 PHP 脚本连接到 SQL Server:

    <?php
    $serverName = "localhost";
    $connectionOptions = array(
        "Database" => "SampleDB",
        "Uid" => "sa",
        "PWD" => "your_password"
    );
    //Establishes the connection
    $conn = sqlsrv_connect($serverName, $connectionOptions);
    if($conn)
        echo "Connected!"
    ?>
    

    【讨论】:

    • 我试图在我的 VPS 上安装它,但是当我收到命令“sudo pecl install sqlsrv pdo_sqlsrv”时,我一直遇到这个错误“pecl: command not found”。跨度>
    【解决方案2】:

    php-mssql 提供mssqlpdo_dblib 扩展,在EPEL 存储库中可用。

    正如 yum 错误输出中所述,您应该禁用 rpmforge(可能还有 apt.sw.be_redhat_el2.1_en_mirrors-rpmforge)

    注意:此扩展已弃用,将在 PHP 7 中删除。因此,为了更好的可维护性,我建议使用 PDO 驱动程序。

    yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    yum install php-mssql  
    

    【讨论】:

    • 我从 EPEL 获得了存储库 URL 并安装了。但我得到了错误。 [root@localhost tmp]# yum install php5-sybase 加载的插件:fastestmirror, langpacks 从缓存的主机文件加载镜像速度 没有可用的包 php5-sybase。错误:无事可做 [root@localhost tmp]#
    • 看我的回答,包是php-mssql,不是php5-sybase
    • 不走运。遇到同样的问题...我正在使用 Centos 7 和 PHP 5.4
    • 不知道会发生什么,这对其他人有用,并且包在那里:dl.fedoraproject.org/pub/epel/7/x86_64/p/…
    【解决方案3】:

    我从 EPEL 获得存储库 URL 并安装。但我得到了

    [root@localhost tmp]# yum install php5-sybase
    Loaded plugins: fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
    No package php5-sybase available.
    Error: Nothing to do
    [root@localhost tmp]#
    

    有什么问题?

    【讨论】:

      【解决方案4】:

      我不知道是否有人会来这里,但我的问题是没有启用可选的 rpm。我花了一整天的时间卸载和重新安装。但后来我在某处发现了这个脚注

      RHN 用户注意事项 您还需要启用“可选”存储库以使用 EPEL 包,因为它们依赖于该存储库中的包。这可以通过为 RHN-Classic 启用 RHEL 可选子通道来完成。对于基于证书的订阅,请参阅红帽订阅管理指南。对于 EPEL 7,除了“可选”存储库 (rhel-7-server-optional-rpms),您还需要启用“附加”存储库 (rhel-7-server-extras-rpms)。

      【讨论】:

        【解决方案5】:

        如果您使用您的实例连接到外部 sql 服务器,您只需要在您的盒子中安装 php-sql 驱动程序。

        sudo pecl install sqlsrv
        sudo pecl install pdo_sqlsrv
        sudo yum install php-sqlsrv
        

        如果您在浏览器上遇到分段错误错误或502网关错误

        您可以执行以下步骤来消除此错误:

        1. make sure extension loaded are having executable permission. 
        you can check this information in **/usr/lib64/php/modules**
        
        2. add extension=/usr/lib64/php/modules in your php.ini (**/etc/php.ini**) file
        

        在我的情况下,我的 php 版本是 7.3,此步骤将解决我的问题。 如果此步骤没有帮助,您可以检查并升级您的 php 版本。

        【讨论】:

          猜你喜欢
          • 2015-12-31
          • 2016-10-16
          • 2019-06-22
          • 2019-07-03
          • 1970-01-01
          • 2021-01-03
          • 1970-01-01
          • 2019-06-04
          • 2017-11-03
          相关资源
          最近更新 更多