The steps to install PHP and configure MSSQL connection in Ubuntu system require specific code examples
Ubuntu is a popular Linux operating system that provides a powerful The development environment is conducive to building web applications. Installing PHP and configuring MSSQL connections in Ubuntu systems is one of the important skills that many developers need to master. This article will introduce how to install PHP in the Ubuntu system and configure the steps for MSSQL connection, including specific code examples.
Step 1: Install PHP
Open the terminal and update the system package list:
sudo apt-get update
Install PHP and related extensions :
sudo apt-get install php php-mysql php-xml php-mbstring
Verify whether the PHP installation is successful:
php -v
Install the PHP development kit:
sudo apt-get install php-dev
Step 2: Install the FreeTDS library
Install the FreeTDS library to establish a connection with MSSQL:
sudo apt-get install freetds-dev freetds-bin tdsodbc
Configure FreeTDS:
Open the FreeTDS configuration file:
sudo nano /etc/freetds/freetds.conf
Add MSSQL configuration at the end of the file:
[MSSQL] host = your_mssql_host port = 1433 tds version = 8.0
Configure ODBC:
Open the ODBC configuration file:
sudo nano /etc/odbc.ini
Add MSSQL configuration:
[MSSQL] Driver = FreeTDS Description = MSSQL Server Servername = MSSQL Database = your_database_name Port = 1433 TDS_Version = 8.0
Step 3: Install PDO_ODBC extension
Install PDO_ODBC extension:
sudo apt-get install php-pdo-odbc
Edit the PHP configuration file and enable the PDO_ODBC extension:
sudo nano /etc/php/7.x/apache2/php.ini
Add the following content in the file:
extension=pdo_odbc
Restart the Apache service:
sudo systemctl restart apache2
Step 4: Test MSSQL connection
Create a PHP file for testing MSSQL connection, such as test-mssql.php:
<?php $server = 'MSSQL'; $database = 'your_database_name'; $username = 'your_username'; $password = 'your_password'; $conn = new PDO("odbc:Driver=FreeTDS;Server=$server;Database=$database;", $username, $password); if ($conn) { echo 'Connected to MSSQL successfully.'; } else { echo 'Failed to connect to MSSQL.'; } ?>
Summary
Through the above steps, we successfully installed PHP in the Ubuntu system and configured the MSSQL connection. During the development process, make sure to follow the above steps one by one and adjust the configuration file according to the specific situation. In this way, you can successfully develop PHP in the Ubuntu system and connect to the MSSQL database.
The above is the detailed content of Steps to install PHP and configure MSSQL connection in Ubuntu system. For more information, please follow other related articles on the PHP Chinese website!