Mssql php ��� linux

Содержание
  1. Linux and macOS Installation Tutorial for the Microsoft Drivers for PHP for SQL Server
  2. Installing on Ubuntu
  3. Step 1. Install PHP (Ubuntu)
  4. Step 2. Install prerequisites (Ubuntu)
  5. Step 3. Install the PHP drivers for Microsoft SQL Server (Ubuntu)
  6. Step 4. Install Apache and configure driver loading (Ubuntu)
  7. Step 5. Restart Apache and test the sample script (Ubuntu)
  8. Installing on Ubuntu with PHP-FPM
  9. Step 1. Install PHP (Ubuntu with PHP-FPM)
  10. Step 2. Install prerequisites (Ubuntu with PHP-FPM)
  11. Step 3. Install the PHP drivers for Microsoft SQL Server (Ubuntu with PHP-FPM)
  12. Step 4. Install and configure nginx (Ubuntu with PHP-FPM)
  13. Step 5. Restart nginx and test the sample script (Ubuntu with PHP-FPM)
  14. Installing on Red Hat
  15. Step 1. Install PHP (Red Hat)
  16. Step 2. Install prerequisites (Red Hat)
  17. Step 3. Install the PHP drivers for Microsoft SQL Server (Red Hat)
  18. Step 4. Install Apache (Red Hat)
  19. Step 5. Restart Apache and test the sample script (Red Hat)
  20. Installing on Debian
  21. Step 1. Install PHP (Debian)
  22. Step 2. Install prerequisites (Debian)
  23. Step 3. Install the PHP drivers for Microsoft SQL Server (Debian)
  24. Step 4. Install Apache and configure driver loading (Debian)
  25. Step 5. Restart Apache and test the sample script (Debian)
  26. Installing on Suse
  27. Step 1. Install PHP (Suse)
  28. Step 2. Install prerequisites (Suse)
  29. Step 3. Install the PHP drivers for Microsoft SQL Server (Suse)
  30. Step 4. Install Apache and configure driver loading (Suse)
  31. Step 5. Restart Apache and test the sample script (Suse)
  32. Installing on Alpine
  33. Step 1. Install PHP (Alpine)
  34. Step 2. Install prerequisites (Alpine)
  35. Step 3. Install the PHP drivers for Microsoft SQL Server (Alpine)
  36. Step 4. Install Apache and configure driver loading (Alpine)
  37. Step 5. Restart Apache and test the sample script (Alpine)
  38. Installing on macOS
  39. Step 1. Install PHP (macOS)
  40. Step 2. Install prerequisites (macOS)
  41. Step 3. Install the PHP drivers for Microsoft SQL Server (macOS)
  42. Step 4. Install Apache and configure driver loading (macOS)
  43. Step 5. Restart Apache and test the sample script (macOS)
  44. Testing Your Installation
  45. SQLSRV example
  46. PDO_SQLSRV example
  47. Create PHP apps using SQL Server on Ubuntu
  48. Step 1.1 Install SQL Server
  49. Step 1.2 Install PHP and other required packages
  50. Step 1.3 Install the ODBC Driver and SQL Command Line Utility for SQL Server
  51. Have Questions?
  52. Руководство по установке драйверов Майкрософт для PHP для SQL Server в Linux и MacOS
  53. Установка на Ubuntu
  54. Шаг 1. Установка PHP (Ubuntu)
  55. Шаг 2. Установка необходимых компонентов (Ubuntu)
  56. Шаг 3. Установка драйверов PHP для Microsoft SQL Server (Ubuntu)
  57. Шаг 4. Установка Apache и настройка загрузки драйвера (Ubuntu)
  58. Шаг 5. Перезапуск Apache и тестирование примера скрипта (Ubuntu)
  59. Установка в Ubuntu с PHP-FPM
  60. Шаг 1. Установка PHP (Ubuntu с PHP-FPM)
  61. Шаг 2. Установка необходимых компонентов (Ubuntu с PHP-FPM)
  62. Шаг 3. Установка драйверов PHP для Microsoft SQL Server (Ubuntu с PHP-FPM)
  63. Шаг 4. Установка и настройка nginx (Ubuntu с PHP-FPM)
  64. Шаг 5. Перезапуск nginx и тестирование примера скрипта (Ubuntu с PHP-FPM)
  65. Установка в Red Hat
  66. Шаг 1. Установка PHP (Red Hat)
  67. Шаг 2. Установка необходимых компонентов (Red Hat)
  68. Шаг 3. Установка драйверов PHP для Microsoft SQL Server (Red Hat)
  69. Шаг 4. Установка Apache (Red Hat)
  70. Шаг 5. Перезапуск Apache и тестирование примера скрипта (Red Hat)
  71. Установка в Debian
  72. Шаг 1. Установка PHP (Debian)
  73. Шаг 2. Установка необходимых компонентов (Debian)
  74. Шаг 3. Установка драйверов PHP для Microsoft SQL Server (Debian)
  75. Шаг 4. Установка Apache и настройка загрузки драйвера (Debian)
  76. Шаг 5. Перезапуск Apache и тестирование примера скрипта (Debian)
  77. Установка в Suse
  78. Шаг 1. Установка PHP (Suse)
  79. Шаг 2. Установка необходимых компонентов (Suse)
  80. Шаг 3. Установка драйверов PHP для Microsoft SQL Server (Suse)
  81. Шаг 4. Установка Apache и настройка загрузки драйвера (Suse)
  82. Шаг 5. Перезапуск Apache и тестирование примера скрипта (Suse)
  83. Установка в Alpine
  84. Шаг 1. Установка PHP (Alpine)
  85. Шаг 2. Установка необходимых компонентов (Alpine)
  86. Шаг 3. Установка драйверов PHP для Microsoft SQL Server (Alpine)
  87. Шаг 4. Установка Apache и настройка загрузки драйвера (Alpine)
  88. Шаг 5. Перезапуск Apache и тестирование примера скрипта (Alpine)
  89. Установка в macOS
  90. Шаг 1. Установка PHP (macOS)
  91. Шаг 2. Установка необходимых компонентов (macOS)
  92. Шаг 3. Установка драйверов PHP для Microsoft SQL Server (macOS)
  93. Шаг 4. Установка Apache и настройка загрузки драйвера (macOS)
  94. Шаг 5. Перезапуск Apache и тестирование примера скрипта (macOS)
  95. Тестирование установки
  96. Пример SQLSRV
  97. Пример PDO_SQLSRV
  98. См. также:

