3

404 errors with index.php

Submitted by bootes in Postmill

Sorry for being a pain and opening so many threads.

So I finally got it up and running and I can access the main index.php. However Every link on the page comes up 404

9, request: "GET /forums HTTP/1.1", host: "192.168.1.109", referrer: "http://192.168.1.109/"
2018/02/08 20:56:48 [error] 17836#17836: *20 open() "/Postmill/public/login" failed (2: No such file or directory), client: 192.168.1.100, server: 192.168.1.109, request: "GET /login HTTP/1.1", host: "192.168.1.109", referrer: "http://192.168.1.109/"
2018/02/08 20:56:54 [error] 17836#17836: *20 open() "/Postmill/public/forums" failed (2: No such file or directory), client: 192.168.1.100, server: 192.168.1.109, request: "GET /forums HTTP/1.1", host: "192.168.1.109", referrer: "http://192.168.1.109/"
2018/02/08 20:56:56 [error] 17836#17836: *20 open() "/Postmill/public/wiki" failed (2: No such file or directory), client: 192.168.1.100, server: 192.168.1.109, request: "GET /wiki HTTP/1.1", host: "192.168.1.109", referrer: "http://192.168.1.109/"
2018/02/08 20:56:58 [error] 17836#17836: *20 open() "/Postmill/public/new" failed (2: No such file or directory), client: 192.168.1.100, server: 192.168.1.109, request: "GET /new HTTP/1.1", host: "192.168.1.109", referrer: "http://192.168.1.109/"

None of those files exist in the directory:

drwxr-xr-x  6 postmill postmill 4.0K Feb  8 20:12 .
drwxr-xr-x 15 postmill postmill 4.0K Feb  8 20:18 ..
-rw-r--r--  1 postmill postmill 3.3K Feb  8 20:03 apple-touch-icon-precomposed.png
drwxr-xr-x  3 postmill     postmill      20K Feb  8 20:10 build
drwxrwxrwx  2 postmill postmill 4.0K Feb  8 20:12 bundles
-rw-r--r--  1 postmill postmill  21K Feb  8 20:03 check.php
-rw-r--r--  1 postmill postmill 5.4K Feb  8 20:03 favicon.ico
-rw-r--r--  1 postmill postmill 1.4K Feb  8 20:03 index.php
drwxrwxrwx  3 postmill postmill 4.0K Feb  8 20:12 js
-rw-r--r--  1 postmill postmill  116 Feb  8 20:03 robots.txt
drwxr-xr-x  2 postmill postmill 4.0K Feb  8 20:12 submission_images

Comments

You must log in or register to comment.

1

WindTalk wrote (edited )

ok, so I did a complete setup of PHP 7.2, PostgreSQL 10.1, nginx/1.10.3 and managed to get Postmill runing via nginx.

  1. my root folder is /home/myuser/PostmillSite0/Postmill (I did a git checkout from /home/myuser/PostmillSite0 folder)
  2. Everything is working fine with the bin/console server:run 0.0.0.0:8000 using my account myuser
  3. Then i went with the bone-stock version of nginx that Ubuntu 16.04 currently provides.
  4. Based on the information you provided, you and I are both running the same version of PHP 7.2 - HOWEVER

I notice something, you are using Ubuntu 17.10? To run a server in public, I think most would go with 16.04 - as it's LTS and there is more documentation out there on it. (I saw your "7.2.2-3+ubuntu17.10.1+deb.sury.org+1" vs mine "7.2.2-3+ubuntu16.04.1+deb.sury.org+1")

I suspect that puts you on a different, newer version, of nginx/1.10.3 - and maybe some alternate configs?

Here is the config I used that was a non-default site. nginx/1.10.3 is providing a simple static file for my default, using what Ubuntu 16.04 setup. http://server4.plasticirony.com - will show that default site.

Now, to wire up PHP and Postmill, I added a second site (same IP Address, same port):

/etc/nginx/sites-available/forum.plasticirony.com

