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

Dave97's avatar

Fatal error: require(): Failed opening required '/home/forge/default/public/../vendor/autoload.php'

Hi,

I achieved a Laravel5 website running OK on my local server and uploaded on bitbucket. I decided to use Forge+Digital Ocean for the deployment on remote server.

I encounter a first deployment failure with ' /home/forge/default/bootstrap/cache directory must be present and writable' on Forge that i solved by installing the project without installing the composer dependencies.

Then i updated the .env file with Forge db credentials mail infos and ran the first deployment that was said to install the dependencies. Everything seems ok per the Log file except that when visiting the site i got now :

Warning: require(/home/forge/default/public/../vendor/autoload.php): failed to open stream: No such file or directory in /home/forge/default/public/index.php on line 24

Fatal error: require(): Failed opening required '/home/forge/default/public/../vendor/autoload.php' (include_path='.:/usr/share/php') in /home/forge/default/public/index.php on line 24

(Using MySQLWorkbench with SSH, i also cant see any tables migrated)

Did someone encounter such issue? I got a hard time with Forge process...

0 likes
15 replies
Dave97's avatar

@Sergiu17 Indeed after breathing some fresh air, i thought to try composer install through SSH CLI:

It started generating dependencies and failed with : ' In PackageManifest.php line 165:

The /home/forge/default/bootstrap/cache directory must be present and writable.' Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1

This took me to the initial error that i got with Forge deployment when composer dependencies ticked. By CLI , listing all the file in my folder bootstrap i can see that folder Cache doesnt exist...

ejdelmonico's avatar

If you deployed the server with Forge, then all permission and configurations are done for you. When you perform an action such as composer install, you need to ssh into the server as the forge user. If you have the missing cache message after initial code deployment, it is usually because you have included the vendor or cache directories in the repo. You can do that but all required directories will need to be present. In your case, the /bootstrap/cache file was missing. After you correct anything, you will need to run composer dump-autoload to fix the other failure messages.

Dave97's avatar

@ejdelmonico

Thks for advise but i checked my gitignore excludes the vendor, storage and cache folder (which exists locally on my test site). They dont appear on my bitbucket which is used for deployment on Forge .;(

ejdelmonico's avatar

@dave97 So, have you added the proper deployment actions under the deploy scripts or whatever it is called these days? Things like php artisan migrate --force.

cd /home/forge/example.com
git pull origin master
composer dump-autoload
composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader
php artisan cache:clear
php artisan route:cache
php artisan view:clear
php artisan migrate --force
Dave97's avatar

@ejdelmonico I just tried now with the following script (How do you format code as yours on Laracast?):

'cd /home/forge/default

git pull origin master

composer dump-autoload

composer install

php artisan migrate --force

echo "" | sudo -S service php7.2-fpm reload'

but still the same error : 'In PackageManifest.php line 165:

The /home/forge/default/bootstrap/cache directory must be present and writa ble.

Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1'

When SSHing my server with same command, i got same error too

ejdelmonico's avatar

Hmm, that is odd. First, I never recommend using the default site because you will have problems with SSL site verification. One thing you could do is create a second site with your site name like example.com and setup up everything and see if you have the same issues. If it's fine then use that and delete the default site. Otherwise, you know it is either your repo or the forge server.

Dave97's avatar

@ejdelmonico Yes i tried with deploying on another site instead of default but same access error. Thks for the try.

I drop a line to Forge customer service: when solved i will post the feedback

Dave97's avatar

@ejdelmonico

I managed to go a little further in installation but now failing with 404 not found :

Step followed :

1)Install project without dependencies otherwise it fails

2)Deploy script used :

cd /home/forge/www.site.com git pull origin master composer dump-autoload composer install php artisan migrate --force echo "" | sudo -S service php7.2-fpm reload

deployment fails but the folder 'storage' get created and accessible.

3)I create with mkdir the missing folders frameworks, cache, views and sessions in folder storage.

