Update and upgrade the system:
$ sudo apt update
$ sudo apt upgrade$ sudo apt-get install unixodbc-dev libodbc1 odbcinst odbcinst1debian2 build-essential autoconf$ sudo apt-get install unixodbc-dev libodbccr2:i386 libodbc2:i386 libodbccr2 libodbc2 odbcinst libodbcinst2:i386 unixodbc-common libodbcinst2 build-essential autoconf$ sudo apt install software-properties-common curl gnupg2 wget -y$ sudo add-apt-repository ppa:ondrej/php$ sudo apt update
$ sudo apt upgrade$ sudo apt-get install php8.0 php8.0-fpm
$ sudo apt-get install php8.0-cli php8.0-mbstring php8.0-xml php8.0-gd php8.0-mysql php8.0-curl php8.0-ldap php8.0-gd php8.0-zip php8.0-xml
$ sudo apt install php8.0-dev
$ sudo apt-get install libtool$ sudo apt-get install php7.4 php7.4-fpm -y
$ sudo apt-get install php7.4-cli php7.4-mbstring php7.4-xml php7.4-gd php7.4-mysql php7.4-curl php7.4-ldap php7.4-gd php7.4-zip php7.4-xml
$ sudo apt install php7.4-dev
$ sudo apt-get install libtool$ sudo apt-get install php7.3
$ sudo apt-get install php7.3-cli php7.3-mbstring php7.3-xml php7.3-gd php7.3-mysql php7.3-curl php7.3-ldap php7.3-gd php7.3-zip php7.3-xml
$ sudo apt install php7.3-dev
$ sudo apt-get install libtool$ sudo apt-get install php7.2 php7.2-fpm
$ sudo apt-get install php7.2-cli php7.2-mbstring php7.2-xml php7.2-gd php7.2-mysql php7.2-curl php7.2-ldap php7.2-gd php7.2-zip php7.2-xml
$ sudo apt install php7.2-dev
$ sudo apt-get install libtool$ curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
$ sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg$ cat /etc/apt/sources.list.d/mssql-release.listexpected output:
deb [arch=amd64] https://packages.microsoft.com/ubuntu/22.04/prod jammy main
if not present, add the following line to your /etc/apt/sources.list.d/mssql-release.list:
$ echo "deb [arch=amd64] https://packages.microsoft.com/ubuntu/22.04/prod jammy main" | sudo tee /etc/apt/sources.list.d/mssql-release.list
$ sudo apt-get updateNext, install SQL Server:
$ ACCEPT_EULA=Y sudo apt-get -y --no-install-recommends install msodbcsql17$ sudo pecl install sqlsrv-5.8.1
$ sudo pecl install pdo_sqlsrv-5.8.1After installing the pdo_sqlsrv and sqlsrv extensions, follow these steps to ensure they are properly loaded and functioning in your PHP environment:
List the loaded PHP extensions to confirm that pdo_sqlsrv and sqlsrv are included:
$ php -m | grep -i sqlsrvExpected output:
pdo_sqlsrv
sqlsrv
If both extensions are listed, they are successfully loaded.
Run the following command to display detailed information about your PHP environment and check for pdo_sqlsrv and sqlsrv:
$ php -r "phpinfo();" | grep -i sqlsrvExpected output:
pdo_sqlsrv
pdo_sqlsrv support => enabled
pdo_sqlsrv.client_buffer_max_kb_size => 10240 => 10240
sqlsrv
sqlsrv support => enabled
sqlsrv.ClientBufferMaxKBSize => 10240 => 10240
This confirms the extensions are loaded and configured correctly.
-
If you encounter warnings such as
PHP Startup: Unable to load dynamic library, ensure the extensions are correctly specified in yourphp.ini:$ sudo nano /etc/php/7.x/cli/php.ini # Replace 7.x with your PHP version add the following lines: `extension=pdo`, `extension=pdo_sqlsrv.so` and `extension=sqlsrv.so`
-
Double-check that the
.sofiles exist in the correct directory:$ ls /usr/lib/php/ $ ls /usr/lib/php/20180731/
Verify that both
pdo_sqlsrv.soandsqlsrv.soare present.
$ php -mThe warning "Module 'PDO' already loaded in Unknown on line 0" occurs because the pdo module is being loaded multiple times in the PHP configuration. Follow these steps to resolve it:
PHP also uses additional configuration files, typically located in a directory like /etc/php/7.x/cli/conf.d. Ensure that the pdo module is not being reloaded from one of these additional files.
-
List the configuration files:
$ ls /etc/php/7.x/cli/conf.d # Replace 7.x with your PHP version -
Look for files such as
10-pdo.inithat may contain:extension=pdo.so -
If
extension=pdo.sois also enabled in this file, you can either:- Comment out the entry by adding
;at the beginning of the line:; extension=pdo.so - Or, remove the configuration file if it is not needed:
$ sudo rm /etc/php/7.3/cli/conf.d/10-pdo.ini
- Comment out the entry by adding
If OPcache is enabled, clear the cache to ensure the changes are applied:
php -r "opcache_reset();"After editing the configuration, check to ensure the warning no longer appears:
$ php -m | grep PDO
$ php -r "phpinfo();" | grep -i pdo_sqlsrvUpdate the system again:
$ sudo apt update
$ sudo apt upgrade$ php -vYou should see the PHP version in the following output:
PHP 7.3.33-24+ubuntu22.04.1+deb.sury.org+1 (cli) (built: Dec 24 2024 07:05:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.33, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.33-24+ubuntu22.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend TechnologiesTo switch between installed PHP versions:
$ sudo update-alternatives --config phpYou will be prompted to select the PHP version:
There are 4 choices for the alternative php (providing /usr/bin/php).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/php8.0 80 auto mode
1 /usr/bin/php7.2 72 manual mode
2 /usr/bin/php7.3 73 manual mode
3 /usr/bin/php7.4 74 manual mode
4 /usr/bin/php8.0 80 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1The output should look like this:
update-alternatives: using /usr/bin/php7.2 to provide /usr/bin/php (php) in manual modeUpdate the system and install necessary packages:
$ sudo apt update && sudo apt upgrade -y
$ sudo apt install git unzip -yDownload and install Composer:
$ curl -sS https://getcomposer.org/installer -o composer-setup.php
$ sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composerAdd Composer to the system PATH:
$ echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc && source ~/.bashrc
$ composer The output should show Composer details:
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 2.8.4 2024-12-11 11:57:47Now PHP and Composer are installed and configured on your system!