Failed to open stream


#1

Hello,
I’m just starting with CakePHP but having trouble running my first testing application.
I have creates a new PROJECT using

php composer.phar create-project --prefer-dist cakephp/app test

apparently with success, but when I enter the site, I see the following error:

**Warning** : require(/var/www/html/test/vendor/autoload.php): failed to open stream: No such file or directory in **/var/www/html/test/webroot/index.php** on line **31**

**Fatal error** : require(): Failed opening required '/var/www/html/test/vendor/autoload.php' (include_path='.:/usr/share/php') in **/var/www/html/test/webroot/index.php** on line **31**

I verified and the mentioned file:
/var/www/html/test/vendor/autoload.php
does not exist, perhaps It should, I think.

Please, can someone tell me How can I fix it?


#2

how did you install cake? did you used method from book?
https://book.cakephp.org/3.0/en/installation.html#create-a-cakephp-project

EDIT:
woop sorry tried to reply too fast,
you can try
composer dumpautoload


#3

Thanks for your reply, Graziel,
I used the mentioned method:

]php composer.phar create-project --prefer-dist cakephp/app test

as mentioned in the documentation.
I’ve forgot to execute the following (also mentioned in documentation):

]bin/cake server

That is not found, because I don’t know where was CakePHP installed.

]

#4

and what about
composer dumpautoload ?


#5

/var/www/html$ composer dumpautoload
Composer could not find a composer.json file in /var/www/html
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ “Getting Started” section

I told installing CakePHP was an easier task.


#6

and what about

php composer.phar dumpautoload

cake installation is strightforward but your composer is not installed globally


#7

Thanks,
I executed the following, inside one of my projects, that contain a composer.json file:

composer dumpautoload

and this is the output:

Generating autoload files Class Cake\Composer\Installer\PluginInstaller is not autoloadable, can not call post-autoload-dump script

There is still something missing, I guess


#8

try to add it manually

composer require cakephp/plugin-installer:*


#9

If @Graziel’s suggestion doesn’t work, would you mind posting your composer.json?


#10

Fine
I executed:

and the response:
[CODE[Using version ^1.1 for cakephp/plugin-installer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing cakephp/plugin-installer (1.1.0): Downloading (100%)         
Writing lock file
Generating autoload files

then

$ composer dumpautoload Generating autoload files $ bin/cake server
at last, the command indicated in the book
[/CODE]
bash: bin/cake: No existe el archivo o el directorio
[/CODE]
that is: file or directory does not exist


#11

try running composer require cakephp/bake


#12

Fine, executed command

composer require cakephp/bake

with no flaws.

I Now have generated a new project:
bookmarker
using command:

php composer.phar create-project --prefer-dist cakephp/app bookmarker

successfully, at least in appearance.
When I open site
http://localhost/bookmarker/
I get the following response:

**Warning** : require(/var/www/html/bookmarker/vendor/autoload.php): failed to open stream: No such file or directory in **/var/www/html/bookmarker/webroot/index.php** on line **31**

**Fatal error** : require(): Failed opening required '/var/www/html/bookmarker/vendor/autoload.php' (include_path='.:/usr/share/php') in **/var/www/html/bookmarker/webroot/index.php** on line **31**

So, I suspect composer is not creating missing file
autoload.php
… and maybe others.


#13

Including my composer.json file would be a good idea, how can I do that?


#14

open it in your IDE and slap it here between three backticks.


#15
{
    "name": "cakephp/app",
    "description": "CakePHP skeleton app",
    "homepage": "https://cakephp.org",
    "type": "project",
    "license": "MIT",
    "require": {
        "php": ">=5.6",
        "cakephp/cakephp": "3.6.*",
        "cakephp/migrations": "^2.0.0",
        "cakephp/plugin-installer": "^1.0",
        "josegonzalez/dotenv": "3.*",
        "mobiledetect/mobiledetectlib": "2.*"
    },
    "require-dev": {
        "cakephp/bake": "^1.1",
        "cakephp/cakephp-codesniffer": "^3.0",
        "cakephp/debug_kit": "^3.15.0",
        "psy/psysh": "@stable"
    },
    "suggest": {
        "markstory/asset_compress": "An asset compression plugin which provides file concatenation and a flexible filter system for preprocessing and minification.",
        "dereuromark/cakephp-ide-helper": "After baking your code, this keeps your annotations in sync with the code evolving from there on for maximum IDE and PHPStan compatibility.",
        "phpunit/phpunit": "Allows automated tests to be run without system-wide install."
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Test\\": "tests/",
            "Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
        }
    },
    "scripts": {
        "post-install-cmd": "App\\Console\\Installer::postInstall",
        "post-create-project-cmd": "App\\Console\\Installer::postInstall",
        "post-autoload-dump": "Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump",
        "check": [
            "@test",
            "@cs-check"
        ],
        "cs-check": "phpcs --colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
        "cs-fix": "phpcbf --colors --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
        "test": "phpunit --colors=always"
    },
    "prefer-stable": true,
    "config": {
        "sort-packages": true
    }
}

#16

Seems like it’s pretty much the same as mine.
You could try to remove everything in the directory but the composer.json (so only leaving the composer.json) then running composer install.
It should download everything again and have you start with everything needed.