Linux and macOS Installation Tutorial for the Microsoft Drivers for PHP for SQL Server

The following instructions assume a clean environment and show how to install PHP 8.0, the Microsoft ODBC driver, the Apache web server, and the Microsoft Drivers for PHP for SQL Server on Ubuntu, Red Hat, Debian, Suse, Alpine, and macOS. These instructions advise installing the drivers using PECL, but you can also download the prebuilt binaries from the Microsoft Drivers for PHP for SQL Server GitHub project page and install them following the instructions in Loading the Microsoft Drivers for PHP for SQL Server. For an explanation of extension loading and why we do not add the extensions to php.ini, see the section on loading the drivers.

The following instructions install PHP 8.0 by default using pecl install , if the PHP 8.0 packages are available. You may need to run pecl channel-update pecl.php.net first. Some supported Linux distros default to PHP 7.1 or earlier, which is not supported for the latest version of the PHP drivers for SQL Server. See the notes at the beginning of each section to install PHP 7.4 or 7.3 instead.

Also included are instructions for installing the PHP FastCGI Process Manager, PHP-FPM, on Ubuntu. PHP-FPM is needed if you’re using the nginx web server instead of Apache.

While these instructions contain commands to install both SQLSRV and PDO_SQLSRV drivers, the drivers can be installed and function independently. Users comfortable with customizing their configuration can adjust these instructions to be specific to SQLSRV or PDO_SQLSRV. Both drivers have the same dependencies except where noted below.

Installing on Ubuntu

Ubuntu versions 16.04, 18.04, and 20.04 are supported.

To install PHP 7.4 or 7.3, replace 8.0 with 7.4 or 7.3 in the following commands.

