Welcome Guest, Not a member yet? Register   Sign In
Installation & Setup on Windows IIS
#1

(This post was last modified: 03-19-2025, 01:21 PM by wolverine4277.)

First of all, if the topic should go in another subforum feel free to move it.
After a long time trying to run an application developed with CodeIgniter4 on a server with IIS and due to some difficulties I decided to write this kind of tutorial.
On Apache in a local environment the applications work immediately, but when making the move to IIS is not so easy (or at least that's what happened to me).
Everything I am going to describe is in addition to what is indicated in the Getting started guide.

We will need:
  • Enable the mod_rewrite extension
  • Import the .htaccess file of the project to generate a web.config file like this:
    PHP Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="Regla 1 importada" stopProcessing="true">
                        <match url="^(.*)$" ignoreCase="false" />
                        <action type="Rewrite" url="public/{R:1}" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration> 

  • Import the .htaccess file of the public folder to generate a web.config file like this:
    PHP Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="Regla 1 importada-1" stopProcessing="true">
                        <match url="^" ignoreCase="false" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                            <add input="{URL}" pattern="(.+)/$" ignoreCase="false" />
                        </conditions>
                        <action type="Redirect" url="{C:1}" redirectType="Permanent" />
                    </rule>
                    <rule name="Regla 2 importada" stopProcessing="true">
                        <match url="^" ignoreCase="false" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{HTTPS}" pattern="^on$" ignoreCase="false" negate="true" />
                            <add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
                        </conditions>
                        <action type="Redirect" url="http://{C:1}{URL}" redirectType="Permanent" />
                    </rule>
                    <rule name="Regla 3 importada" stopProcessing="true">
                        <match url="^([\s\S]*)$" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration> 

  • Create a virtual directory pointing to the public folder of the project (for example, if the project is located in c:\inetpub\wwwroot\myproject then we must add the virtual directory myproject pointing to c:\inetpub\wwwroot\myproject\public)
    To do this we select the folder above the project folder, right click on the folder and select the option Add virtual directory and configure an alias (myproject) and the physical path c:\inetpub\wwwroot\myproject\public.
  • Configure the HTTP verbs that we are going to use since not all are enabled by default (PUT is not enabled by default and when testing it threw me error 500, without recording in any error log the reason).
    To do this we select the project folder, double click on Handler mappings, double click on the PHP version we are using, then click on the Request Restrictions button
  • In the verbs tab we select the option All verbs or we select the option One of the following verbs and separate them with comma (for example: GET, PUT).

I hope it helps you, it would have saved me a lot of time to know all this when uploading my application to a Windows server.
Regards.


Luego de un buen tiempo intentando hacer funcionar un aplicación desarrollada con CodeIgniter4 sobre un servidor con IIS y debido a algunas dificultades que se me presentaron, me decidí a escribir esta especie de tutorial.
Sobre Apache en un entorno local las aplicaciones funcionan inmediatamente, pero al hacer el pase a IIS no es tan sencillo (o por lo menos es lo que me ha sucedido a mi).
Todo lo que voy a describir es adicional a lo indicado en la guía Como empezar.

Vamos a necesitar:
  • Habilitar la extensión mod_rewrite
  • Importar el archivo .htaccess del proyecto para generar un archivo web.config similar a este:
    PHP Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="Regla 1 importada" stopProcessing="true">
                        <match url="^(.*)$" ignoreCase="false" />
                        <action type="Rewrite" url="public/{R:1}" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration> 

  • Importar el archivo .htaccess de la carpeta public para generar un archivo web.config similar a este:
    PHP Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="Regla 1 importada-1" stopProcessing="true">
                        <match url="^" ignoreCase="false" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                            <add input="{URL}" pattern="(.+)/$" ignoreCase="false" />
                        </conditions>
                        <action type="Redirect" url="{C:1}" redirectType="Permanent" />
                    </rule>
                    <rule name="Regla 2 importada" stopProcessing="true">
                        <match url="^" ignoreCase="false" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{HTTPS}" pattern="^on$" ignoreCase="false" negate="true" />
                            <add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
                        </conditions>
                        <action type="Redirect" url="http://{C:1}{URL}" redirectType="Permanent" />
                    </rule>
                    <rule name="Regla 3 importada" stopProcessing="true">
                        <match url="^([\s\S]*)$" />
                        <conditions logicalGrouping="MatchAll">
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration> 

  • Crear un directorio virtual apuntando a la carpeta public del proyecto (por ejemplo, si el proyecto se encuentra en c:\inetpub\wwwroot\myproject\ entonces debemos agregar el directorio virtual myproject apuntando a c:\inetpub\myproject\public).
    Para esto seleccionamos la carpeta superior a la del proyecto, hacemos clic con el botón derecho sobre la carpeta y seleccionamos la opción Agregar directorio virtual y configuramos un alias (myproject) y la ruta de acceso física c:\inetpub\wwwroot\myproject\public
  • Configurar los verbos HTTP que vamos a utilizar ya que no todos están habilitados por defecto (PUT no está habilitado por defecto y al hacer pruebas me arrojaba error 500, sin grabar en ningún log de errores el motivo).
    Para esto seleccionamos la carpeta del proyecto, hacemos doble clic en asignaciones del controlador, hacemos doble clic en la versión de PHP que estamos utilizando, luego clic en el botón Restricciones de solicitudes
  • En la pestaña verbos seleccionamos la opción Todos los verbos o seleccionamos la opción Uno de los siguientes verbos y los separamos con coma (por ejemplo: GET, PUT).

Espero les ayude, a mi me habría ahorrado un buen tiempo saber todo esto a la hora de subir mi aplicación a un servidor Windows.
Saludos.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB