Skip to content
This repository has been archived by the owner on Aug 12, 2019. It is now read-only.

Installation stop #277

Open
acarlomagno opened this issue Jun 16, 2015 · 39 comments
Open

Installation stop #277

acarlomagno opened this issue Jun 16, 2015 · 39 comments

Comments

@acarlomagno
Copy link

Hi,
During install procedure via browser (install.php), after user and db parameters .. when I click install, display this error and does not end the installation

"An error occured: fstat() expects parameter 1 to be resource, boolean given"

Clean machine with LAMP Ubuntu and all dependencies

thanks
AC

@acarlomagno
Copy link
Author

Hi,
via command line ... install works fine ..

@Hywan Hywan added this to the 0.4.0 milestone Jun 17, 2015
@Hywan Hywan self-assigned this Jun 17, 2015
@Hywan
Copy link
Member

Hywan commented Jun 17, 2015

Hello :-),

Are you sure the permissions are correct? Did you grab the project from an archive (ZIP or PHAR) or directly from Github?

@acarlomagno
Copy link
Author

Hello,
I clone from git .... If I use the command line installer ... works fine .

What are permissions that I must to use ?

@evert
Copy link
Member

evert commented Jun 18, 2015

The real problem here is lack of proper feedback. Basically, the webserver needs to have full write access to everything in the data/ directory.

@acarlomagno
Copy link
Author

yes, I set full write access to data/

@Hywan
Copy link
Member

Hywan commented Jun 22, 2015

Sorry I was absent these days because I am a fresh new father 😉.
Please, can you provide me your OS and your PHP version? I will try to reproduce.

@Hywan
Copy link
Member

Hywan commented Jun 22, 2015

(OS is Ubuntu ok)

@acarlomagno
Copy link
Author

Hello Hywan, congratulation for birth !

this is phpinfo of my server: http://178.62.61.170/info.php

@Hywan
Copy link
Member

Hywan commented Jun 23, 2015

Do you have the same issue while installing from the archive instead of the Git repository?

@acarlomagno
Copy link
Author

I have not tried ... on GIt web and command line ... command line works fine

@naevtamarkus
Copy link

Hi, I have the same issue.
I installed with unzip, changed ownership to the webserver uid (chown http.http data -R) and run the installer.php from a browser.
I can see that the data/ dir was populated by the installer:

drwxr-xr-x 7 http http 4096 2015-06-25 08:32 .
drwxr-xr-x 9 root root 4096 2015-06-25 08:32 ..
drwxr-xr-x 2 http http 4096 2015-06-25 08:56 configuration
drwxr-xr-x 2 http http 4096 2015-06-25 08:56 database
drwxr-xr-x 2 http http 4096 2015-06-25 08:32 home
drwxr-xr-x 2 http http 4096 2015-06-25 08:56 log
drwxr-xr-x 3 http http 4096 2015-06-25 08:32 share

8:32 is the unzip time, and 8:56 is the install.php time.

The webserver is a Synology station:

# php -version
PHP 5.5.22 (cli) (built: May 12 2015 15:34:24) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies
# uname -a
Linux Hostname 2.6.32.12 #5055 Tue May 12 15:22:35 CST 2015 armv5tel GNU/Linux

Hope it helps!

@DominikTo
Copy link
Member

I am able to reproduce this issue with the master branch on OS X (running built-in php and mysql) like this:

git clone git@github.com:fruux/sabre-katana.git
cd sabre-katana/
make install

Open http://foo.bar/install.php in the browser.

Run chmod -R a+rw data/

Reload http://foo.bar/install.php in the browser (warning about not writeable /data directory is now gone).

Give the installer all the necessary data and choose MySQL.

An error occured: fstat() expects parameter 1 to be resource, boolean given

screen shot 2015-07-04 at 16 11 39

Reloading the installer page in the browser however then returns:

sabre/katana is already installed
Surprisingly, you cannot install this software twice.

What's next? Go manage your server with the administration interface.

Logging in doesn't work though, because the database has not been set up. Maybe this is also the root cause of #279.

@chikamichi
Copy link

@DominikTo I reproduce the same error, while using the browser-based installer (which I hadn't use so far).

@DominikTo
Copy link
Member

The last message that the installer emits before the error appears is:

So the problem must be related to:

@chikamichi
Copy link

Maybe a missing file / wrong path at some point during the process? fstat could complain about that.

edit: the problem may be with the getTemplateSchemaIterator from Database, so maybe something related to Hoa\File\Finder?

@DominikTo
Copy link
Member

If I had a way to easily convince sabre-katana to give me a stack trace or any helpful output at all, this would probably be quite easy to debug. :-) /cc @Hywan

This is the response body for the failing install.php request:

HTTP/1.1 200 OK
Date: Sat, 04 Jul 2015 15:36:41 GMT
Server: Apache/2.4.12 (Unix) PHP/5.5.24
X-Powered-By: PHP/5.5.24
Transfer-Encoding: identity, chunked
Cache-Control: no-cache
X-Accel-Buffering: no
Keep-Alive: timeout=5, max=79
Connection: Keep-Alive
Content-Type: text/event-stream