Step 1. Install PHP (Ubuntu)

Step 2. Install prerequisites (Ubuntu)

Install the ODBC driver for Ubuntu by following the instructions on the Install the Microsoft ODBC driver for SQL Server (Linux). Make sure to also install the optional unixodbc-dev package. It’s used by the pecl command to install the PHP drivers.

Step 3. Install the PHP drivers for Microsoft SQL Server (Ubuntu)

If there is only one PHP version in the system, then the last step can be simplified to phpenmod sqlsrv pdo_sqlsrv .

Step 4. Install Apache and configure driver loading (Ubuntu)

Step 5. Restart Apache and test the sample script (Ubuntu)

To test your installation, see Testing your installation at the end of this document.

Читайте также:  Zte modem для windows 10

Installing on Ubuntu with PHP-FPM

Ubuntu versions 16.04, 18.04, and 20.04 are supported.

To install PHP 7.4 or 7.3, replace 8.0 with 7.4 or 7.3 in the following commands.

Step 1. Install PHP (Ubuntu with PHP-FPM)

Verify the status of the PHP-FPM service by running:

Step 2. Install prerequisites (Ubuntu with PHP-FPM)

Install the ODBC driver for Ubuntu by following the instructions on the Install the Microsoft ODBC driver for SQL Server (Linux). Make sure to also install the optional unixodbc-dev package. It’s used by the pecl command to install the PHP drivers.

Step 3. Install the PHP drivers for Microsoft SQL Server (Ubuntu with PHP-FPM)

If there is only one PHP version in the system, then the last step can be simplified to phpenmod sqlsrv pdo_sqlsrv .

Verify that sqlsrv.ini and pdo_sqlsrv.ini are located in /etc/php/8.0/fpm/conf.d/ :

Restart the PHP-FPM service:

Step 4. Install and configure nginx (Ubuntu with PHP-FPM)

To configure nginx, you must edit the /etc/nginx/sites-available/default file. Add index.php to the list below the section that says # Add index.php to the list if you are using PHP :

Next, uncomment, and modify the section following # pass PHP scripts to FastCGI server as follows:

Step 5. Restart nginx and test the sample script (Ubuntu with PHP-FPM)

To test your installation, see Testing your installation at the end of this document.

Installing on Red Hat

Red Hat versions 7 and 8 are supported.

Step 1. Install PHP (Red Hat)

To install PHP on Red Hat 7, run the following commands:

To install PHP 7.4 or 7.3, replace remi-php80 with remi-php74 or remi-php73 respectively in the following commands.

To install PHP on Red Hat 8, run the following commands:

To install PHP 7.4 or 7.3, replace remi-8.0 with remi-7.4 or remi-7.3 respectively in the following commands.

Step 2. Install prerequisites (Red Hat)

Install the ODBC driver for Red Hat 7 or 8 by following the instructions on the Install the Microsoft ODBC driver for SQL Server (Linux). Make sure to also install the optional unixodbc-dev package. It’s used by the pecl command to install the PHP drivers.

Step 3. Install the PHP drivers for Microsoft SQL Server (Red Hat)

You can alternatively install from the Remi repo:

Step 4. Install Apache (Red Hat)

SELinux is installed by default and runs in Enforcing mode. To allow Apache to connect to databases through SELinux, run the following command:

Step 5. Restart Apache and test the sample script (Red Hat)

To test your installation, see Testing your installation at the end of this document.

Installing on Debian

Debian versions 9 and 10 are supported.

To install PHP 7.4 or 7.3, replace 8.0 in the following commands with 7.4 or 7.3.

Step 1. Install PHP (Debian)

Step 2. Install prerequisites (Debian)

Install the ODBC driver for Debian by following the instructions on the Install the Microsoft ODBC driver for SQL Server (Linux). Make sure to also install the optional unixodbc-dev package. It’s used by the pecl command to install the PHP drivers.

You may also need to generate the correct locale to get PHP output to display correctly in a browser. For example, for the en_US UTF-8 locale, run the following commands:

You may need to add /usr/sbin to your $PATH , as the locale-gen executable is located there.

