Steps to install PHP and configure MSSQL connection in Ubuntu system

WBOY
Release: 2024-02-29 13:10:01
Original
1131 people have browsed it

Steps to install PHP and configure MSSQL connection in Ubuntu system

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

  1. Open the terminal and update the system package list:

    sudo apt-get update
    Copy after login
  2. Install PHP and related extensions :

    sudo apt-get install php php-mysql php-xml php-mbstring
    Copy after login
  3. Verify whether the PHP installation is successful:

    php -v
    Copy after login
  4. Install the PHP development kit:

    sudo apt-get install php-dev
    Copy after login

Step 2: Install the FreeTDS library

  1. Install the FreeTDS library to establish a connection with MSSQL:

    sudo apt-get install freetds-dev freetds-bin tdsodbc
    Copy after login
  2. Configure FreeTDS:
    Open the FreeTDS configuration file:

    sudo nano /etc/freetds/freetds.conf
    Copy after login

    Add MSSQL configuration at the end of the file:

    [MSSQL]
     host = your_mssql_host
     port = 1433
     tds version = 8.0
    Copy after login
  3. Configure ODBC:
    Open the ODBC configuration file:

    sudo nano /etc/odbc.ini
    Copy after login

    Add MSSQL configuration:

    [MSSQL]
     Driver = FreeTDS
     Description = MSSQL Server
     Servername = MSSQL
     Database = your_database_name
     Port = 1433
     TDS_Version = 8.0
    Copy after login

Step 3: Install PDO_ODBC extension

  1. Install PDO_ODBC extension:

    sudo apt-get install php-pdo-odbc
    Copy after login
  2. Edit the PHP configuration file and enable the PDO_ODBC extension:

    sudo nano /etc/php/7.x/apache2/php.ini
    Copy after login

    Add the following content in the file:

    extension=pdo_odbc
    Copy after login
  3. Restart the Apache service:

    sudo systemctl restart apache2
    Copy after login

Step 4: Test MSSQL connection

  1. 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.';
    }
    ?>
    Copy after login
  2. Access the test-mssql.php file in the browser to check whether it is successfully connected to the MSSQL database.

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!