4)Deploying : no deployment error (nothing to migrate message) message but error 404

5)so modifying the NGINX file: Replace the

listen 80; listen [::]:80; by listen 80 default_server; listen [::]:80 default_server;

Result : I got the Laravel formatted text : " Whoops, looks like something went wrong. " so it is getting closer to site working but still not.

As the site is working on my local server, i would like to know which files are different and need to be checked usually on the production server?

For example the.env file of production server : is it normal to have following? APP_URL=http://localhost DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306

Thks for help

ejdelmonico's avatar

Well, for production, I usually change the APP_URL to match the site url so that the project base path is correct. For the DB, yes, those are the normal values for MySQL in Ubuntu server. On a side note, Forge provisioning does all of the Nginx configurations for you, you shouldn't have to modify it except to add more aggressive caching. Essentially, you shouldn't have to do any modifications except to setup the deployment process. Are you installing Laravel differently than what is expected by Forge? I have many servers managed by Forge and the only issue that ever pops up is whether or not to do a composer install (which you would not with Spark).

Dave97's avatar

@ejdelmonico

1)Install the site without composer dependencies otherwise install failure => site installed but the storage folder is not present

2)Modify deploy script :

  • 'cd /home/forge/example
  • git pull origin master
  • composer install
  • php artisan migrate --force
  • echo "" | sudo -S service php7.2-fpm reload' =>deployment failed with : 'Please provide a valid cache path' but folder storage is present and writable again.
  1. create manually in storage folder, the subfolder Frameworks and cache, sessions, views then deploy with same script : => 'Package manifest generated successfully. Nothing to migrate.'

  2. But still the site is not displaying : 404 not found

5)I have seen the folder assets is missing in public folder, so through SSH CLI :

  • npm install
  • npm run production (in the deploy script it doesnt succeed) and the folder asset get created.

6)Site is live by IP address (Still the issue that it doesnt work with the hostname configured in the registrar)

I did this process many times removing some steps or writing everything in the deploy script without using the ssh cli command but then it will fail.

I would like to understand what is the issue

Dave97's avatar

Can you please provide an example of your gitignore file? I feel it is not normal that following folders are excluded in my gitignore causing so errors:

public/assets

public/mix-manifest.json

/public/hot

/public/storage

ejdelmonico's avatar
Level 53

Here is a typical one that I use in a Laravel project:

/node_modules
/public/storage
/public/hot
/public/css/app.css
/public/fonts
/public/js/app.js
/storage/\*.key
/storage/purify
/vendor
/.idea
Homestead.json
Homestead.yaml
.env
.DS_Store
_ide_helper.php
.phpstorm.meta.php
.php_cs.cache
yarn-error.log

FYI: I had to escape the * for display purposes.

Dave97's avatar

Ok, it makes sense.

If you exclude your public from git, it means you have to run npm on server, as i had to do to generate the contents after creating these missing folders. (I didnt have the / of /public, this might be the reason why the empty folder didnt exist in my git so i had to create them through ssh before running npm)

I understand there are 2styles : People who want to run npm locally and include the public assets in their git and other people who exclude these folders but run npm on server. Thanks for you patience

Dave97's avatar

I understood the issue, the culprit are the following files in my gitignore :

/storage/

/storage/debugbar/

/storage/framework/views/

/storage/framework/sessions/

/public/assets

/public/mix-manifest.json

/public/hot

With above instructions each folder with its content is excluded from git and not pushed in my bucket.So the reason why i had to re create them through SSH.

But for Forge to properly work, we need to have these folder structure uploaded (but being empty, the reason why they all have a .gitignore inside them). So I shouldnt have these instructions in my main gitignore file.By removing them I am able to deploy successfully with Composer dependencies ticked in Forge

It seems also that Forge do a npm run install, npm run production automatically during the deployment as the folders are populated on the server. So no need to run this command manually anymore.

Now everything is fine. Thank you I learnt a lot on Forge during these investigations

Please or to participate in this conversation.