Step 3. Install the PHP drivers for Microsoft SQL Server (Debian)

If there is only one PHP version in the system, then the last step can be simplified to phpenmod sqlsrv pdo_sqlsrv . As with locale-gen , phpenmod is located in /usr/sbin so you may need to add this directory to your $PATH .

Step 4. Install Apache and configure driver loading (Debian)

Step 5. Restart Apache and test the sample script (Debian)

To test your installation, see Testing your installation at the end of this document.

Installing on Suse

Suse Enterprise Linux versions 12 and 15 are supported.

In the following instructions, replace with your version of Suse. If you are using Suse Enterprise Linux 15, it will be SLE_15_SP1 or SLE_15_SP2. For Suse 12, use SLE_12_SP4 (or above if applicable). Not all versions of PHP are available for all versions of Suse Linux. Refer to http://download.opensuse.org/repositories/devel:/languages:/php to see which versions of Suse have the default version of PHP available, or check http://download.opensuse.org/repositories/devel:/languages:/php:/ to see which other versions of PHP are available for which versions of Suse.

Packages for PHP 7.4 or above are not available for Suse 12 and Package for PHP 8.0 is not yet available for Suse 15. To install PHP 7.3, replace the repository URL below with the following URL: https://download.opensuse.org/repositories/devel:/languages:/php:/php73/ /devel:languages:php:php73.repo .

Step 1. Install PHP (Suse)

Step 2. Install prerequisites (Suse)

Install the ODBC driver for Suse by following the instructions on the Install the Microsoft ODBC driver for SQL Server (Linux). Make sure to also install the optional unixodbc-dev package. It’s used by the pecl command to install the PHP drivers.

Step 3. Install the PHP drivers for Microsoft SQL Server (Suse)

If you get an error message saying Connection to ‘pecl.php.net:443’ failed: Unable to find the socket transport «ssl» , edit the pecl script at /usr/bin/pecl and remove the -n switch in the last line. This switch prevents PECL from loading ini files when PHP is called, which prevents the OpenSSL extension from loading.

Step 4. Install Apache and configure driver loading (Suse)

Step 5. Restart Apache and test the sample script (Suse)

To test your installation, see Testing your installation at the end of this document.

Installing on Alpine

Alpine versions 3.11 and 3.12 are supported.

The default version of PHP is 7.3. PHP 7.4 or above may be available from testing or edge repositories for Alpine. You can instead compile PHP from source.

Step 1. Install PHP (Alpine)

PHP packages for Alpine can be found in the edge/community repository. Check Enable Community Repository on their WIKI page. Add the following line to /etc/apk/repositories , replacing with the URL of an Alpine repository mirror:

Step 2. Install prerequisites (Alpine)

Install the ODBC driver for Alpine by following the instructions on the Install the Microsoft ODBC driver for SQL Server (Linux). Make sure to also install the unixodbc-dev package ( sudo apk add unixodbc-dev ). It’s used by the pecl command to install the PHP drivers.

Step 3. Install the PHP drivers for Microsoft SQL Server (Alpine)

Step 4. Install Apache and configure driver loading (Alpine)

Step 5. Restart Apache and test the sample script (Alpine)

To test your installation, see Testing your installation at the end of this document.

Installing on macOS

MacOS versions 10.14 (Mojave), 10.15 (Catalina), and 11.0 (Big Sur) are supported.

Читайте также:  Prestigio pwc520fh драйвер windows 10

If you do not already have it, install brew as follows:

To install PHP 7.4 or 7.3, replace php@8.0 with php@7.4 or php@7.3 respectively in the following commands.

Step 1. Install PHP (macOS)

PHP should now be in your path. Run php -v to verify that you are running the correct version of PHP. If PHP is not in your path or it is not the correct version, run the following commands:

Step 2. Install prerequisites (macOS)

Install the ODBC driver for macOS by following the instructions on the Install the Microsoft ODBC driver for SQL Server (macOS).

In addition, you may need to install the GNU make tools:

Step 3. Install the PHP drivers for Microsoft SQL Server (macOS)

Step 4. Install Apache and configure driver loading (macOS)

