Uncategorized
Setting Up PHP Laravel on Windows Server with IIS
Deploying a PHP Laravel application on a Windows Server with IIS involves several steps to ensure the web server handles PHP requests correctly. Here’s a step-by-step guide to get you started with setting up PHP and Laravel on IIS. Step 1: Download PHP for Windows First, download the latest…
Deploying a PHP Laravel application on a Windows Server with IIS involves several steps to ensure the web server handles PHP requests correctly.
Here’s a step-by-step guide to get you started with setting up PHP and Laravel on IIS.
Step 1: Download PHP for Windows
First, download the latest version of PHP for Windows from the official PHP website .
Choose the “Non-thread-safe” version for better compatibility with IIS FastCGI.
Step 2: Install PHP on the Server
- Extract the downloaded PHP files to a directory, for example,
C:PHP. - Add
C:PHPto your system’s Environment Variables to make PHP globally accessible: — Right-click on This PC and select Properties. — Click Advanced system settings → Environment Variables. — Under System Variables, find Path, click Edit, and add the PHP directory path (C:PHP). - Open Command Prompt and type
php -vto verify that PHP is installed and properly configured.
Step 3: Configure IIS for PHP
- Open IIS Manager
- Create a new site (do not set it up as a sub-application): — Select **Sites **in the left pane and click Add Website. — Point the Physical path to your Laravel application’s folder. — Assign a domain (or use localhost for testing purposes).
Step 4: Install FastCGI for IIS
PHP works with IIS through the FastCGI module, so you need to ensure it’s installed:
- Open Server Manager → Add Roles and Features.
- In the Features section, make sure **CGI **is installed. If it isn’t, check the box and install it.
Step 5: Set Up Handler Mapping for PHP in IIS
- In IIS Manager, select the site you just created.
- Under Handler Mappings, click** Add Module Mapping **.
- Fill in the form as follows:
— Request path:
*.php— Module: FastCGI Module — Executable: Path tophp-cgi.exe(e.g.,C:PHPphp-cgi.exe) — Name:PHP_FastCGI - Click OK, then confirm if prompted.
Step 6: Install IIS Rewrite and CORS Modules
To ensure your Laravel app functions correctly with URL rewriting and CORS, you need to install the** IIS Rewrite** and **CORS **modules: – Download and install the URL Rewrite module and CORS module
Step 7: Configure php.ini
- Locate the
php.inifile in yourC:PHPfolder. - Modify the following settings to optimize PHP in your php.ini file
max_execution_time = 90 max_input_time = 90 memory_limit = 4028M post_max_size = 64M
- Ensure the following extensions are enabled by uncommenting them or adding them if missing:
extension=curl extension=fileinfo extension=mbstring extension=openssl extension=php_gd.dll extension=D:PHPextphp_mysqli.dll extension=php_sqlsrv_81_nts_x64.dll extension=php_pdo_sqlsrv_81_nts_x64.dll
Note: If you’re using a different version of PHP, replace 81 in the SQL Server drivers with your version number (e.g., 82).
Step 8: Install PHP SQL Server Drivers
Download the appropriate version of the PHP SQL Server drivers from this link for your PHP version (e.g., php_sqlsrv_82_nts_x64.dll for PHP 8.2).
2. Copy the downloaded .dll files to the ext folder inside C:PHP.
3. In php.ini, ensure the SQLSRV and PDO_SQLSRV extensions are enabled:
extension=php_sqlsrv_81_nts_x64.dll extension=php_pdo_sqlsrv_81_nts_x64.dll
Step 9: Restart IIS
After all configurations, restart IIS to apply the changes: – Open Command Prompt as Administrator and run:
iisreset
Step 10: Test the Laravel Application
- Navigate to the URL (or localhost) where the application is hosted.
- If everything is set up correctly, you should see your Laravel application’s homepage.
Conclusion
By following these steps, you can successfully set up PHP Laravel on a Windows Server with IIS. This setup ensures that Laravel runs efficiently with proper PHP, SQL Server drivers, and IIS FastCGI support. Don’t forget to enable necessary PHP extensions and tweak the php.ini file to match your application’s requirements.
