Why you should use nginx instead of apache for laragon.


  • | 559 points

    I am using Laragon with several local Laravel Apps. There are lots of API Reqeusts between those apps.

    Using Apache there is following problem:
    If App1 makes (within a normal browser triggered request) an http request to the API of App2, than App2 gets the Environment Variables of App1!

    (This is not a Laragon specific problem, it is a combination of Not Thread Safe Apache for Windows and the a Laragon component handling .env Variables )

    Solution 1)
    It is possible to set your Env Variables in your Apache vhost config eg
    </directory>

        #laravel hack 
        SetEnv DB_DATABASE xyz
    

    </VirtualHost>

    don't forget to remove the variables from your .env file

    Solution 2)
    Use Nginx as Webserver - if so don't forget to check that your usr/laragon.ini contains
    [nginx]
    Upstream=2 (or higher)

    as discused here https://forum.laragon.org/topic/1467/http-request-between-2-local-apps-deadlock-with-default-settings


  • | 436 points

    The problem with nginx, is that a lot of servers still use apache, and when I have to develop apps to use later in a real environment, i need my local .htaccess to work.

    There are solutions out there that have a stack of nginx with apache to run nginx and still honor the .htaccess file, but I dont know how to do this with laragon.

    With this i just want to say that sometimes the option to use nginx is simply not there.


  • | 559 points

    For your local Development Environment:
    As mentioned above you can set your Laravel ENV variables in your Apache Vhost instead:

    <Vhost>
    ...
    SetEnv DB_DATABASE xyz
    SetEnv DB_NAME testdatabase
    ...

    and remove those Variables from your local Laravel .env file

    This way the problem with mixed up environment Variables does not occur on windows based Apache Servers.


  • administrators
    | 108154 points

    @peterreb : Did you test with PHP NTS (Non Thread Safe)?
    When using PHP NTS, Laragon will use Apache mod_cgi instead.


Log in to reply
 

Looks like your connection to Laragon was lost, please wait while we try to reconnect.