server {
    server_name plasticirony.com forum.plasticirony.com;
    root /home/myuser/PostmillSite0/Postmill/public;

    location / {
        # try to serve file directly, fallback to index.php
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\.php(/|$) {
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;

        # optionally set the value of the environment variables used in the application
        # fastcgi_param APP_ENV prod;
        # fastcgi_param APP_SECRET <app-secret-id>;
        # fastcgi_param DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name";

        # Postmill
        fastcgi_param APP_ENV 'prod';
        fastcgi_param APP_SECRET 'mysecret';
        fastcgi_param SITE_NAME 'forum.PlasticIrony.com';
        fastcgi_param DATABASE_URL 'pgsql://postmill:mydatapassword@127.0.0.1/postmilldb0?serverVersion10.1';
        fastcgi_param MAILER_URL 'smtp://localhost:25?encryption=&auth_mode=';
        fastcgi_param NO_REPLY_ADDRESS 'no-reply@example.com';


        # When you are using symlinks to link the document root to the
        # current version of your application, you should pass the real
        # application path instead of the path to the symlink to PHP
        # FPM.
        # Otherwise, PHP's OPcache may not properly detect changes to
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
        # for more information).
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        # Prevents URIs that include the front controller. This will 404:
        # http://domain.tld/index.php/some-path
        # Remove the internal directive to allow URIs like this
        internal;
    }

    # return 404 for all other php files not matching the front controller
    # this prevents access to other php files you don't want to be accessible.
    location ~ \.php$ {
        return 404;
    }

    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;
}

And, it's working fine off of http://forum.PlasticIrony.com - and responding correctly. I did waste 30 minutes figuring out that the proper PHP 7.2 path for /var/run/php/php7.2-fpm.sock - but once I solved that issue, Postmill started working file via nginx.

My Ubuntu 16.04 server has only 1GB of RAM, so I'm running Postmill on Nginx off of less than what you are attempting.

cat /proc/meminfo

MemTotal:        1048576 kB
MemFree:          501372 kB
Cached:           126480 kB
Buffers:               0 kB
Active:            84096 kB
Inactive:         131424 kB
Active(anon):      34932 kB
Inactive(anon):    54108 kB
Active(file):      49164 kB
Inactive(file):    77316 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       1048576 kB
SwapFree:        1034996 kB
Dirty:             42252 kB
Writeback:             0 kB
AnonPages:         89040 kB
Shmem:            316680 kB
Slab:              14984 kB
SReclaimable:       3744 kB
SUnreclaim:        11240 kB
1

emma wrote (edited )

BORN TO DIE

WORLD IS A FUCK

鬼神 Kill Em All 1989

I am trash man

410,757,864,530 DEAD COPS

1

bootes wrote (edited )

server {
    listen 80;
    server_name 192.168.1.109;
    root /Postmill/public;
    index index.php;
    location / {
        # try to serve file directly, fallback to index.php
        #try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\.php(/|$) {
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_param APP_ENV 'prod';
        fastcgi_param APP_SECRET 'xxx';
        fastcgi_param SITE_NAME 'TestSite';
        fastcgi_param DATABASE_URL 'pgsql://xxx:xxx@localhost:5432/postmill?serverVersion=10';
        fastcgi_param MAILER_URL 'smtp://localhost:25?encryption=&auth_mode=';
        fastcgi_param NO_REPLY_ADDRESS 'no-reply@example.com';
        include fastcgi_params;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        internal;
    }

    # return 404 for all other php files not matching the front controller
    # this prevents access to other php files you don't want to be accessible.
    location ~ \.php$ {
        return 404;
    }

   error_log /var/log/nginx/project_error.log;
   access_log /var/log/nginx/project_access.log;
}



1

WindTalk wrote

You get this resolved.. you need help?

I currently have an empty Ubuntu 16.04 server I can try to setup nginx on to compare notes with.

3

bootes wrote

Not yet. I have not had a chance to try this yet. Im planning on this weekend giving it a go.

2

bootes wrote

I got it up and running now sorta. I figured out the permissions issues, but Now Im running into memory issues with PHP. Since Im running it on a test VM, I figured thats the problem , even with 4g dedicated to it...but still.

I 've got a raspberry PI for some other projects comming. I'll wait till then.

1

WindTalk wrote (edited )

4GB of memory? I'm running fine on 0.8GB. It isn't even touching that. With apache2.

What is top telling you? is it PostgreSQL using all the memory or nginx? Try apache2?

1

bootes wrote

Im not sure on top, I'll give that a check. But the error Im getting is

Fatal error: Out of memory (allocated 17039360) (tried to allocate 77824 bytes) in /postmill

I have my php.ini memory limit set to -1

1

WindTalk wrote

Fatal error: Out of memory (allocated 17039360) (tried to allocate 77824 bytes) in /postmill

That's only 17MB. Maybe post output of: cat /proc/meminfo

1

bootes wrote

ok. Finally got the exact error:

2018/02/28 07:39:51 [error] 2158#2158: *17 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /Postmill/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 109
PHP message: PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 32768 bytes) in /Postmill/vendor/symfony/debug/Exception/OutOfMemoryException.php on line 1" while reading response header from upstream, client: 192.168.1.100, server: 192.168.1.109, request: "GET /login HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.2-fpm.sock:", host: "192.168.1.106"
$  cat /proc/meminfo
MemTotal:        4039996 kB
MemFree:         1599136 kB
MemAvailable:    2040880 kB
Buffers:           84896 kB
Cached:           579648 kB
SwapCached:            0 kB
Active:           622112 kB
Inactive:         447528 kB
Active(anon):     439524 kB
Inactive(anon):    30144 kB
Active(file):     182588 kB
Inactive(file):   417384 kB
Unevictable:     1210420 kB
Mlocked:         1210420 kB
SwapTotal:       1043964 kB
SwapFree:        1043964 kB
Dirty:                 4 kB
Writeback:             0 kB
AnonPages:       1615536 kB
Mapped:           116184 kB
Shmem:             36372 kB
Slab:             117284 kB
SReclaimable:      89756 kB
SUnreclaim:        27528 kB
KernelStack:        4336 kB
PageTables:        13224 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     3063960 kB
Committed_AS:    2435176 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
HardwareCorrupted:     0 kB
AnonHugePages:    212992 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       71616 kB
DirectMap2M:     4122624 kB
1

