Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cristian9509's avatar

Configure a route to point to a php url like "/in.php"

I have a server that receives data from a popular service and for which the initial route was just a plain php file myserver.com/in.php. I moved the entire app to a Lumen app and now I am forced to setup either a file in public/in.php or create a route /in.php. I want to create a route to /in.php but I am struggling to do with in Nginx. The only thing I was able to do was a rewrite that creates a permanent 301 and changes the route from /in.php to a route in lumen /in. However I don't know how the service handles redirects and I am still trying to find a way to declare in lumen a route that ends in .php.

Anyone has an idea how to achieve this?

Btw, I am currently using homestead with the default Nginx configuration.

0 likes
7 replies
burlresearch's avatar

There are couple ways you could do this.

  1. Certainly you could massage nginx server config a little and have it serve any PHP file in the /public directory, first, if it exists, before invoking the default 'index.php' which then bootstraps Lumen. Let me know if that's what you think you need, I could probably help with that, but

  2. You can define any routes you want in the router. So, if you want, why not, in routes/web.php simply create the route:

$router->get('in.php', function () {
    // invoke a controller method
    // or whatever you want...
    return 'in.php';
});
cristian9509's avatar

@burlresearch i want to implement option #2. I've tried it like that already and it does not work. It tries to find the file in public and if the file is not there it fails.

burlresearch's avatar

The route will work like that. Sounds like your problem is something else. Possibly you're having trouble generating the response?

The only public file need be: /public/index.php

Robstar's avatar

For option #2 have you tried without the physical PHP file in the public dir? I believe option #2 will only work if /public/in.php does not exist. Latter assumes you are using an unmodified Lumen .htaccess file.

In situations where I have a legacy url I'd prefer to migrate it into Lumen.

burlresearch's avatar

True ... this may depend on what you have in your webserver config. Either

  1. do as @Robstar suggests and put the actual 'in.php' in your public/ directory
  2. post your nginx.conf from homestead so we can have a look
cristian9509's avatar

I don't have the "in.php" file in the public folder, just the "index.php". I have configured the route like $router->post("/in.php", "IncomingController@in").

Nginx looks like this for locations which matters. I don't use rewrites in it right now, it's just the default homestead generated conf.

location / {
        try_files $uri $uri/ /index.php$query_args;
    }

...
location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        fastcgi_pass unix:/var/run/php7-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }
burlresearch's avatar

I was using Laravel Valet on my Mac when I tried that $router->get('in.php',... and it worked OK, but that isn't using the same NGINX config as above (I assume).

Later I tried it on my native linux box, and it did not work - and that's with NGINX configured as yours above.

But, if you simply move the 'in.php' to your public/ folder, it will be run as expected and rendered as a normal PHP page (though obviously not bootstrapping Laravel/Lumen).

Please or to participate in this conversation.