Did you add your complete Laravel project to the lp folder or only the files from the public folder?
Deploy laravel in subfolder of wordpress 404 not found
Hi, my customer's server is sharehosting and run wordpress. But I need deploy Laravel 9 web to subfolder. This is tree folder:
/site.com/pubic_html/{sourcecode wp}
/site.com/pubic_html/lp/{laravel source}
I need to run laravel in URL: site.com/lp
My htaccess of laravel root folder: /site.com/pubic_html/lp/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/ [L]
</IfModule>
But site.com/lp always show 404 not found (page 404 with style laravel)
Thank for your help
@gych I install complete laravel project by composer, all file source code of laravel in lp folder
@gych I was try clone laravel project to another folder, same level with public_html, and only copy all file in public folder to lp folder, custom path in index.php. but it show 405 error page. error page of sharehosting server
@ThoHC Ok your laravel project folder should be added outside of public_html
Do you have SSH access on the shared host?
@gych Yes I have
@ThoHC Ok good
Put the Laravel project folder on the same level as the public_html folder (not inside public_html) If the lp folder already exists, delete it first, otherwise you will get an error when trying to create a symlink.
Now create the symlink between the laravel project's public folder and the lp folder via ssh terminal. When the terminal is located inside the laravel project folder run this command.
ln -sr public ../public_html/lp
This will create the lp folder inside public_html with a symlink between the laravel project's public folder and the lp folder.
@gych Thank for suggesting. I created symlink, and web show 405 Method Not Allowed when connect to site.com/lp. error from server, not laravel
@ThoHC Which APP_URL did you set in your ENV file?
@gych APP_URL=https: //site. com/lp (not space)
@ThoHC Ok and your htaccess files is it like the original files or changed? When I once did this I didn't had to change anything to the htaccess files
@gych this is some htaccess file:
/lp/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/ [L]
</IfModule>
/lp/public/.htaccess
<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>
/public_html/.htaccess
SetEnvIf Request_URI ".*" Ngx_Cache_NoCacheMode=off
SetEnvIf Request_URI ".*" Ngx_Cache_AllCacheMode
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-di
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
@ThoHC Delete this /lp/.htaccess file, its not necessary. Then test again to see if you still get the error.
@gych thanks for keep support for me. I was deleted /lp/.htaccess but web still 405 error
@ThoHC No problem :) Did you change anything to the default index.php in your laravel application's public folder?
@gych Nothing to change index.php , I think 405 error from server is mean can't connect to outside of public_html.
When laravel project push into public_html, web show 404 notfound page of laravel. I try add dd(1) to index.php and web show dump:
$kernel = $app->make(Kernel::class);
dd(1); // web show dump
$response = $kernel->handle(
$request = Request::capture()
)->send();
dd(1); // web show 404 not found page
$kernel->terminate($request, $response);
@ThoHC If your routes are cached try to run php artisan route:clear
Does your host use nginx or apache?
@gych I'm try clear all cache but still error. My shared hosting use nginx
@gych Hi, I have some change and loaded source laravel, but it not correctly. For now, my directory:
-
/lp_source(laravel project, all file) -
/public_html(wp project)
I marked symlink:
ln -sr lp_source/public public_html/lp
When load site.com/lp show blank screen. after checklog I see web load js or CSS file from site.com/build/..., this must be site.com/lp/build/...
I don't know how to config htaccess to make load build from site.com/lp, please help.
I try make symlink build folder to public_html
ln -sr lp_source/public/build public_html/build
and then link URL auto duplicate path from site.com/lp to site.com/lp/lp/ and load success web lp, but when F5 or ctrl+R link site.com/lp/lp/ web will show 403 page because not have lp folder in lp folder
@ThoHC So you are now trying to test if it works with a fresh Laravel installation?
What is the APP_URL in the env file ? Is it still https://site.com/lp ?
@gych APP_URL just https ://site. com, change to https ://site. com/lp same error
@gych for now I don't know why URL auto duplicate path. you can visit mypage to view behavior
https ://n-kaihatsu. net/lp2
@ThoHC Did you change anything to htaccess files or are they still as default?
@gych htaccess still as default in /lp_source/public/.htaccess and public_html/.htaccess
@ThoHC Ok and you still have symlink between lp_source/public and public_html/lp ?
@gych yes. I have 2 symlink
lp_source/public and public_html/lp
and
lp_source/public and public_html/lp2
because /lp have error and cache from server, so I testing with /lp2
You can't disable the caching for that directory ?
Something went wrong when setting this up, my first guess would be the htaccess file but since you did not change anyting to that.
You also made multiple symlinks try to delete the symlinks and directories lp and lp2
Then create a symlink only between the public folder and lp2
@gych Server was remove caching, url lp is worked, but still duplicate lp when I connect https://n-kaihatsu.net/lp, web auto add /lp => https://n-kaihatsu.net/lp/lp/, look like only add to url without redirect reload.
this doesn't happen at my localhost
@ThoHC Try to add this rule in your laravel project's htaccess file
RewriteRule ^lp/lp/([^/]+)/?$ /lp/ [R=301,L]
@gych I use window.history.pushState to remove lp in URL, same idea, but it's not as good as your way, anyway it worked, thank you very much
@ThoHC No problem :) I'm glad it works
Don't use Laravel in subfolder.
Why are you complicating things. Just get another webspace for your Laravel application and create a subdomain.
example.com for the wp
lp.example.com for laravel.
Please or to participate in this conversation.