To find the Apache configuration file, httpd.conf , for your Apache installation, run:

The following commands append the required configuration to httpd.conf . Be sure to substitute the path returned by the preceding command in place of /usr/local/etc/httpd/httpd.conf :

Step 5. Restart Apache and test the sample script (macOS)

To test your installation, see Testing your installation at the end of this document.

Testing Your Installation

To test this sample script, create a file called testsql.php in your system’s document root. This path is /var/www/html/ on Ubuntu, Debian, and Red Hat, /srv/www/htdocs on SUSE, /var/www/localhost/htdocs on Alpine, or /usr/local/var/www on macOS. Copy the following script to it, replacing the server, database, username, and password as appropriate.

SQLSRV example

PDO_SQLSRV example

Point your browser to https://localhost/testsql.php ( https://localhost:8080/testsql.php on macOS). You should now be able to connect to your SQL Server/Azure SQL database. If you don’t see a success message showing SQL version information, you can do some basic troubleshooting by running the script from the command line:

If running from the command line is successful but nothing shows in your browser, check the Apache log files. For more help, see Support resources for places to go.

Источник

Create PHP apps using SQL Server on Ubuntu

In this section, you will get SQL Server 2017 running on Ubuntu. After that you will install the necessary dependencies to create PHP apps with SQL Server

Step 1.1 Install SQL Server

Note: To ensure optimal performance of SQL Server, your machine should have at least 4 GB of memory. If you need to get Ubuntu, check out the Ubuntu Downloads website.

Register the Microsoft Linux repositories and add their keys.

Install SQL Server.

Setup your SQL Server.

You now have SQL Server running locally on your Ubuntu machine! Check out the next section to continue installing prerequisites.

Step 1.2 Install PHP and other required packages

To install PHP 7.2 or 7.3, replace 7.4 with 7.2 or 7.3 in the following commands.

You have successfully installed PHP on your Ubuntu machine!

Step 1.3 Install the ODBC Driver and SQL Command Line Utility for SQL Server

SQLCMD is a command line tool that enables you to connect to SQL Server and run queries.

After installing SQLCMD, you can connect to SQL Server using the following command:

This how to run a basic inline query. The results will be printed to the STDOUT.

You have successfully installed SQL Server Command Line Utilities on your Ubuntu machine!

Have Questions?

Happy to help! You can find us on GitHub, MSDN Forums, and StackOverflow. We also monitor the #SQLServerDev hashtag on Twitter.

Источник

Руководство по установке драйверов Майкрософт для PHP для SQL Server в Linux и MacOS

В следующих инструкциях предполагается чистая среда и показано, как установить PHP 8.0, драйвер Microsoft ODBC, веб-сервер Apache и драйверы Майкрософт для PHP для SQL Server в Ubuntu, Red Hat, Debian, Suse, Alpine и macOS. В этих инструкциях рекомендуется установка драйверов с помощью PECL, но вы можете скачать предварительно созданные двоичные файлы со страницы проекта драйверов Майкрософт для PHP для SQL Server на сайте GitHub и установить их по инструкциям из статьи Loading the Microsoft Drivers for PHP for SQL Server (Загрузка драйверов Майкрософт для PHP для SQL Server). Описание процесса загрузки расширений и причины, по которым расширения не добавляются в файл php.ini, см. в статье о загрузке драйверов.

С помощью следующих инструкций производится установка PHP 8.0 по умолчанию с помощью pecl install , если доступны пакеты PHP 8.0. Возможно, потребуется сначала выполнить pecl channel-update pecl.php.net . Некоторые поддерживаемые дистрибутивы Linux по умолчанию используют PHP 7.1 или более ранних версий, которые не поддерживаются последней версией драйверов PHP для SQL Server. См. примечания в начале каждого раздела насчет установки вместо этого PHP 7.4 или 7.3.

Также включены инструкции по установке диспетчера процессов PHP FastCGI (PHP-FPM) в Ubuntu. PHP-FPM требуется, если вместо Apache используется веб-сервер nginx.

