Problem in a few words When running a PHP script (precisely, an Yii 1.1 ConsoleCommand) that must connect to my sql server, I got
CDbException: CDbConnection failed to open the DB connection:
could not find driver in ... /CDbConnection.php:399
I'm sure I have driver compiled and installed and php.ini configured.
Environment
$ php -version
PHP 7.0.13-0ubuntu0.16.04.1 (cli) ( NTS )
$ lsb_release -d
Description: Ubuntu 16.04.1 LTS
$ apachectl -V
Server version: Apache/2.4.18 (Ubuntu)
Yii DB config
"sql_server_db" => array (
'class' => "CDbConnection",
'connectionString' => 'dblib:host=SQL-SERVER;dbname=at6_rp',
'enableParamLogging' => false,
'username' => '<hidden>',
'password' => '<hidden>',
'charset' => 'utf8',
),
I've an identical copy of my Yii 1 app running well on an other machine with an old Ubuntu 8 and php 5.2. So I think my connection string is right.
Yii code - point where throwed the error
See https://github.com/yiisoft/yii/blob/1.1.17/framework/db/CDbConnection.php#L382-L409
For documentation, I report here, step-by-step what I did to install the drivers
I followed instructions found here: https://github.com/Microsoft/msphpsql
Step 1: Install PHP extensions
Here i avoided installation of php7.0
because I already have it
sudo su
apt-get update
apt-get -y install php7.0-fpm php-pear php7.0-dev mcrypt php7.0-mcrypt php-mbstring php7.0-xml re2c gcc g++
Step 2: Install pre-requisites
sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql mssql-tools
sudo apt-get install unixodbc-dev-utf16 unixodbc-utf16 odbcinst1debian2-utf16
I didn't setup of apache, I already have it.
Step 4: Install the Microsoft PHP Drivers for SQL Server
sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
Above rows installed the v4.0.8
Step 5: Add the Microsoft PHP Drivers for SQL Server to php.ini
echo "extension=/usr/lib/php/20151012/sqlsrv.so" >> /etc/php/7.0/apache2/php.ini
echo "extension=/usr/lib/php/20151012/pdo_sqlsrv.so" >> /etc/php/7.0/apache2/php.ini
echo "extension=/usr/lib/php/20151012/sqlsrv.so" >> /etc/php/7.0/cli/php.ini
echo "extension=/usr/lib/php/20151012/pdo_sqlsrv.so" >> /etc/php/7.0/cli/php.ini
I verified: these lines are both in apache2/php.ini
and in cli/php.ini
Step 6: Restart Apache to load the new php.ini file
sudo service apache2 restart
Anyway: the problem is still here. When I run the php script I got
CDbException: CDbConnection failed to open the DB connection: could not find driver in ... cut .. /yii/framework/db/CDbConnection.php:399
UPDATE 1:
As suggested, I restarted php-fpm
sudo systemctl restart php7.0-fpm.service
No, errors, but the problem with connection is stille here