WindTalk wrote

Allowed memory size of 134217728 bytes exhausted

128MB is standard memory limit for PHP, and apps like Drupal run fine with that amount. So, I'm thinking something else. However, try removing the limit

  1. run "php --ini" to confirm you are using the INI you think you are. What's your version of php? "php -v"
  2. Just to see if problem goes away, change memory_limit in php.ini to -1 and see if that changes behavior.
2

bootes wrote

php -v

PHP 7.2.2-3+ubuntu17.10.1+deb.sury.org+1 (cli) (built: Feb 6 2018 16:11:55) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.2-3+ubuntu17.10.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

php -ini

$ php -i-ini phpinfo() PHP Version => 7.2.2-3+ubuntu17.10.1+deb.sury.org+1

System => Linux reddit 4.13.0-32-generic #35-Ubuntu SMP Thu Jan 25 09:13:46 UTC 2018 x86_64 Build Date => Feb 6 2018 16:11:55 Server API => Command Line Interface Virtual Directory Support => disabled Configuration File (php.ini) Path => /etc/php/7.2/cli Loaded Configuration File => /etc/php/7.2/cli/php.ini

$ cat /etc/php/7.2/cli/php.ini | grep 'memory_limit'

memory_limit = -1

1

emma wrote (edited )

BORN TO DIE

WORLD IS A FUCK

鬼神 Kill Em All 1989

I am trash man

410,757,864,530 DEAD COPS