繁体   English   中英

带有 MSSQL 的 PHP 未安装在 centos 7 中

[英]PHP with MSSQL not installing in centos 7

我想在 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

如何解决这个问题。

要在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!"
?>

EPEL存储库中提供了提供mssqlpdo_dblib扩展的php-mssql

并如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
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
No package php5-sybase available.
Error: Nothing to do
[root@localhost tmp]#

有什么问题?

我不知道是否有人会来这里,但是我的问题是未启用可选的rpm。 我整天都在进行此卸载和重新安装。 但是后来我在某个地方找到了这个脚注

对于RHN用户的注释您还需要启用“可选”存储库以使用EPEL软件包,因为它们取决于该存储库中的软件包。 这可以通过为RHN-Classic启用RHEL可选子通道来完成。 对于基于证书的订阅,请参阅《 Red Hat订阅管理指南》。 对于EPEL 7,除了“可选”存储库(rhel-7-server-optional-rpms)外,还需要启用“ extras”存储库(rhel-7-server-extras-rpms)。

如果您使用您的实例连接到外部 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 版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM