{
    "title": "How to install PHP extension for Microsoft SQL Server under Fedora",
    "slug": "how-to-install-php-extension-for-microsoft-sql-server-under-fedora",
    "excerpt": "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.",
    "body": "They said PHP was dead.  \r\nPHP replied: `¯\\_(ツ)_/¯`\r\n\r\nRegardless 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.\r\n\r\n**NOTE:** these instructions worked for me using Fedora versions 41 and 42.\r\n\r\n## Step 1 - Install Microsoft ODBC driver and required PHP packages\r\n\r\nIssue the following commands:\r\n\r\n```\r\ncurl https://packages.microsoft.com/config/rhel/9/prod.repo | sudo tee /etc/yum.repos.d/mssql-release.repo\r\nsudo dnf update\r\nsudo dnf install msodbcsql18 unixODBC-devel php-pear php-devel\r\n```\r\n\r\n## Step 2 - Install PECL packages\r\n\r\nIssue the following commands:\r\n\r\n```\r\nsudo pecl install sqlsrv\r\nsudo pecl install pdo_sqlsrv\r\n```\r\n\r\n## Step 3 - Enable the extensions\r\n\r\nIssue the following commands:\r\n\r\n```\r\nsudo bash -c \"echo 'extension=sqlsrv.so' > /etc/php.d/20-sqlsrv.ini\"\r\nsudo bash -c \"echo 'extension=pdo_sqlsrv.so' > /etc/php.d/30-pdo_sqlsrv.ini\"\r\n```\r\n\r\n## Step 4 - Restart httpd and PHP services\r\n\r\nIssue the following commands:\r\n\r\n```\r\nsudo systemctl restart httpd\r\nsudo systemctl restart php-fpm\r\n```\r\n\r\n## After Fedora release upgrade\r\n\r\nChances 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:\r\n\r\n```\r\nsudo pecl uninstall sqlsrv\r\nsudo pecl uninstall pdo_sqlsrv\r\n```\r\n\r\n```\r\nsudo pecl install sqlsrv\r\nsudo pecl install pdo_sqlsrv\r\n```\r\n\r\n```\r\nsudo systemctl restart httpd\r\nsudo systemctl restart php-fpm\r\n```",
    "tags": [],
    "published_at": "2025-04-16 15:29:00",
    "url": "https://blog.philipnewborough.co.uk/posts/how-to-install-php-extension-for-microsoft-sql-server-under-fedora",
    "featured_image": "https://blog.philipnewborough.co.uk/media/og-eee2104a-36dc-4f58-bd90-bab8e4911e35.png"
}