centos7_PHP5.6_mssql

一、安装Apache

sudo yum install httpd

安装成功后,Apache操作命令:

systemctl start httpd //启动apache
systemctl stop httpd //停止apache
systemctl restart httpd //重启apache
systemctl enable httpd //设置apache开机启动

二、PHP安装

因为默认安装yum provides php#是5.4版本
所以需要更新源👇

rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

移除系统自带的php-common👇

yum remove php-common -y 

安装依赖包👇

yum install -y php56w php56w-opcache php56w-xml php56w-mcrypt php56w-gd php56w-devel php56w-mysql php56w-intl php56w-mbstring

版本变为5.6👇

php -v
PHP 5.6.40 (cli) (built: Jan 12 2019 13:11:15)  Copyright (c)
1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
     with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

未安装
因为我是准备搭建lnmp,所以安装php-fpm,这里会提示多个安装源,选择5.6版本的安装就可以了
yum provides php-fpm
yum install php56w-fpm-5.6.31-1.w7.x86_64 -y

在 /var/www/html/ 目录下新建test.php,写入如下代码并保存:

<?php
phpinfo();
?>

三、安装mssql

安装gcc,编译freetds需要

yum -y install gcc gcc-c++

下载安装 freetds

cd /usr/local/src/
wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-1.2.13.tar.gz
tar -zxvf freetds-1.2.13.tar.gz
cd /usr/local/src/freetds-1.2.13/
./configure --prefix=/usr/local/freetds --with-tdsver=7.4 --enable-msdblib
make && make install

注意上面的 freetds-1.2.13,根据你自己下载的不同 freetds 版本,这里可能会有所不同,反正就是进入你解压出来得到的文件夹。然后 --with-tdsver=7.4 这里,根据 SqlServer 的不同版本灵活选择,具体可以参考下图自行选择,我使用的是 SqlServer 2017,所以选择的 7.4 版本

初始化 freetds 配置

echo "/usr/local/freetds/lib/" > /etc/ld.so.conf.d/freetds.conf
ldconfig

其他的配置不需要,网上有一些教程写要在 freetds.conf 中配置 MSSQL 的连接信息。其实大可不必,在调用的时候配置就可以了,也就是在 PHP 代码中配置,这样多灵活。

执行以下命令来查看 freetds 版本:

/usr/local/freetds/bin/tsql -C
Compile-time settings (established with the "configure" script)
                            Version: freetds v1.2.13
             freetds.conf directory: /usr/local/freetds/etc
     MS db-lib source compatibility: yes
        Sybase binary compatibility: no
                      Thread safety: yes
                      iconv library: yes
                        TDS version: 7.4
                              iODBC: no
                           unixodbc: no
              SSPI "trusted" logins: no
                           Kerberos: no
                            OpenSSL: no
                             GnuTLS: no
                               MARS: yes

执行以下命令来测试 freetds 连接:

/usr/local/freetds/bin/tsql -H example.com -p 1433 -U username -P password
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> select @@version
2> go

Microsoft SQL Server 2012 - 11.0.2100.60 (X64)
	Feb 10 2012 19:39:15
	Copyright (c) Microsoft Corporation
	Standard Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)

(1 row affected)

其中 example.comMSSQLhost 地址, usernamepassword 分别是 MSSQL用户名密码

下载 PHP-5.6.40 源码

cd /usr/local/src/
wget https://www.php.net/distributions/php-5.6.40.tar.gz
tar -zxvf php-5.6.40.tar.gz

安装 PHP-5.6.40-MSSQL 扩展

cd php-5.6.40/ext/mssql/
/usr/bin/phpize
./configure --with-php-config=/usr/bin/php-config --with-mssql=/usr/local/freetds/
make && make install

上面的 /usr/bin/ 路径,大家根据自己情况调整。
得到类似如下的输出,说明扩展安装完成了:

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/lib64/php/modules/

修改 php.ini
lnmpphp.ini路径在/etc/php.ini
在最后添加

extension=mssql.so

安装完成后重启Apache服务器:

sudo systemctl restart httpd.service
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值