7. PHP Tutorial - IIS Server

PHP Tutorial – IIS Server

()

What is IIS Server?

Internet Information Services (IIS) is a web server software package developed by Microsoft for use with the Microsoft Windows operating system. IIS is used to host websites and other content on the web. It can be used to host websites, web applications, and web services. It supports HTTP, HTTPS, FTP, FTPS, SMTP, and NNTP protocols. You can use IIS to manage and configure your web server, create and manage websites and web applications, and handle requests from users over the internet.

IIS Server Setup:

To set up an IIS (Internet Information Services) server, you will need to follow these steps:

  1. Install IIS: To install IIS, you will need a computer running the Windows operating system (such as Windows 10, Windows 8, or Windows 7). IIS is not available on other operating systems. To install IIS, you can follow these steps:
    • Open the “Control Panel” on your computer.
    • In the “Control Panel“, click on “Programs and Features“.
    • In the “Programs and Features” window, click on “Turn Windows features on or off“.
    • In the “Windows Features” dialog, scroll down and check the box next to “Internet Information Services“.
    • Click “OK” to install IIS.
  2. Configure IIS: Once IIS is installed, you will need to configure it to host your websites, web applications, and web services. You can use the IIS Manager to configure IIS. To open the IIS Manager, you can follow these steps:
    • Open the “Control Panel” on your computer.
    • In the “Control Panel“, click on “Administrative Tools“.
    • In the “Administrative Tools” window, click on “Internet Information Services (IIS) Manager“.

The IIS Manager is a graphical user interface that you can use to manage and configure your IIS server. You can use it to create and manage websites, web applications, and web services, and to configure various settings such as authentication, security, and performance.

  1. Create and host a website: To create and host a website on IIS, you can follow these steps:
    • Open the IIS Manager.
    • In the IIS Manager, click on the server’s name and then click on the “Sites” icon.
    • In the “Actions” pane on the right, click on “Add Website“.
    • In the “Add Website” dialog, enter the following information:
    • Site name: (enter a name for your website)
    • Physical path: (browse to the folder on your computer where you want to store your website files)
    • Binding: (select the binding type and port number for your website)
    • Click “OK” to create the website.

Once you have created the website, you can add web pages and other content to the website and then access the website from a web browser using the URL specified in the binding.

You have now set up an IIS server and created and hosted a website on it. You can now use IIS to manage and host your websites, web applications, and web services.

PHP run in IIS Server:

