AlphaReign / www-php

The website of AlphaReign
56 stars 24 forks source link

missing hosts variable #3

Closed agilob closed 7 years ago

agilob commented 7 years ago

Hi,

I'm trying to build a complete docker image with scraper and website. I got scraper working correctly, it download all metadata and ES works correctly too, but when I try to connect to www-php

browser -> nginx-proxy -> docker -> nginx it fails to set hosts variable, the error I'm getting is

2017/05/16 08:58:37 [error] 2136#2136: *23 FastCGI sent in stderr: "PHP message: PHP Warning:  Missing argument 1 for Elasticsearch\ClientBuilder::setHosts(), called in /srv/www/middleware/es.php on line 6 and defined in /srv/www/vendor/elasticsearch/elasticsearch/src/Elasticsearch/ClientBuilder.php on line 344
PHP message: PHP Notice:  Undefined variable: hosts in /srv/www/vendor/elasticsearch/elasticsearch/src/Elasticsearch/ClientBuilder.php on line 346" while reading response header from upstream, client: 172.17.0.1, server: alpha, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "host.com"

The website just shows:

Oops!
Looks like we ran into a little issue. Please try again later.
Home

nginx in docker uses nginx.conf file you provided in the repo, my proxy config in main nginx is:

upstream alpha {
  server 127.0.0.1:8888;
}

...

location ~ /alpha/(?<ndpath>.*) {
  proxy_redirect off;
  proxy_set_header                  Host $host;
  proxy_set_header                  X-Forwarded-Server $host;
  proxy_set_header                  X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_http_version                1.1;
  proxy_set_header Connection       "keep-alive";
  proxy_store                       off;
  proxy_pass                        http://alpha/$ndpath$is_args$args;
}

Any idea what might be wrong with that config?

Raxvis commented 7 years ago

I believe it's not an nginx error but one with PHP accessing ElasticSearch. Look in middleware/es.php and change the ES connection to use the correct host

agilob commented 7 years ago

@Prefinem scraper works correctly and it adds magnets to ES database, ES is run on localhost:9200. How exactly do I hardcode the host in es.php?

Raxvis commented 7 years ago

Line 6 here: https://github.com/AlphaReign/www-php/blob/master/middleware/es.php

setHosts should accepts an ip:port setup

Docs here: https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_configuration.html

agilob commented 7 years ago

When I defined hosts of my ip, hostname or localhost it still fails with status code 500 and doesn't even log anything. I can use ip, hostname to query ES with curl GET /torrents/_search and it works correctly.

Raxvis commented 7 years ago

You will probably need to ensure that your ES is inside the same docker container as the php app or give it an external IP

agilob commented 7 years ago

Yup, www-php, scraper, ES, nginx and mariadb is in one container, I wanted to make it work out-of-box, just download docker image, start container and it's on.

Raxvis commented 7 years ago

so, for middleware/es.php you should have this line

$this->client = Elasticsearch\ClientBuilder::create()->setHosts('127.0.0.1:9200')->build();

where 9200 is the port that Elasticsearch is running on

agilob commented 7 years ago

If I do what exactly what you said I get:

Elasticsearch\Common\Exceptions\InvalidArgumentException: Hosts parameter must be an array of strings, or an array of Connection hashes.
 in /srv/www/vendor/elasticsearch/elasticsearch/src/Elasticsearch/ClientBuilder.php:623

so I change it to:

$this->client = Elasticsearch\ClientBuilder::create()->setHosts(['127.0.0.1:9200'])->build();

and then I'm getting no error and website still doesn't work.

Oops!
Looks like we ran into a little issue. Please try again later.

Can I email you credentials to potrainer where you could login and connect to bash on the instance? You have full right to refuse if you don't want to spend your time on it of course.

Raxvis commented 7 years ago

Just save the Docker file for your image and send it to me here or in a gist so I can take a look.

But, that error is a good step in the right direction. I just made a change to the www-php/index.php file so if you change displayErrorDetails to true in www-php/settings.php you will see the error.

agilob commented 7 years ago

0Ok, now I'm getting a meaning full error and I think I can go somewhere from here, you can keep the dockerfile and improve it if you want, I was going to make it public on git na dockerhub anyway

#0 /srv/www/lib/rb.php(683): RedBeanPHP\Driver\RPDO->connect()
#1 /srv/www/lib/rb.php(881): RedBeanPHP\Driver\RPDO->runQuery('show tables', Array)
#2 /srv/www/lib/rb.php(902): RedBeanPHP\Driver\RPDO->GetAll('show tables', Array)
#3 /srv/www/lib/rb.php(3448): RedBeanPHP\Driver\RPDO->GetCol('show tables', Array)
#4 /srv/www/lib/rb.php(5636): RedBeanPHP\Adapter\DBAdapter->getCol('show tables')
agilob commented 7 years ago

I had missing dependencies on ubuntu 16.04 it should be apt-get install php7.0-mysqli and mariadb-client not php7.0-mysql and

Raxvis commented 7 years ago

Glad to hear you got it resolved! I will add these to the list

agilob commented 7 years ago

Cheers for help, I made it work out of box in docker instance, pull image and start it, done. Will share it in a few days.

Raxvis commented 7 years ago

Awesome. Glad to hear!

agilob commented 7 years ago

Some suggestions:

To anyone who wants to run this as docker container

Raxvis commented 7 years ago

What are the out of date dependencies for scraper? They should be able to be upgraded.

I removed some of the domain specific stuff from settings.php

agilob commented 7 years ago
➜  scraper git:(master) npm install
npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated minimatch@0.2.14: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated graceful-fs@1.2.3: graceful-fs v3.0.0 and before will fail on node releases >= v7.0. Please update to graceful-fs@^4.0.0 as soon as possible. Use 'npm ls graceful-fs' to find it in the tree.
Raxvis commented 7 years ago

Ah, those are included by another package. I will have to trace it down. Thanks