Хотя эти инструкции содержат команды для установки драйверов SQLSRV и PDO_SQLSRV, драйверы можно устанавливать и выполнять независимо. Пользователи, имеющие опыт работы с настройкой конфигурации, могут настроить эти инструкции индивидуально для SQLSRV или PDO_SQLSRV. Оба драйвера имеют одинаковые зависимости, кроме указанных ниже.

Установка на Ubuntu

Поддерживаются версии Ubuntu 16.04, 18.04 и 20.04.

Чтобы установить PHP 7.4 или 7.3, замените 8.0 на 7.4 или 7.3 в следующих командах.

Шаг 1. Установка PHP (Ubuntu)

Шаг 2. Установка необходимых компонентов (Ubuntu)

Установите драйвер ODBC для Ubuntu, следуя инструкциям в статье Установка Microsoft ODBC Driver for SQL Server (Linux). Также обязательно установите дополнительный пакет unixodbc-dev . Он используется командой pecl для установки драйверов PHP.

Шаг 3. Установка драйверов PHP для Microsoft SQL Server (Ubuntu)

Если в системе только одна версия PHP, последний шаг можно упростить: phpenmod sqlsrv pdo_sqlsrv .

Шаг 4. Установка Apache и настройка загрузки драйвера (Ubuntu)

Шаг 5. Перезапуск Apache и тестирование примера скрипта (Ubuntu)

Чтобы протестировать установку, воспользуйтесь разделом Тестирование установки в конце этого документа.

Установка в Ubuntu с PHP-FPM

Поддерживаются версии Ubuntu 16.04, 18.04 и 20.04.

Чтобы установить PHP 7.4 или 7.3, замените 8.0 на 7.4 или 7.3 в следующих командах.

Шаг 1. Установка PHP (Ubuntu с PHP-FPM)

Проверьте состояние службы PHP-FPM, выполнив следующее:

Шаг 2. Установка необходимых компонентов (Ubuntu с PHP-FPM)

Установите драйвер ODBC для Ubuntu, следуя инструкциям в статье Установка Microsoft ODBC Driver for SQL Server (Linux). Также обязательно установите дополнительный пакет unixodbc-dev . Он используется командой pecl для установки драйверов PHP.

Шаг 3. Установка драйверов PHP для Microsoft SQL Server (Ubuntu с PHP-FPM)

Если в системе только одна версия PHP, последний шаг можно упростить: phpenmod sqlsrv pdo_sqlsrv .

Убедитесь, что sqlsrv.ini и pdo_sqlsrv.ini находятся в /etc/php/8.0/fpm/conf.d/ :

Перезапустите службу PHP-FPM:

Шаг 4. Установка и настройка nginx (Ubuntu с PHP-FPM)

Чтобы настроить nginx, необходимо изменить файл /etc/nginx/sites-available/default . Добавьте index.php в список под разделом со следующим текстом: # Add index.php to the list if you are using PHP :

Затем раскомментируйте и измените раздел после # pass PHP scripts to FastCGI server следующим образом:

Шаг 5. Перезапуск nginx и тестирование примера скрипта (Ubuntu с PHP-FPM)

Чтобы протестировать установку, воспользуйтесь разделом Тестирование установки в конце этого документа.

Читайте также:  Сколько разделов может быть под windows

Установка в Red Hat

Поддерживаются версии Red Hat 7 и 8.

Шаг 1. Установка PHP (Red Hat)

Чтобы установить PHP в Red Hat 7, выполните следующие команды:

Чтобы установить PHP 7.4 или 7.3, замените remi-php80 строкой remi-php74 или remi-php73 соответственно в следующих командах.

Чтобы установить PHP в Red Hat 8, выполните следующие команды:

Чтобы установить PHP 7.4 или 7.3, замените remi-8.0 на remi-7.4 или remi-7.3 соответственно в следующих командах.

Шаг 2. Установка необходимых компонентов (Red Hat)

Установите драйвер ODBC для Red Hat 7 или 8, следуя инструкциям в статье Установка Microsoft ODBC Driver for SQL Server (Linux). Также обязательно установите дополнительный пакет unixodbc-dev . Он используется командой pecl для установки драйверов PHP.

