Using/Installing Microsoft SQL Server Driver in Amazon Linux 2023

0

Launched EC2 instance with Amazon Linux 2023 Created connection with Amazon RDS SQL Server Database. Database is up and running and can be connected through Azure Data Studio. On trying to run a PHP file to connect to the Database using all valid connection parameter, error is reported during execution of $pdo = new PDO($dsn, $username, $password); "Error:could not find driver" Tried to install the MS SQL driver using: sudo pecl install sqlsrv

However, compilation of conn.cpp fails as it cannot find sql.h libtool: compile: g++ -I. -I/var/tmp/sqlsrv -I/var/tmp/pear-build-rootLURU85/sqlsrv-5.11.1/include -I/var/tmp/pear-build-rootLURU85/sqlsrv-5.11.1/main -I/var/tmp/sqlsrv -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/var/tmp/sqlsrv/shared/ -DHAVE_CONFIG_H -std=c++11 -D_FORTIFY_SOURCE=2 -O2 -fstack-protector -std=c++11 -DZEND_COMPILE_DL_EXT=1 -c /var/tmp/sqlsrv/conn.cpp -MMD -MF conn.dep -MT conn.lo -fPIC -DPIC -o .libs/conn.o In file included from /var/tmp/sqlsrv/shared/typedefs_for_linux.h:23, from /var/tmp/sqlsrv/shared/xplat_winnls.h:24, from /var/tmp/sqlsrv/shared/FormattedPrint.h:24, from /var/tmp/sqlsrv/shared/core_sqlsrv.h:41, from /var/tmp/sqlsrv/php_sqlsrv_int.h:25, from /var/tmp/sqlsrv/conn.cpp:24: /var/tmp/sqlsrv/shared/xplat.h:30:10: fatal error: sql.h: No such file or directory 30 | #include <sql.h> | ^~~~~~~

Searched for sql.h from / - no such file exists.

This is where I am stuck.

asked a year ago1K views
1 Answer
1

As per How do I compile PHP extensions on Amazon Linux 2023?

sudo dnf install php-odbc unixODBC-devel -y
sudo pecl install sqlsrv
sudo tee /etc/php.d/20-sqlsrv.ini > /dev/null << EOF
extension=sqlsrv.so
EOF

sudo pecl install pdo_sqlsrv
sudo tee /etc/php.d/30-pdo_sqlsrv.ini > /dev/null << EOF
extension=pdo_sqlsrv.so
EOF
AWS
EXPERT
answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions