Laravel 4.2 remove /public from URL - php

I've seen many people posting here on how to remove the /public folder from URL.
E.g. http://some-domain.com/LaravelProject/public/index.php

It's simple. Suppose your Laravel project is in LaravelProject directory. Copy the server.php in the same folder as index.php.
After that, copy the .htaccess file from public folder in LaravelProject, i.e. your Laravel root folder. It should work!

Related

Migrate Laravel 8 to a subfolder of a shared host

I am using a shared host. Inside my shared host public_html, I have a folder named project1. This folder contains the files for my main site.
I want to create a new folder (e.g. Project2) for my new Laravel 8 application. I've tried putting all my file inside public_html. It is working when I visit the site using the example.com/project2/public/index.php URL format. But the problem with this is that my important file like the .env, will be public.
I've also tried this but when I tried to run the project, it gave me a 500 error.
Try changing the name of server.php file to index.php and copy .htaccess file from public folder to same location where server.php

How to allow access to sub folders in laravel?

I have laravel installed on my server and I want to add a folder called 'projects' in laravel's root folder and access the projects folder from URL.
What should I do to solve this issue? I want to upload some PHP code demos and allow people to view them.
I have tried playing with the .htaccess but nothing seems to work for me.
public_path(); // Path of public/
base_path(); // Path of application root
app_path(); // Path of app/

Laravel delete file in app folder (root)

How to delete files from Laravel app directory (not the public directory but the one in the root)?
I tried :
\Storage::Delete('App\file.php');
\Storage::Delete('\App\file.php');
\File::Delete('App\file.php');
\File::Delete('\App\file.php');
unlink ('\App\file.php');
Nothing works.
UPDATE:
The file is in something like \App\folder\folder\file.db
When not specifying an absolute path then what is used is the current working directory (the value that getcwd() would return). Usually, that's the /public directory and not the actual project root.
You need to specific an absolute path using the Laravel helpers:
\File::delete(app_path('file.php'));
Note: You can't use the \Storage helpers because they are limited to only work within the app storage folder.

Laravel - move index.php file in project/public

I am hosting my Laravel project on shared hosting where I don't have access to modify the apache config to look for the index file in /public.
I've also tried adding DirectoryIndex index.html to my .htaccess file at the place where the hosting is looking for the index.php file.
This does not work.
That being said, I think I can solve the problem if I simply move the index.php file out of /public (where Laravel has it by default) to the root where the hosting is looking for it.
That being said, what do I need to modify in this index.php file to allow the Laravel app to work?
My structure is:
public_html/ <-- where my files are served from and where index.php should be
my-project/
public/
index.php <-- where Laravel expects index.php to be to bootstrap the app
Okay here we go:
Let's say this is your folder structure:
MyUser/
public_html/
public/
What you want to do is:
Step 1. create a folder on the same level as public_html named laravel (or something to your liking):
MyUser/
laravel/
public_html/
public/
Step 2. upload ALL your laravel code to the laravel folder. Your code is now inaccessible through a web browser.
Step 3. Next, you copy all data from MyUser/Laravel/public to MyUser/public_html. Now we're getting somewhere. Warning: Don't forget to copy the .htaccess file too
Step 4. open MyUser/public_html/index.php in your favorite editor and change
$app = require __DIR__.'/../bootstrap/app.php';
to:
$app = require __DIR__.'/../laravel/bootstrap/app.php';
and change:
require __DIR__.'/../bootstrap/autoload.php'
to:
require __DIR__.'/../laravel/bootstrap/autoload.php'
Step 5. Now, since your storage directory is outside of your public_html, it'll most likely not be accessible, so CHMOD that to 777, and you're done!
A small tip:
See if you can create a symlink from MyUser/laravel/public to MyUser/public_html. That'll let you skip step 3 and 4.
Hope this helped.

Laravel on sub folder

I am trying to install Laravel 5.3 in sub domain /public_html/mysite
but it's not working should I change .htaccess or what ?
Put the content of public (L5) directly on public_html (be aware of don't overwrite the .htaccess file accidentally) Now in then modify your index.php and your bootstrap.php and it will work just fine
I hope #Nino Armani gave you the right answer. Although you can try with visual video tutorial here-
http://www.tisuchi.com/upload-laravel-projecy-cpanel/
Move everything from project/public folder to project/ folder
Update index.php to have bootstrap path like "./bootstrap"
Add base APP_URL in your .env
Update layout folder paths like {{URL::to('/css/app.css')}}

Categories