NGINX Unit
v. 1.22.0

Laravel§

To run apps based on the Laravel framework using Unit:

  1. Install Unit with a PHP language module.

  2. Install and configure Laravel’s prerequisites.

  3. Install Laravel’s core files.

  4. Create a Laravel project. For our purposes, the path is /path/to/app/:

    $ cd /path/to/app/
    $ laravel new blog
    
  5. Run the following command for each directory containing app code or data so Unit can access it:

    # chown -R unit:unit /path/to/app/
    

    Note

    The unit:unit user-group pair is available only with official packages, Docker images, and some third-party repos. Otherwise, account names may differ; run the ps aux | grep unitd command to be sure.

    For further details, including permissions, see the security checklist.

    Note

    See the Laravel docs for further details on server configuration and directory structure.

  6. Next, prepare the Laravel configuration for Unit:

    {
        "listeners": {
            "*:80": {
                "pass": "routes/laravel"
            }
        },
    
        "routes": {
            "laravel": [
                {
                    "match": {
                        "uri": "!/index.php"
                    },
                    "action": {
                        "share": "/path/to/app/blog/public/",
                        "fallback": {
                            "pass": "applications/laravel"
                        }
                    }
                }
            ]
        },
    
        "applications": {
            "laravel": {
                "type": "php",
                "root": "/path/to/app/blog/public/",
                "script": "index.php"
            }
        }
    }
    
  7. Upload the updated configuration. Assuming the JSON above was added to config.json:

    # curl -X PUT --data-binary @config.json --unix-socket \
           /path/to/control.unit.sock http://localhost/config/
    

    Note

    The control socket path may vary; run unitd --help or see Startup and Shutdown for details.

    After a successful update, browse to http://localhost and set up your Laravel application:

Laravel on Unit - Sample Screen