Creating a new Laravel project using Apache for host in WSL

Hello. I have a problem. I created WSL distro with NixOS inside. Now i trying to host project, but get 403 Forbidden error even when using 127.0.0.1.
What i did:

  1. Apache had a problem with “DocumentRoot doesnt exist”. I found solution
systemd.services.httpd.serviceConfig.User = lib.mkForce "root";

It helped, warning disappeared.
2) I looked up in httpd.conf file created and i found, that is create with AllowOverride None
So i replaced it with the full virtual host description in extraConfig option

Listen 127.0.0.1:8000 http
<VirtualHost 127.0.0.1:8000>
  DocumentRoot "/home/nixos/Documents/Laravel-pet-1/public"
  ServerName laravelPet1
  <Directory "/home/nixos/Documents/Laravel-pet-1/public">
    AllowOverride All
    Allow from all
    Require all granted
  </Directory>
</VirtualHost>

Also there is firewall settings:

enable = true;
allowedTCPPorts = [ 8000 ];
  1. Just in case checked the apache version, just so i using the directives correctly, my version is 2.4.62

  2. Also checked the htaccess file in the “public” directory. Found only rewrite rules.

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
  1. Changed my config. Now im using nixos user and only one directive, still doesn’t work
 services.httpd.user = "nixos";
  services.httpd.group = "users";
  services.httpd.logDir = "/home/nixos/httpd_logs";
 # systemd.services.httpd.serviceConfig.User = lib.mkForce "root";
 services.httpd.extraConfig =
  ''
  Listen 127.0.0.1:8000 http
  <VirtualHost 127.0.0.1:8000>
    DocumentRoot "/home/nixos/Documents/Laravel-pet-1/public"
    ServerName laravelPet1
    <Directory "/home/nixos/Documents/Laravel-pet-1/public">
      Require all granted
    </Directory>
  </VirtualHost>
  '';

But its all not working, when i trying to use wget on this address i got this:

wget 127.0.0.1:8000
Prepended http:// to '127.0.0.1:8000'
--2025-03-30 19:03:03--  http://127.0.0.1:8000/
Connecting to 127.0.0.1:8000... connected.
HTTP request sent, awaiting response... 403 Forbidden
2025-03-30 19:03:03 ERROR 403: Forbidden.

I’m not familiar with Apache, but this Require all granted seems sus: it feels like it’s used to authenticate users using a password (e.g with some htpasswd file).

Hello, i saw this in this documentation after this quote to the bottom you can find an example.
Access Control - Apache HTTP Server Version 2.4

The Require provides a variety of different ways to allow or deny access to resources. In conjunction with the RequireAll , RequireAny , and RequireNone directives, these requirements may be combined in arbitrarily complex ways, to enforce whatever your access policy happens to be.

It also says that Allow is deprecated, it feels like you wanna allow access from everywhere, then you can remove everything you have in the <Directory> block, and have something like DirectoryIndex index.html instead?

The default settings deny everything and the virtual hosts allow what they needed. i tried to remove Allow directives, run into the access denied to log directory, so i changed the config.

 services.httpd.user = "nixos";
  services.httpd.group = "users";
  services.httpd.logDir = "/home/nixos/httpd_logs";
 # systemd.services.httpd.serviceConfig.User = lib.mkForce "root";
 services.httpd.extraConfig =
  ''
  Listen 127.0.0.1:8000 http
  <VirtualHost 127.0.0.1:8000>
    DocumentRoot "/home/nixos/Documents/Laravel-pet-1/public"
    ServerName laravelPet1
    <Directory "/home/nixos/Documents/Laravel-pet-1/public">
      Require all granted
    </Directory>
  </VirtualHost>
  '';

So now i theory, the server is running inder the main user, so it will be no problem with file access, but i still have error 403, wich is sad

FWIW I asked some llm, and assuming the server has the permissions to access the files, if there is no index to serve then you’ll get a 403, directory listing can be enabled with Options +Indexes within the directory block.

Unfortunately i have index.php file in the directory, so thats not the case.

total 8
-rwxrwxrwx 1 nixos users    0 Apr 12  2022 favicon.ico
-rwxrwxrwx 1 nixos users 1710 Apr 12  2022 index.php
-rwxrwxrwx 1 nixos users   24 Apr 12  2022 robots.txt

Finally got it working. This was the trivial problem, but i remember, that i did not do it previously. So i added DirectoryIndex index.php to specify what file to process and it seems to work now.

 <VirtualHost 127.0.0.1:8000>
    DocumentRoot "/home/nixos/Documents/Laravel-pet-1/public"
    ServerName laravelPet1
    <Directory "/home/nixos/Documents/Laravel-pet-1/public">
      Require all granted
      DirectoryIndex index.php
    </Directory>
  </VirtualHost>
wget http://127.0.0.1:8000
--2025-04-02 13:33:19--  http://127.0.0.1:8000/
Connecting to 127.0.0.1:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.html’

index.html                                          [ <=>                                                                                                  ]  17.18K  --.-KB/s    in 0s

2025-04-02 13:33:24 (940 MB/s) - ‘index.html’ saved [17594]

Now i will try to open it in my main browser, now it is refusing connection.