my server using cPanel. directory structure here
laravel-project
public_ftp
public_html
public
index.php
I deployed on the server following this guy
https://github.com/petehouston/laravel-deploy-on-shared-hosting
everything well but my base path is "mydomain.com/public"
I don't want to remove /public out from my path but to change it,
I want path like this "mydomain.com/noticed"
I using laravel version 5.3
Any Idea?
Thank You
In laravel 5.6 add this code to bootstrap/app.php :
$app->bind('path.public', function() {
return realpath(__DIR__.'/../');
});
where __DIR__.'/../' is path to your public folder
It was suggested to change the index.php in your public folder.
*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/../bootstrap/app.php';
// set the public path to this directory
$app->bind('path.public', function() {
return __DIR__;
});
Now you dont need to change your public path when your public
directory has changed.
Elixir has a hardcoded public path! Do not forget to set the changed
public path in the Elixir config.
I might add that you also need to make sure that your new public path have the same permission as the default one. You might also want to change the public path in the config/filesystem.php.
Related
I changed my laravel installation folder structure by moving all files and folders from the root directory to a new folder 'core'.
The goal is, to have only the folders in the root directory of the project
core
public
I have updated the index.php in public folder but I have the following problem:
when I die dump the paths, all are correct except the public path
dd(app_path()); // somepath\project\core\app
dd(storage_path()); // somepath\project\core\storage
dd(base_path()); // somepath\project\core
dd(public_path()); // somepath\project\core\public
I want to retain all other paths and change only the public path to somepath\project\public instead of somepath\project\core\public , how can I do this, online docs I've reference focus on changing public_html to public but I don't want to change the public_html, just to tell laravel that the public path is somepath\project\public
This particularly needful for me as I use the laravel storage for handling uploads.
Below is my folder structure
project
|-core
|- every other folders and files
|-public
|-every other asset files
You need to rewrite the base path in the app/Providers/AppServiceProvider.php like so:
public function boot()
{
$this->app->bind('path.public', function () {
return dirname(getcwd(), 1) . '/public';
});
}
I want to change the public folder to public_html, the main problem is that some commands and functions not work because it still point to public.
I am trying to use the laravel+vue to develop a spa. i normally rename the public folder to public_html and that's all, but know it seems that i have to use the public_path helper and the console and these use the public folder too.
im using npm run dev as in the laravel docs, but it generate everything in the public folder, not in the public_html that i have renamed
so how can i tell the console and the public_path helper to do they magic in the public_html folder?
I am using Laravel 5.6, it is a fresh project, with just a controller and a view with a mix helper calling the js that i want link this <script src="{{ mix('js/app.js') }}"></script>.
May this can help you. You can override Laravel default helper methods. This code helped me at a time when I got same problem like you.
Simple I created one helper file and override public_html function something like this:
/**
* Get the path to the public folder.
*
* #param string $path
* #return string
*/
function public_path($path = '')
{
return base_path().'/public_html';
}
Let's say file name is AppHelper.php and located into app/Http folder.
To override helper from base you need to include your helper file(AppHelper.php) before Laravel does it's own autoload file.
So for the web you have to include your file into index.php like this:
require __DIR__.'/../app/Http/AppHelper.php';
require __DIR__.'/../vendor/autoload.php';
Remember your helper must be included before autoload file. and this code snippet for Command line or Artisan CLI:
require __DIR__.'/app/Http/AppHelper.php';
require __DIR__.'/vendor/autoload.php';
You have to write your artisan cli changes into artisan file which is on root.
In Laravel if you check helper function then each and every function wrapped with if condition like this function is not exist then declare it using function_exists()
In our case we already declare public_path function and included before Laravel autoload file so every request first execute our function.
Hope this can help you. Good luck.
Add this in register() method of your AppServiceProvider
public function register()
{
// Add this part
$this->app->bind('path.public', function() {
return base_path().'/public_html';
});
}
For the css+js resources, as #Bagus Tesa said, you have a file named webpack.mix.js in the root of your application folder. It's not you who created it, it comes with the laravel project. In that file you'll find something like:
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css');
Change the destination path from public to public_html
I am having a bit of an issue with one route (and only with this one, every other route works without any issue).
This are my routes (I commented out all routes, except the /home, just to be sure that they are not messing up something):
<?php
// Route::get('/', 'DashboardController#index')->middleware('menu.admin')->name('home');
Route::get('/home', 'DashboardController#index')->middleware('menu.admin')->name('home');
// Route::get('/user/verify/{token}', 'Auth\RegisterController#verifyUser');
// Route::get('logout', '\App\Http\Controllers\Auth\LoginController#logout');
// Auth::routes();
// // Admin routes (admin dashboard)
// require(base_path() . '/routes/admin.php');
// // Site routes (frontend)
// require(base_path() . '/routes/front.php');
I am getting this error:
Not Found
The requested resource /home was not found on this server.
The / route works without any issues, and when I try /home (the only difference between this two routes), I am getting the error.
I did php artisan route:clear, and it didn't help. Does anyone have an idea what is going on (.htaccess file is not an issue here)?
Laravel ^5.6
if your routes are defined properly, and by properly i mean you defineded routes in the right order (to avoid conflicts) and the artisan command php artisan route:list get executed correctly BUT you still get 404 Not found - The requested resource /path was not found on this server. weird, not exactly what you were expecting!!
...i also faced this problem, and here is the thing, that error occurs when you create a folder in the public directory with the same URI
...to illustrate here's an example (this is the problem i faced)
routes/web.php
/*
|--------------------------------------------------------------------------
| Web Routes - Backend
|--------------------------------------------------------------------------
*/
Route::group(['namespace' => 'Backend', 'prefix' => 'backend'], function () {
Route::get('/', 'DashboardController')->name('backend.dashboard');
// ...
});
php artisan route:list
php artisan route:list --name=backend --columns=uri --columns=name
+--------------------------------+--------------------------------------+
| URI | Name |
+--------------------------------+--------------------------------------+
| backend | backend.dashboard |
| // ... | // ... |
+--------------------------------+--------------------------------------+
public/
+---public
| +---backend
| | +---css
| | +---fonts
| | +---images
| | +---js
| +---.htaccess
| +---favicon.ico
| +---index.php
| +---mix-manifest.json
| +---robots.txt
As you can see, i have a route URI that start with backend AND also a folder under the public directory named backend as well, that's what cause the problem, so it's up to you to change one of those, personally i changed the name of the folder under public directory to "back-end". that solved my problem.
you use apache or nginx as web server?
try to set config for webserver
https://laravel.com/docs/5.6/installation
Because, you have a folder named control on /public folder. That error occurs when you create a folder in the public folder with the same name as your route so please change the name of the folder you have put in the public folder so that it has a different name from your route this will probably solve your error
I am using laravel and deployed my application on server
application folder path /var/www/app
So when i run the url with public, css will load.
http://xxx.xxx.xxx.xxx/app/public/
But when i remove the public from url, css will not load.
http://xxx.xxx.xxx.xxx/app/
Css and js files are located into the public folder
How can i solve this issue, can i change the asset path if yes please tell me the where the asset define
Thanks
Laravel is designed to run the code from the public directory, so files like .env are protected from public access. Your server should be pointed to the public folder.
However, if you want to change the public url, you can edit the index.php file and specify your own path:
// add after $app = require_once... in index.php
$app->bind('path.public', function() {
return __DIR__;
});
I uploaded my laravel 4.2 project on my shared webhost. now I have to go to mydomain.com/public to see the view . But I dont want ant public folder in my address . I used so many suggested .htaccess files but they didn't work for me.
Does any one know other solutions ? (not using .htaccess file) ... for example any laravel config that can help me...
thanks
Normally you need the htaccess file to point to the public folder. But you can copy the content of the public folder in your root folder and change the app path to it.
Copy your index file in your root folder and add this to your index.php file:
// set the public path to this directory
$app->bind('path.public', function() {
return __DIR__;
});
Here is solution I recently found and worked on my local host (I wish and think this works on shared webhost too). I hope it helps someone if has the same problem :
laravel 4 remove public from the URL
Follow the steps below to achieve this.
Step 1
Move everything from public folder to the root directory
Step 2
Now delete the empty ‘public’ folder.
Step 3
Edit the file bootstrap/paths.php
Find the following line
'public' => __DIR__.'/../public',
and replace it with:
'public' => __DIR__.'/..',
Step 4
Modify index.php in root
Find the following line
require __DIR__.'/../bootstrap/autoload.php';
and replace it with:
require __DIR__.'/bootstrap/autoload.php';
Now in the same file find the following line
$app = require_once __DIR__.'/../bootstrap/start.php';
and replace it with:
$app = require_once __DIR__.'/bootstrap/start.php';
That’s all. Browse to your Laravel installation without public in the URL and make sure it works.