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

ivan2nn's avatar

Laravel 8 on shared hosting server in subfolder

I am trying to move my local laravel 8 app to a shared hosting server. The server is in the address 'www.nameofsite.com'.

I need to put the application inside 'www.nameofsite.com/myapp'

I don't have public_html inside the 'www.nameofsite.com'.

Using FTP I created a folder called myapp inside the folder www. nameofsite. com; then I copied the local version of myapp inside this live myapp folder. I moved public folder to be at the same level as the application folder. At the moment i have the app setup in the following way:

                                           |--- css, js, index.php, etc...
www.nameofsite--->myapp--->|
                                           |--- myapp-> app, bootstrap, etc.....

I modified the index.php setting:

if (file_exists(__DIR__.'/myapp/storage/framework/maintenance.php')) {
    require __DIR__.'/myapp/storage/framework/maintenance.php';
}

and I repeated the same operation for vendor and bootstrap in the index.php.

Now the problem: I launch the site going to 'www.nameofsite.com/myapp', the laravel 8 auth starts and it brings me to:

www.nameofsite.com/myapp/items/create

that is the form of creation of the item. As soon as I push the button SAVE of the form, I get the "Not Found The requested URL was not found on this server".

And the URL appearing in the address bar is:

www.nameofsite.com/items

(it lost the /myapp/ part)

In the web.php file I have a normal setup for the Items routing:

Route::post('/items','App\Http\Controllers\ItemsController@store')->middleware('auth','isAdmin');

and in the view i have:

<form method="POST" action="/items" class="mt-5">
            @csrf
  . .....

The .htaccess which is at the same level of index.php is the following:

Options -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [L,R=301]

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

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

I can't understand why it behaves like this or why it jumps back to the "master" parent folder ('www.nameofthesite.com') when I do the POST action

0 likes
8 replies
Snapey's avatar

use a web host that allows you to place your application outside of the publically served folder

jlrdw's avatar

To add:

  • Yes preferred, main laravel out of web altogether.

Or

  • If you can't, make public the document root as per documentation.

I use the htaccess that comes with laravel, have never needed to change it.

I moved public folder to be at the same level as the application folder.

That is not a correct setup.

mikelucid@gmail.com's avatar

" I moved public folder to be at the same level as the application folder."

This is whats causing issues. app/ and public/ should be at the same levelSo that would make your root index public/index.php.

Then your .htaccess should look like this(like the docs say):

Options +FollowSymLinks
RewriteEngine On

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

Then you will be good to go.

ivan2nn's avatar

Thank you all.

So i removed all the files and upload (like the original structure) again the local version (tha has the original files and it works like a charm) to the server (in the myapp subfolder).

'www.nameofsite.com/myapp' does not work (Forbidden: You don't have permission to access this resource.),

but 'www.nameofsite.com/myapp/public' shows the login and the Item create page.

As soon as I try to post a form the site goes back to 'www.nameofsite.com/item' (a level up from my app) and shows: Not Found: The requested URL was not found on this server.

Using Filezilla i changed the permissions of the 'www.nameofsite.com/myapp' folder to 757.

I don't get it. And I don't understand why moving a WordPress site in a subfolder works like a charm, while with Laravel i have this problem

Thank you

Snapey's avatar

Did you set App_url to be the subfolder.

By the way, you are sure to be hacked if you have the laravel project in a publicly served folder.

Consider instead setting up a subdomain, eg myapp.nameofsite.com

ivan2nn's avatar

I changed, inside .env, the APP_URL to "http:// www.nameofsite.com/myapp"

I still have the same problem; whenver i have to create an item, so method="POST", action="/items", the application tries to access "www.nameofsite.com/items" instead of "www.nameofsite.com/myapp/items" (or "www.nameofsite.com/myapp/public/items"... )

Snapey's avatar

because your URL starts with / (meaning from the root) use the route() helper instead then you will get urls that are using app_url

jlrdw's avatar

Just setup laravel correctly.

Please or to participate in this conversation.