4d
event: step
data: {"percent":5,"message":"Create configuration file\u2026"}


57
event: step
data: {"percent":25,"message":"Configuration file created \ud83d\udc4d!"}


48
event: step
data: {"percent":30,"message":"Create the database\u2026"}


7a
event: step
data: {"percent":-1,"message":"An error occured: fstat() expects parameter 1 to be resource, boolean given"}


0

@DominikTo
Copy link
Member

Here's the stack trace for this issue:

fstat() expects parameter 1 to be resource, boolean given

#0 /sabre-katana/vendor/hoa/core/Core.php(391): Hoa\Core\Exception\Idle::error(2, 'fstat() expects parameter 1 to be resource, boolean given', '/sabre-katana/vendor/hoa/core/Protocol.php', 843, Array)
#1 unknown file(unknown line): Hoa\Core\Core::Hoa\Core\{closure}(2, 'fstat() expects parameter 1 to be resource, boolean given', '/sabre-katana/vendor/hoa/core/Protocol.php', 843, Array)
#2 /sabre-katana/vendor/hoa/core/Protocol.php(843): fstat(false)
#3 unknown file(unknown line): Hoa\Core\Protocol\Wrapper->stream_stat()
#4 /sabre-katana/vendor/hoa/file/ReadWrite.php(231): stream_get_contents(Resource id #76, -1, 0)
#5 /sabre-katana/lib/Server/Installer.php(416): Hoa\File\ReadWrite->readAll()
#6 /sabre-katana/public/install.php(211): Sabre\Katana\Server\Installer::createDatabase(Sabre\Katana\Configuration)
#7 unknown file(unknown line): {closure}('{"baseurl":"/server.php/","email":"admin@example.org","password":"admin","database":{"driver":"mysql","host":"127.0.0.1","port":"3306","name":"sabre-katana","username":"root","password":""}}')
#8 unknown file(unknown line): Closure->__invoke('{"baseurl":"/server.php/","email":"admin@example.org","password":"admin","database":{"driver":"mysql","host":"127.0.0.1","port":"3306","name":"sabre-katana","username":"root","password":""}}')
#9 /sabre-katana/vendor/hoa/dispatcher/Basic.php(255): ReflectionMethod->invokeArgs(Closure, Array)
#10 /sabre-katana/vendor/hoa/dispatcher/Dispatcher.php(149): Hoa\Dispatcher\Basic->resolve(Array, Hoa\Router\Http\Http, NULL)
#11 /sabre-katana/public/install.php(301): Hoa\Dispatcher\Dispatcher->dispatch(Hoa\Router\Http\Http)

@chikamichi
Copy link

Looking at data/log/TIMESTAMP.exceptions.log, I have:

[2015-07-04T15:54:04+00:00] "fstat() expects parameter 1 to be resource, boolean given" vendor/hoa/core/Protocol.php:843

so it's consistent at least. I wouldn't be surprised if a template's name was mistyped or something. I'm just discovering the codebase though.

@DominikTo
Copy link
Member

Guessing from the stack trace, things seem to start going wrong here:

Installer.php(416): Hoa\File\ReadWrite->readAll() which calls readAll() in hoa/file, which then eventually calls stream_stat() in hoa/core and for some reason $this->getStream() in there does not return a stream, but instead false.

@evert
Copy link
Member

evert commented Jul 4, 2015

It's time to rip out the katana:// stuff.

@DominikTo
Copy link
Member

Seems to happen right for the first file, might be related to the katana:// protocol stuff somehow. There's a bit too much magic going on for me at 38° Celsius and with no AC. :-)

Hoa\File\SplFileInfo Object
(
    [_stream:protected] => 
    [_hash:protected] => 6f20308b448da6182ce8b795b795170c
    [_relativePath:protected] => katana://resource/default/database/
    [pathName:SplFileInfo:private] => katana://resource/default/database/addressbooks.mysql.sql
    [fileName:SplFileInfo:private] => addressbooks.mysql.sql
)

@DominikTo
Copy link
Member

Yea I'd be sympathetic to that. it's quite hard to debug and has been the source of similar issues before, iirc.

@chikamichi
Copy link

Locally, I have the error but not for addressbooks.mysql.sql. I set a debug on $driverName within getTemplateSchemaIterator, and on the $templateSchema's pathName within createDatabase.

When using sqlite and the browser install, I get:

Driver: sqlite
Schema: katana://resource/default/database/propertystorage.sqlite.sql

Then, it fails.


Edit: With mysql, it's on:

Driver: mysql
Schema: katana://resource/default/database/calendars.mysql.sql

Dunno if that's relevant.

@DominikTo
Copy link
Member

Same error, @chikamichi. Just for SQLite instead of MySQL. That it fails on a different file for you when selecting MySQL is just related to which file it tries to load first.

@chikamichi
Copy link

I'm not sure about my finding, but still, food for thoughts. In hoa's Core/Protocol, within stream_open, the mode is a bit weird and could explain the false flag we've seen passed around. $mode is provided as a+b when opening a stream for a file from resource/default/database, which is unlike any expected mode by PHP's fopen. On top of that, at line 784 of stream_open, a check is made prior to calling fopen:

