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

bhojkamal's avatar

What to configure to deploy the laravel 9 project in server to live a website from cpanel?

Hello, What to configure to .htaccess and add file to laravel 9 application to deploy the laravel 9 project to make live a new website in the server from the cpanel. In Laravel 9, I don't see the server.php in the root project. I have done the laravel 8 projects adding following line in .htaccess.

	RewriteEngine On
	RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ ^ [N] 
    RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
    RewriteRule ^(.*)$ public/ 
 
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ server.php
0 likes
10 replies
Tray2's avatar

If possible you should change the document root in the virtualhost file rather than using the htaccess file to redirect to public.

It should point to the index.php file and not the server.php file.

I use this htaccess on my shared host

#Rewrite everything to subfolder
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public
Rewriterule ^(.*)$ public/ [L]
bhojkamal's avatar

@Tray2 Thank you for your reply. It works only when I put example.com/public, other otherwise it does not work. If I hit just example.com -> it gives 404 - Not Found. Error.

Tray2's avatar

@bhojkamal That htaccess file should be placed in directory that contains the public directory.

bhojkamal's avatar

@tray2

If I use that code in .htaccess under public directory. It shows all file on root url and If I go /public, it add another public in url like this /public/public and it does not work. Thanks for reply.

bhojkamal's avatar

It should use on root. We need different for htaccess in public.

bhojkamal's avatar

@Tray2 one new .htaccess should be on project root. And we have write logic on it. What is the correct logic, that what I need. The above one didn't work.

Snapey's avatar

the best approach is to delete public_html folder and recreate it as a symlink to the projects public folder

bhojkamal's avatar
bhojkamal
OP
Best Answer
Level 1
	RewriteEngine On
	RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ ^ [N] 
    RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
    RewriteRule ^(.*)$ public/ 
 
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ server.php

This is enough in website root .htaccess. just create server.php or index.php and add require_once __DIR__ . '/public/index.php' I have done and work perfectly. In laravel there is already server.php, but in laravel 9, need to add this file.

1 like

Please or to participate in this conversation.