PHP can be run on IIS (Internet Information Services) server. In order to run PHP on IIS, you will need to install PHP and configure IIS to use PHP. Here are the steps you can follow to install and configure PHP on IIS:

  1. Download and install PHP from the official PHP website (https://www.php.net/downloads.php). Make sure to download the version of PHP that is compatible with your version of IIS.
  2. Once PHP is installed, open the IIS Manager.
  3. In the IIS Manager, click on the server’s name and then click on the “Handler Mappings” icon.
  4. In the “Actions” pane on the right, click on “Add Module Mapping“.
  5. In the “Add Module Mapping” dialog, enter the following information:
    • Request path: *.php
    • Module: FastCgiModule
    • Executable: (browse to the location of the PHP executable file, typically C:\PHP\php-cgi.exe)
    • Name: PHP via FastCGI
  6. Click “OK” to save the module mapping.
  7. In the IIS Manager, click on the server’s name and then click on the “FastCGI Settings” icon.
  8. In the “Actions” pane on the right, click on “Add Application”.
  9. In the “Add Application” dialog, enter the following information:
    • Full path: (browse to the location of the PHP executable file, typically C:\PHP\php-cgi.exe)
    • Arguments: (leave this field blank)
    • Name: PHP via FastCGI
  10. Click “OK” to save the FastCGI application.

You have now installed and configured PHP on IIS. You can now create PHP web applications and host them on your IIS server.

Which Database is used in IIS Server?

IIS (Internet Information Services) is a web server software package and does not come with a database. It is typically used to host websites, web applications, and web services, and can be used with a variety of databases.

Some common databases that can be used with IIS include:

  • Microsoft SQL Server: A powerful and feature-rich relational database management system (RDBMS) developed by Microsoft.
  • MySQL: A popular open-source RDBMS that is widely used for web applications.
  • Oracle: An enterprise-class RDBMS developed by Oracle Corporation.
  • PostgreSQL: An open-source object-relational database management system (ORDBMS).
  • MariaDB: A fork of the MySQL database that is developed and maintained by the MariaDB Foundation.

You can choose the database that best meets the needs of your web application and use it with IIS to store and retrieve data.

How can we use Microsoft SQL Server in IIS for PHP?

To use Microsoft SQL Server with PHP on IIS, you will need to follow these steps:

  1. Download and install Microsoft SQL Server on your IIS server. You can download Microsoft SQL Server from the Microsoft website (https://www.microsoft.com/sql-server/).
  2. Download and install the Microsoft Drivers for PHP for SQL Server. The Microsoft Drivers for PHP for SQL Server provide connectivity to Microsoft SQL Server from PHP applications. You can download the Microsoft Drivers for PHP for SQL Server from the Microsoft website (https://www.microsoft.com/sql-server/developer-get-started/php/).
  3. Configure the PHP runtime on IIS to use the Microsoft Drivers for PHP for SQL Server. To do this, you will need to add the following line to your PHP configuration file (php.ini):
extension=php_sqlsrv.dll
  1. Restart the IIS server for the changes to take effect.
  2. Connect to Microsoft SQL Server from PHP. To connect to Microsoft SQL Server from PHP, you can use the sqlsrv_connect() function. Here is an example of how to use sqlsrv_connect() to connect to a Microsoft SQL Server database:
$serverName = "serverName\instanceName"; 
$connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password"); 
$conn = sqlsrv_connect( $serverName, $connectionInfo);

If the connection is successful, $conn will be a resource that represents the connection to the database. You can then use this resource to execute queries and perform other database operations.

You have now configured IIS to use Microsoft SQL Server with PHP. You can now create PHP applications that connect to and query Microsoft SQL Server databases.

How can we use Maria DB & MySQL Database in IIS for PHP?

To use MariaDB or MySQL with PHP on IIS, you will need to follow these steps:

  1. Download and install MariaDB or MySQL on your IIS server. You can download MariaDB from the MariaDB website (https://mariadb.org/) and MySQL from the MySQL website (https://www.mysql.com/).
  2. Download and install the PHP MySQL library (mysqlnd). The PHP MySQL library (mysqlnd) is a driver that provides connectivity to MySQL from PHP. It is included with PHP by default, so you should not need to install it separately.
  3. Configure the PHP runtime on IIS to use the PHP MySQL library (mysqlnd). To do this, you will need to add the following line to your PHP configuration file (php.ini):
extension=mysqlnd
  1. Restart the IIS server for the changes to take effect.
  2. Connect to MariaDB or MySQL from PHP. To connect to MariaDB or MySQL from PHP, you can use the mysqli_connect() function. Here is an example of how-to user mysqli_connect() to connect to a MariaDB or MySQL database:
$link = mysqli_connect("hostname", "username", "password", "database_name");

If the connection is successful, $link will be a resource that represents the connection to the database. You can then use this resource to execute queries and perform other database operations.

You have now configured IIS to use MariaDB or MySQL with PHP. You can now create PHP applications that connect to and query MariaDB or MySQL databases.

Check version PHP in IIS:

There are a few different ways you can check the version of PHP that is installed and being used by IIS (Internet Information Services):

  1. Check the PHP runtime version:
  • Open the IIS Manager.
  • In the IIS Manager, click on the server’s name and then click on the “PHP Manager” icon.
  • In the “PHP Manager” window, click on the “PHP runtime” icon.
  • The version of PHP that is currently being used by IIS will be displayed in the “PHP Version” section.
  1. Check the PHP version in the PHP configuration file:
  • Open the PHP configuration file (php.ini) in a text editor.
  • The version of PHP is specified in the “phpversion” setting in the configuration file.
  1. Check the PHP version from PHP code:
  • Create a new PHP file (e.g. version.php) and add the following code to it:
<?php echo "PHP version: " . PHP_VERSION . "\n"; ?>
  • Save the file and place it in the root folder of your PHP website on IIS.
  • Access the file from a web browser (e.g., http://localhost/version.php).
  • The version of PHP that is being used by IIS will be displayed in the browser.

You have now checked the version of PHP that is installed and being used by IIS.

Start & Stop services of IIS & PHP:

To start or stop services for IIS (Internet Information Services) and PHP, you will need to use the Services Manager. The Services Manager is a tool that you can use to manage and control the various services that are running on your computer. Here is how you can start or stop services for IIS and PHP using the Services Manager:

  1. Open the Services Manager. To open the Services Manager, you can follow these steps:
    • Press the “Windows” key and the “R” key on your keyboard at the same time to open the “Run” dialog.
    • In the “Run” dialog, type “services.msc” and press “Enter“.
  2. In the Services Manager, look for the following services:
    • IIS Admin Service: This service is responsible for managing the IIS server.
    • World Wide Web Publishing Service: This service is responsible for hosting websites and web applications on IIS.
    • PHP FastCGI Process Manager: This service is responsible for managing the PHP FastCGI process on IIS.
  3. To start a service, right-click on the service and click on “Start“. To stop a service, right-click on the service and click on “Stop“.

That’s it! You have now started or stopped services for IIS and PHP using the Services Manager. You can use this tool to manage and control the services that are running on your computer.

Some Advanced Steps in IIS Server for PHP:

Here are some advanced steps you can take to further configure and optimize your IIS server for PHP:

  1. Enable output buffering: Output buffering can help improve the performance of your PHP applications by reducing the number of times that the PHP runtime needs to write to the output stream. To enable output buffering in PHP, you will need to add the following line to your PHP configuration file (php.ini):
output_buffering = On
  1. Enable Gzip compression: Gzip compression can help reduce the size of the data that is transferred between the server and the client, which can improve the performance of your PHP applications. To enable Gzip compression in IIS, you will need to follow these steps:
    • Open the IIS Manager.
    • In the IIS Manager, click on the server’s name and then click on the “Compression” icon.
    • In the “Compression” window, click on “Edit Feature Settings” in the “Actions” pane on the right.
    • In the “Edit Feature Settings” dialog, check the boxes next to “Dynamic content” and “Static content” and click “OK”.
  2. Enable caching: Caching can help improve the performance of your PHP applications by storing frequently accessed data in memory, reducing the need to retrieve the data from a database or other storage location. To enable caching in IIS, you will need to follow these steps:
    • Open the IIS Manager.
    • In the IIS Manager, click on the server name and then click on the “Output Caching” icon.
    • In the “Output Caching” window, click on “Edit Feature Settings” in the “Actions” pane on the right.
    • In the “Edit Feature Settings” dialog, check the boxes next to “Dynamic content” and “Static content” and click “OK”.
  3. Configure FastCGI settings: FastCGI is a protocol that is used to execute PHP scripts on IIS. You can configure various FastCGI settings to optimize the performance of your PHP applications. To configure FastCGI settings in IIS, you will need to follow these steps:
    • Open the IIS Manager.
    • In the IIS Manager, click on the server name and then click on the “FastCGI Settings” icon.
    • In the “FastCGI Settings” window, click on the PHP FastCGI application and then click on “Edit” in the “Actions” pane on the right.
    • In the “Edit FastCGI Application” dialog, you can configure various FastCGI settings such as the number of worker processes, the request timeout, and the activity timeout.

These are some advanced steps you can take to further configure and optimize your IIS server for PHP.

PROS & CONS of IIS Server & IIS Server with PHP:

Here are some pros and cons of using IIS (Internet Information Services) and IIS with PHP:

Pros of IIS:

  • Easy to install and use: IIS is easy to install and use, even for users who are not familiar with web servers.
  • Secure: IIS includes various security features such as SSL/TLS support, request filtering, and IP and domain restrictions.
  • Scalable: IIS can be scaled up to handle large amounts of traffic and data.
  • Integrated with other Microsoft products: IIS is integrated with other Microsoft products such as Windows, .NET, and Visual Studio, making it easy to develop and deploy web applications on the platform.

Cons of IIS:

  • Only available on Windows: IIS is only available on the Windows operating system, so it is not an option for users who are running other operating systems.
  • Limited support for non-Microsoft technologies: IIS may not provide as much support for non-Microsoft technologies such as PHP, Ruby, or Python as other web servers.
  • May be more expensive: Depending on the version of Windows you are using; IIS may be more expensive to use than other web servers.

Pros of IIS with PHP:

  • Easy to deploy PHP applications: IIS makes it easy to deploy PHP applications, with built-in support for PHP and tools such as the PHP Manager.
  • High performance: IIS with PHP can provide high performance for PHP applications, especially when used with FastCGI and other performance-enhancing features.
  • Good security: IIS with PHP can provide good security for PHP applications; with features such as request filtering and SSL/TLS support.

Cons of IIS with PHP:

  • Limited support for older versions of PHP: IIS may not provide support for older versions of PHP, so you may need to upgrade your PHP version to use IIS.
  • May require additional configuration: IIS with PHP may require additional configuration to work properly, such as setting up FastCGI or installing the PHP MySQL library.
  • May not be as flexible as other web servers: IIS with PHP may not be as flexible as other web servers such as Apache, which can support a wider range of technologies and configurations.

Conclusion on IIS Server & IIS Server with PHP:

In conclusion, IIS (Internet Information Services) is a powerful and feature-rich web server that is easy to install and use. It is well-suited for hosting websites, web applications, and web services on the Windows operating system. IIS is also integrated with other Microsoft products, making it easy to develop and deploy web applications on the platform.

IIS with PHP can provide high performance for PHP applications, with built-in support for PHP and tools such as the PHP Manager. However, it may require additional configuration and may not be as flexible as other web servers.

Overall, IIS is a good choice for users who are looking to host web applications on the Windows operating system, especially if they are using PHP or other Microsoft technologies. However, it may not be the best choice for users who are looking for more flexibility or support for non-Microsoft technologies.

How useful was this post?

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

About the author

Hello,
I'm a Web Developer
My name is Muslim Ahmad. I have experience in developing a real-time web application, complex front-end and back-end management systems, I have worked on mostly mathematical & scientific solution applications and experience in crypto-currencies exchange wallets development. All my projects based on PHP in conjunction with other modern web technologies.