$path = static::realPath($path, 'r' === $mode[0]);

This is where the code breaks. Looking at the doc for realPath, it appears it will return false if the file is not reachable, accounting for the specified mode.

@chikamichi
Copy link

When releasing the constraint on $mode[0] (that is, calling only static::realPath($path)) also fails.

@DominikTo
Copy link
Member

Also just realized that the schema files unnecessarily get opened in read-write mode in Installer.php(416), which probably happens here inside hoa/file. When the same code runs via the CLI installer (where unlike when running that code via Apache we actually have a write permission for those schema files), the problem does not occur.

We're running an awful lot of code here, just to read a few files from disk. Should indeed simplify this. =)

@chikamichi
Copy link

Indeed :)

I'm still digging around that realPath thing, hoa's code is not that straightforward either.

@chikamichi
Copy link

Oh! By the way, I managed to fix the issue simply by changing the file mode for the templates under resource/default/database. It's not perfect, because those templates shouldn't need +w but that's a workaround at least. I guess that is related to the use of hoa's ReadWrite?

@Hywan
Copy link
Member

Hywan commented Jul 5, 2015

So it fails with MySQL but not with SQLite?

I am going to patch Hoa\Core\Protocol to trigger a better error with fstat. PHP is not very verbose here ;-).

@Hywan
Copy link
Member

Hywan commented Jul 5, 2015

@evert @DominikTo katana:// saved our asses several times since the beginning of this project. I would not recommend to remove it. Yes we use an iterator of files, which is basically an FilesystemIterator instance of SplFileInfo objects. This is testable and the best way to abstract stuff in this case (iterating over SQL schemas). I am going to fix this issue as fast as possible and everything will be good :-).

@Hywan
Copy link
Member

Hywan commented Jul 5, 2015

Go create a a.php file at the root of the project, write the following content:

<?php

require 'bootstrap.php';

use Sabre\Katana;

$sqlite = new Katana\Database('sqlite::memory:');
print_r(
    iterator_to_array(
        $sqlite->getTemplateSchemaIterator()
    )
);

$mysql = new Katana\Database('mysql:host=127.0.0.1');
print_r(
    iterator_to_array(
        $mysql->getTemplateSchemaIterator()
    )
);

It works for me. Does it work for you?

@Hywan
Copy link
Member

Hywan commented Jul 5, 2015

Trying with:

<?php

require 'bootstrap.php';

use Sabre\Katana;

$sqlite = new Katana\Database('sqlite::memory:');

foreach ($sqlite->getTemplateSchemaIterator() as $file) {
    var_dump($file->open()->readAll());
}

$mysql = new Katana\Database('mysql:host=127.0.0.1');

foreach ($mysql->getTemplateSchemaIterator() as $file) {
    var_dump($file->open()->readAll());
}

If one file has not the read permission, it fails. Is it your usecase? Why resource/ does not have the read permissions? Oh, because of Apache… Hmm. So this bug has been introduced since we moved files from data/ to resource/. Do you agree?

@Hywan
Copy link
Member

Hywan commented Jul 5, 2015

Two solutions: Either we check that resource/ is also readable (something equivalent to what we do here but checking readability instead of writability), or… hmm, the other is too much complicated. Thoughts?

@DominikTo
Copy link
Member

No, it fails both for MySQL as well as SQLite, see the comment from @chikamichi above.

@Hywan
Copy link
Member

Hywan commented Jul 5, 2015

Error message fixed by https://github.com/hoaproject/Core/releases/tag/2.15.07.05. Run composer update and you will see a nice error message, like:

Hoa\File\File::_open(): (2) Failed to open stream katana://resource/default/database/propertystorage.mysql.sql.

@Hywan Hywan mentioned this issue Jul 5, 2015
2 tasks
@Hywan
Copy link
Member

Hywan commented Jul 5, 2015

If you confirm me that the resource/ directory has not the correct permission for Apache (maybe check the owner), then I will continue #284.

@chikamichi
Copy link

Hum, the way I ran things is I installed sabre-katana in ~/opt/, and used the same user to both install and run the CLI install. It was failing, so I decided to set up an apache vhost in /etc/apache2/ using sudo--but the DocumentRoot is ~/opt/sabre-katana/public. Both ways (CLI install and browser install), it was failing (mysql and sqlite). I'm a bit confused as to why running chmod 666 resource/default/database (I guess 664 would work with Apache/www-data) fixed the issue, though.

@Hywan
Copy link
Member

Hywan commented Jul 13, 2015

@chikamichi Ok, I get it. Because Apache needs to have appropriated permissions to read files too. On some configurations, Apache is inside an isolated group and has not the correct permissions to even read files. So, as the same way we check the data/ directory is writable, we also need to check that the resource/ directory is readable. That's a little bit disturbing because the lib/ directory will have the same level of permissions and it is readable by Apache… Since @DominikTo was able to reproduce, I will follow its steps. It will be easy to avoid and fix the issue but much more harder to understand why it happens exactly :-/.

@evert evert modified the milestones: 0.4.0, 0.5.0 Oct 21, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants