#403 Forbidden on New Laravel app

36 messages · Page 1 of 1 (latest)

hasty sand
#

I just deployed my laravel app to my linux server but am getting a "Forbidden" error. Is there a "default" .htaccess I should be using for Laravel? What file and folder permissions do I need to set to all my files?

unreal forge
#

any print, can you give more details?

strange pewter
#

@hasty sand The files/folders need to be readable by the webserver, regarding permissions.

#

..possibly writable as well, depending on what your code wants to do.

hasty sand
#

My .htaccess only had ```<IfModule mime_module>
AddHandler application/x-httpd-ea-php82 .php .php8 .phtml
</IfModule>

php -- END```

So I just added ```Options +FollowSymLinks -Indexes
RewriteEngine On

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

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]```

And now I get "File not found."

#

I'm just trying to hit the home-page...

strange pewter
#

Verify the site config, both php and apache need the right folders.

#

Tutorials on this might be handy for this, so that you're not missing any steps.

hasty sand
#

I'm running Laravel 11 and just trying to hit my home page "/"

hasty berry
#

have you actually pointed the document root to be in your apps public folder?

hasty sand
#

My httpd.conf has this:

    ServerAlias www.preview.xxx.com
  DocumentRoot /home/xxx/public_html/preview/public/
  ServerAdmin [email protected]
  UseCanonicalName Off
   <Directory /home/xxx/public_html/preview/public/>
        AllowOverride All
        Require all granted
        Allow from all
   </Directory>```
strange pewter
#

That doesn't tell us whether those folders are real and exist or not.

hasty sand
#

/home/xxx/public_html/preview/public/ is a valid folder. I've set all the files in there to 644 and folders to 755. If I go to preview.xxx.com/.env I'm able to read the file a plain text (bad! but tell us something)

strange pewter
#

What happens if you try to load index.php?

acoustic bloom
#

Your doc_root should be the public directory... your laravel app base directory should NEVER be available to the public

strange pewter
#

Right, .env is in the folder one step above public.

acoustic bloom
#

right but if you can load .env in the browser, its misconfigured

#

Not sure what others do, but, i like to keep my laravel apps in /home/user/production/ and then symlink /home/user/public_html/ to /home/user/production/public/

#

that way the app itself is never in the doc_root

hasty sand
#

I'm using a CPANEL managed server...any tips on having it honor the DocumentRoot in apache?

acoustic bloom
#

You can do exactly as a described on cPanel

#

If you dont have shell access to your account, you MAY be able to symlink inside the File Manager

strange pewter
#

@hasty sand What folders are there inside the public folder? Is there an app folder?

acoustic bloom
#

Just make sure to move the cPanel default .htaccess over to your public as EasyApache and PHP Manager will maintain your PHP version mod inside it

hasty sand
#

I think I got it.. in CPANEL, I found an option to change the Document root for a domain. I changed it and now the front-page loads!

acoustic bloom
#

There ya go!

hasty sand
#

Can you please advise what permissions I need to set to secure my folders? Online, I'm finding tutorials that do 777 for everything which I know is wrong

#

Also, am I supposed to put /public and /resources in my .gitignore file?

acoustic bloom
#

644 files, 755 folders

#

that works for PHP running as the user

#

FPM, etc

acoustic bloom
#

unless you are adding other files to your project (vscode workspace, postman workspace, notes, etc) or others that you don't want in VC, it should be fine

hasty sand
#

For example, on my server after running Vite npm run build, I am seeing public/build/assets/app-UqRVr5q0.css Should I add public/build to my .gitignore? It isn't in the default

#

I'm also seeing tons of changed files in /public/dist, /public/fonts, /resources/plugins etc.

acoustic bloom
#

Some folks would say not to put built/compiled assets into VC, some don't care... Dependening on project size, if you're committing both, you're doubling up and when you deploy, you have to build anyway, so, why commit the built