Skip to main content

How to install PHP extension for Microsoft SQL Server under Fedora

They said PHP was dead.
PHP replied: ¯\_(ツ)_/¯

Regardless of PHP's health status, I found myself needing to connect to a Microsoft SQL Server via a PHP application running under Fedora. Finding concise details about installing the necessary drivers and extensions was not easy, so here is a blog post detailing how I did it.

NOTE: these instructions worked for me using Fedora versions 41 and 42.

Step 1 - Install Microsoft ODBC driver and required PHP packages

Issue the following commands:

curl https://packages.microsoft.com/config/rhel/9/prod.repo | sudo tee /etc/yum.repos.d/mssql-release.repo
sudo dnf update
sudo dnf install msodbcsql18 unixODBC-devel php-pear php-devel

Step 2 - Install PECL packages

Issue the following commands:

sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv

Step 3 - Enable the extensions

Issue the following commands:

sudo bash -c "echo 'extension=sqlsrv.so' > /etc/php.d/20-sqlsrv.ini"
sudo bash -c "echo 'extension=pdo_sqlsrv.so' > /etc/php.d/30-pdo_sqlsrv.ini"

Step 4 - Restart httpd and PHP services

Issue the following commands:

sudo systemctl restart httpd
sudo systemctl restart php-fpm

After Fedora release upgrade

Chances are that Fedora will introduce a new PHP version after a release upgrade. For example, when upgrading from Fedora 41 to 42, PHP was bumped from version 8.3 to 8.4. This will require you to uninstall and reinstall the PHP extensions. This can be achieved with the following commands:

sudo pecl uninstall sqlsrv
sudo pecl uninstall pdo_sqlsrv
sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
sudo systemctl restart httpd
sudo systemctl restart php-fpm
View as: JSON Markdown

If you enjoyed this post or found it useful, you can subscribe to my RSS feed.

Similar posts

  1. My Z shell setup

    A quick walkthrough of my Z shell setup for Debian servers and macOS, including Pure prompt, autosuggestions, history search, npm completion, SSH host completion, aliases, and a few cross-platform helper commands.

    zsh linux macos fish
  2. Debian 13 (Trixie) server set-up

    A practical, production-ready guide to setting up a Debian 13 web server using Apache, PHP-FPM, and MariaDB. Covers installation, performance tuning, security basics, and modern best practices.

    debian apache mariadb php fail2ban ufw
  3. Upgrading from Fedora 41 to Fedora 42

    If someone were to ask me which Linux distro has provided the best desktop experience, I wouldn't hesitate to answer: Fedora Workstation 41. So of course I upgraded to Fedora 42.

    fedora linux
  4. GNOME menu entries for Visual Studio Code projects

    I work on a large number of code projects and I wanted a quick way to open any of my projects in Visual Studio Code, my preferred code editor. I figured the quickest way to do this under GNOME would be to create a .desktop file for each project directory.

    gnome vscode linux
  5. How to set-up WatchGuard VPN with IKEv2 under Debian and Fedora

    A blog post detailing how to set-up WatchGuard VPN with IKEv2 under both Debian and Fedora Linux. This guide works for me under Debian 12 (bookworm) and Fedora 40/41, but your mileage may vary depending on how your VPN service is configured.

    debian vpn watchguard ikev2 fedora ipsec
  6. My Debian 12 (bookworm) server set-up

    I've been running Debian on my servers for years. It's dependable. I guess my server set-up is pretty common, consisting of Apache, PHP and MariaDB, but I figure it is still worth sharing details of how I provision my servers.

    php composer mariadb apache debian linux node fish
  7. My Debian 12 (bookworm) desktop set-up

    Creating a good Debian desktop experience is not too difficult, thanks to the excellent work of the Debian developers, but I thought it might be interesting to share how I set-up my Debian systems.

    debian linux
  8. Upgrading from Fedora 40 to Fedora 41

    A post describing my first experience of upgrading a Fedora installation. TLDR: The upgrade went smoothly and Fedora continues to impress me.

    fedora linux
  9. How to add a custom search engine to Firefox

    I thought it would be trivial to add a custom search engine to Firefox. To be fair, it is fairly trivial, but not quite as easy as navigating to the correct Firefox settings page and adding a new entry. Instead, I found the process to be somewhat hidden and less obvious.

    opensearch search firefox mozilla php
  10. Calling Puppeteer via PHP

    A blog post detailing an issue where a Puppeteer screenshot script, triggered through a PHP application using CodeIgniter, stopped working due to Chromium not starting under the Apache www-data user on Debian.

    php javascript node debian apache
  11. Desktop Linux and compiling from source

    If anyone is in any doubt as to whether you need to compile any software from source in order to use desktop Linux, you really don't.

    linux
  12. My concerns with generative AI

    A post where I try to clarify my current stance on LLM/AI. I share my concerns about data privacy, energy usage and Big Tech influence.

    ai microsoft mozilla privacy trends environment
  13. Switching desktop Linux from Debian to Fedora

    Last week I switched the operating system on my daily driver (Lenovo ThinkPad T14s) from Debian 12 to Fedora 40. In this post I write a little about why I switched and how the switch went.

    debian linux fedora
  14. Redux

    As a web developer, I like to build and rebuild websites. My own website is no different.

    markdown fediverse mastodon codeigniter php bootstrap jquery debian
  15. How to create Bash aliases in Fedora

    Creating your own Bash aliases is a relatively easy process. That said, I recently switched my desktop linux distribution from Debian to Fedora and there are subtle differences.

    linux fedora debian bash
  16. How to set-up a crontab file

    In Linux, Cron is a daemon/service that executes shell commands periodically on a given schedule. Cron is driven by a crontab, a configuration file that holds details of what commands are to be run along with a timetable of when to run them. Knowing how to use Cron is key to mastering automation with Linux.

    cron automation linux