Шаг 3. Установка драйверов PHP для Microsoft SQL Server (Red Hat)

Можно также установить их из репозитория Remi:

Шаг 4. Установка Apache (Red Hat)

SELinux устанавливается по умолчанию и выполняется в принудительном режиме. Чтобы разрешить Apache подключаться к базам данных через SELinux, выполните следующую команду:

Шаг 5. Перезапуск Apache и тестирование примера скрипта (Red Hat)

Чтобы протестировать установку, воспользуйтесь разделом Тестирование установки в конце этого документа.

Установка в Debian

Поддерживаются версии Debian 9 и 10.

Чтобы установить PHP 7.4 или 7.3, замените 8.0 на 7.4 или 7.3 в следующих командах.

Шаг 1. Установка PHP (Debian)

Шаг 2. Установка необходимых компонентов (Debian)

Установите драйвер ODBC для Debian, следуя инструкциям в статье Установка Microsoft ODBC Driver for SQL Server (Linux). Также обязательно установите дополнительный пакет unixodbc-dev . Он используется командой pecl для установки драйверов PHP.

Кроме того, может потребоваться создать правильный языковой стандарт, чтобы выходные данные PHP правильно отображались в браузере. Например, для языкового стандарта en_US UTF-8 выполните следующие команды:

Может потребоваться добавить /usr/sbin в $PATH , так как там находится исполняемый файл locale-gen .

Шаг 3. Установка драйверов PHP для Microsoft SQL Server (Debian)

Если в системе только одна версия PHP, последний шаг можно упростить: phpenmod sqlsrv pdo_sqlsrv . Как и в случае с locale-gen , phpenmod находится в /usr/sbin , поэтому может потребоваться добавить этот каталог в $PATH .

Шаг 4. Установка Apache и настройка загрузки драйвера (Debian)

Шаг 5. Перезапуск Apache и тестирование примера скрипта (Debian)

Чтобы протестировать установку, воспользуйтесь разделом Тестирование установки в конце этого документа.

Установка в Suse

Поддерживаются версии Suse Enterprise Linux 12 и 15.

В следующих инструкциях замените на свою версию SUSE. Если вы используете SUSE Enterprise Linux 15, это будет SLE_15_SP1 или SLE_15_SP2. Для SUSE 12 используйте SLE_12_SP4 (или выше, если применимо). Не все версии PHP доступны для всех версий SUSE Linux. В http://download.opensuse.org/repositories/devel:/languages:/php указано, какие версии SUSE имеют доступную версию PHP по умолчанию, а в http://download.opensuse.org/repositories/devel:/languages:/php:/ — какие еще версии PHP доступны для разных версий SUSE.

Пакеты для PHP 7.4 или более поздней версии недоступны для SUSE 12, а пакет для PHP 8.0 пока не доступен для SUSE 15. Чтобы установить PHP 7.3, замените URL-адрес репозитория в команде ниже следующим URL-адресом: https://download.opensuse.org/repositories/devel:/languages:/php:/php73/ /devel:languages:php:php73.repo .

Шаг 1. Установка PHP (Suse)

Шаг 2. Установка необходимых компонентов (Suse)

Установите драйвер ODBC для SUSE, следуя инструкциям в статье Установка Microsoft ODBC Driver for SQL Server (Linux). Также обязательно установите дополнительный пакет unixodbc-dev . Он используется командой pecl для установки драйверов PHP.

Шаг 3. Установка драйверов PHP для Microsoft SQL Server (Suse)

Если вы получаете сообщение об ошибке вида Connection to ‘pecl.php.net:443’ failed: Unable to find the socket transport «ssl» , измените скрипт pecl в папке /usr/bin/pecl, удалив аргумент -n в последней строке. Этот аргумент запрещает PECL загружать ini-файлы при вызове PHP, что мешает загрузить расширение OpenSSL PECL.

Шаг 4. Установка Apache и настройка загрузки драйвера (Suse)

Шаг 5. Перезапуск Apache и тестирование примера скрипта (Suse)

Чтобы протестировать установку, воспользуйтесь разделом Тестирование установки в конце этого документа.

