6

As with a lot of hosts our public folder is called public_html. This is on shared hosting so can't be changed. I've changed the public folder to public_html to reflect this, but when I do artisan serve stops working. Every time I try to start it I get:

[ErrorException]
chdir(): No such file or directory (errno 2)

If I rename the folder back to public then artisan serve starts working again.

I've tried following this post on laracasts, and the user in the post reports artisan works for them, but it made no difference to me. How can I change the folder and have artisan serve work?

Styphon
  • 10,304
  • 9
  • 52
  • 86
  • FYI, Laravel is unlikely to play nice with many shared hosts. – ceejayoz May 20 '15 at 14:58
  • @ceejayoz Why is that? I'm about to redevelop our CMS using Laravel so if that's the case it would be a real pain in the ass. – Styphon May 20 '15 at 15:25
  • Depends on the host. Some won't let you properly set the permissions/ACLs on the `storage` directory. I'd test with a minimal app on your preferred host to see if everything works as expected. You could also consider using something like DigitalOcean to get a $5/month VPS. – ceejayoz May 20 '15 at 15:27
  • Well we use Heart Internet and it seems someone has already written a guide for Laravel with them - http://novate.co.uk/deploy-laravel-5-on-shared-hosting-from-heart-internet/. I think we should be OK. – Styphon May 20 '15 at 15:28

2 Answers2

8

Dipesh's answer is actually a very bad idea - those changes will be blown away anytime you do a Composer install/update/require. Never directly edit anything in the vendor directory.

Instead, in bootstrap/app.php, you should add:

$app->bind('path.public', function() {
    return __DIR__;
});

right after

$app = new Illuminate\Foundation\Application(
    realpath(__DIR__ . '/../')
);

See https://laracasts.com/discuss/channels/general-discussion/where-do-you-set-public-directory-laravel-5 for further discussion and alternate ways of doing this in a safe manner.

You could also extend Illuminate\Foundation\Application. This appears to be necessary for the Laravel CLI (anything starting with php artisan) to pick it up.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • Thanks for that, but if you noticed I linked that very discussion in my original question. I've already modified `bootstrap/app.php` to no avail. I also set up `/app/Providers/CustomServiceProvider.php` and listed it in `config/app.php` with the other providers as suggested by one of the last posts. – Styphon May 20 '15 at 15:18
  • @Styphon Did you try the last link I added, extending Illuminate\Foundation\Application? I suspect it's necessary as Laravel's CLI seems to need the `publicPath()` function, which you'd need to use the extension technique for. Again, the other answer - directly editing `vendor` - will break on you very quickly. – ceejayoz May 20 '15 at 15:19
  • 1
    I've just tried that now, it works a charm. Thank you. – Styphon May 20 '15 at 15:23
  • Unfortunately both links in the answer are broken. If you need it to work with `artisan`, check out my answer here: http://stackoverflow.com/a/33652169/1296104 – ruuter Nov 11 '15 at 14:03
-1

find /vendor/laravel/framework/src/Illuminate/Foundation/Application.php this file
and change on following function

/**
 * Get the path to the public / web directory.
 *
 * @return string
 */
public function publicPath()
{
    return $this->basePath.DIRECTORY_SEPARATOR.'public_html';
}
Dipesh Shihora
  • 414
  • 2
  • 6
  • 19
  • @Styphon This is actually a very bad idea and will be blown away the next time you use `composer update`, `composer require`, or `composer install`. – ceejayoz May 20 '15 at 15:04
  • 1
    You should not change any code on core files. Chose either way from ceejayoz's post. – Sinan Eldem Aug 31 '15 at 20:50
  • You could easily just extend the core class. Check out my answer here: http://stackoverflow.com/a/33652169/1296104 – ruuter Nov 11 '15 at 14:05