Laravel - move index.php file in project/public - php

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.

Related

How we can run codeigniter 4 in local host or subdirectory without changing apache host configuration file?

I am trying to run CodeIgniter 4 localhost using a subfolder like http://localhost/codeigniter4login/ but the root URL always shows http://localhost we need http://localhost/codeigniter4login/.
Step 1: In public/ directory, copy index.php and .htaccess to your root project directory.
Step 2: In the root project directory, open index.php and edit the following line:
Change on Index.php:
$pathsPath = FCPATH . '../app/Config/Paths.php'; change to ($pathsPath = FCPATH . 'app/Config/Paths.php';)
There are two ways to resolve these. One by editing the App.php config file other by the .evn file.
Follow the steps:
Option 1
Open file "app/Config/App.php"
Find public $baseUR and change value to http://localhost/codeigniter4login/.
Save the file.
Option 2 (Using Env)
Open file ".evn"
Find app.baseURL and add the value http://localhost/codeigniter4login/ to it
Save the file.

Laravel/00webhost Error 404. The requested URL was not found on this server

1.
Uploaded my files to 000webhost. I placed all files from the public folder to public_html then I created a folder named laravel and there I uploaded all other files. This is the structure of my directory:
laravel
app
bootstrap
config
....
public_html
index.html
.....
2.
In my index.php file, I already changed some things to these
require DIR.'/../laravel/bootstrap/autoload.php';
$app = require_once DIR.'/../laravel/bootstrap/app.php';
3.
I also changed the .env file and the database.php in the laravel/config folder
Problem:
I am now able to access the home page of my site, but when I click my links to the other pages error 404 shows up.
How do I fix this?
And how do I access the routes in my api.php ?
Thanks!
Your includes seem fine.
Be sure you also uploaded the .htaccess file located in /public (in your /public_html). The file name starts with a dot so it's commonly hidden.
The purpose of this file is to indicate Apache how to map URLs to real files (in this case, everything should point to index.php)
Try changing the index.php file. Change it as the following:
require __DIR__.'/laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'/laravel/bootstrap/app.php';
This should solve the problem.

Set location of laravel .env

So I just published a build of laravel to my production server. But the .env file was readable when I uploaded it. So I uploaded it to root of my site next to the public_html/ directory.
My question is: How to tell laravel where the .env file is located? It worked when I had it in the public_html/ folder but how do I tell it to look in the root folder?
Set env path in bootstrap/app.php:
$app->useEnvironmentPath($env_path);
for example, directory layout for my project:
webapp
-laravel
-public
-.env
Custom path to env file
$app->useEnvironmentPath(
dirname(__DIR__, 2)
);
As you can read in the official documentation, the .env file must be in the root directory of your Laravel app. There's no way to change the file location (and I think there's no point too).
Moreover, the root folder SHOULDN'T be a public folder, as .env shouldn't be exposed to a public access, otherwise the main security aim of it would be completely lost.
What you need to upload to public_html is contents of public directory in Laravel installation including any JavaScript files, CSS files or images that should be accessible to client, everything else should be placed out of public directory.
This way you can access .env file from other location, but it is not good for security.
your-project/bootstrap/app.php
$app = new Illuminate\Foundation\Application(
realpath(DIR.'/../')
);
$app->useEnvironmentPath(base_path('foldername/'));
add this code in .htaccess file for security
<Files .env>
order allow,deny
Deny from all
</Files>
I ended up setting a symlink from public to public_html and everything worked as expected
Add code in bootstrap/app.php
$app = new Gecche\Multidomain\Foundation\Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__),
dirname(__DIR__) . DIRECTORY_SEPARATOR . 'envfolder'
);

Laravel 4.2 remove /public from URL

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!

File structure for dev server and repo

I have a development server at dev.mysite.com and I am working with coda and git to make commits and pushes to the repo which has a developmenet branch that points to my dev domain.
The file structure as of right now is this. As of right now does anyone see anything that I should reconsider changing. I'm asking this because of having a public_html inside the dev folder or what. With this setup currently when I load dev.mysite.com it shows the index of / which shows .gitignore, .git, and public_html.
../
/dev
/mysite.com
.git
.gitignore
/application
/public_html
/assets
index.php
/system
/mysecondsite.com
/application
/public_html
/assets
/index.php
/system
/sites
/mysecondsite.com
/application
/system
index.php
Does anybody have any ideas?
If you want to have a development environment and a production environment. While having the core files for CI outside of a public_html. You have to redefine your document root. I assume you are using a server the comes with cPanel as your means of administration for your server.
So that said, you go into your cpanel and where you defined your dev subdomain, you should be able to edit the document root folder. So on the server in your dev folder you will add a public_html like I gather you already have from the example above. And with your current folder settings for dev you add /public_html to the string that is the folder path now.
Once you do that allow a minute or two for it to delegate to the server from cPanel. And move your folders around as you see fit.
From there, you find the root index.php and open that up, find the references for your application folder and your system folder and change them to match the paths they should be looking for now. Likely using relative paths.. ie: ../../applications for example. Save your index.php
Assuming you have done everything in general correct your copy of CI should load correctly as it did when you didnt have everything in the folders split up like you want..

Categories