Установка в Alpine

Поддерживаются версии Alpine 3.11 и 3.12.

Версия PHP по умолчанию — 7.3. Версия PHP 7.4 или более поздняя может быть доступна в тестовых или пограничных репозиториях для Alpine. Вместо этого можно скомпилировать PHP из источника.

Шаг 1. Установка PHP (Alpine)

Пакеты PHP для Alpine находятся в репозитории edge/community . Проверьте раздел Включить репозиторий сообщества на их вики-странице. Добавьте следующую строку в /etc/apk/repositories , заменив на URL-адрес зеркального отображения репозитория Alpine:

Шаг 2. Установка необходимых компонентов (Alpine)

Установите драйвер ODBC для Alpine, следуя инструкциям в статье Установка Microsoft ODBC Driver for SQL Server (Linux). Также обязательно установите пакет unixodbc-dev ( sudo apk add unixodbc-dev ). Он используется командой pecl для установки драйверов PHP.

Шаг 3. Установка драйверов PHP для Microsoft SQL Server (Alpine)

Шаг 4. Установка Apache и настройка загрузки драйвера (Alpine)

Шаг 5. Перезапуск Apache и тестирование примера скрипта (Alpine)

Чтобы протестировать установку, воспользуйтесь разделом Тестирование установки в конце этого документа.

Установка в macOS

Поддерживаются версии MacOS 10.14 (Mojave), 10.15 (Catalina) и 11.0 (Big Sur).

Установите brew, как описано ниже, если у вас ее еще нет:

Чтобы установить PHP 7.4 или 7.3, замените php@8.0 на php@7.4 или php@7.3 соответственно в следующих командах.

Шаг 1. Установка PHP (macOS)

PHP теперь должен быть указан в пути. Запустите php -v и убедитесь, что используется правильная версия PHP. Если в пути нет PHP или есть PHP неправильной версии, выполните следующие команды:

Шаг 2. Установка необходимых компонентов (macOS)

Установите драйвер ODBC для macOS, следуя инструкциям в статье Установка Microsoft ODBC Driver for SQL Server (macOS).

Кроме того, может потребоваться установить средства make для GNU:

Шаг 3. Установка драйверов PHP для Microsoft SQL Server (macOS)

Шаг 4. Установка Apache и настройка загрузки драйвера (macOS)

Чтобы найти файл конфигурации Apache ( httpd.conf ) для установки Apache, выполните следующую команду:

Следующие команды добавляют необходимую конфигурацию в httpd.conf . Не забудьте указать путь, возвращенный предыдущей командой, вместо /usr/local/etc/httpd/httpd.conf :

Шаг 5. Перезапуск Apache и тестирование примера скрипта (macOS)

Чтобы протестировать установку, воспользуйтесь разделом Тестирование установки в конце этого документа.

Тестирование установки

Чтобы протестировать этот пример скрипта, создайте файл с именем testsql.php в корневом каталоге документов системы. Это путь /var/www/html/ в Ubuntu, Debian и Red Hat, /srv/www/htdocs в Suse, /var/www/localhost/htdocs в Alpine и /usr/local/var/www в macOS. Скопируйте приведенный ниже скрипт, заменив имя сервера, имя базы данных, имя пользователя и пароль правильными значениями.

Пример SQLSRV

Пример PDO_SQLSRV

Перейдите в браузере на страницу https://localhost/testsql.php ( https://localhost:8080/testsql.php в Mac OS). Теперь вы сможете подключиться к базе данных SQL Server или SQL Azure. Если вы не видите сообщение об успешном выполнении с информацией о версии SQL, выполните основные действия по устранению неполадок, запустив скрипт из командной строки:

Если выполнение из командной строки прошло успешно, но в браузере ничего не отображается, проверьте файлы журнала Apache. Если потребуется дополнительная поддержка, см. места, где можно найти необходимую информацию, в разделе Ресурсы поддержки.

См. также:

Getting Started with the Microsoft Drivers for PHP for SQL Server (Начало работы с драйверами Майкрософт для PHP для SQL Server)

Источник

Оцените статью