nginx serving 404 pages - php

EDIT: Based on #Devons advice I ran the following commands with no errors (found in this post):
$ sudo find /var/public/www -type d -exec chmod 755 {} +
$ sudo find /var/public/www -type f -exec chmod 644 {} +
But when I list the files inside www the permissions still look wrong. What am I doing wrong? Thanks!
drwxrwx--- 1 root vboxsf 4096 Aug 28 12:45 app
-rwxrwx--- 1 root vboxsf 1646 Aug 28 12:45 artisan
drwxrwx--- 1 root vboxsf 0 Aug 28 12:45 bootstrap
-rwxrwx--- 1 root vboxsf 1201 Aug 28 12:45 composer.json
-rwxrwx--- 1 root vboxsf 105046 Aug 28 12:55 composer.lock
drwxrwx--- 1 root vboxsf 4096 Aug 28 12:45 config
drwxrwx--- 1 root vboxsf 0 Aug 28 12:45 database
-rwxrwx--- 1 root vboxsf 503 Aug 28 12:45 gulpfile.js
-rwxrwx--- 1 root vboxsf 159 Aug 28 12:45 package.json
-rwxrwx--- 1 root vboxsf 87 Aug 28 12:45 phpspec.yml
-rwxrwx--- 1 root vboxsf 899 Aug 28 12:45 phpunit.xml
drwxrwx--- 1 root vboxsf 0 Aug 28 12:45 public
-rwxrwx--- 1 root vboxsf 1928 Aug 28 12:45 readme.md
drwxrwx--- 1 root vboxsf 0 Aug 28 12:45 resources
-rwxrwx--- 1 root vboxsf 567 Aug 28 12:45 server.php
drwxrwx--- 1 root vboxsf 0 Aug 28 12:45 storage
drwxrwx--- 1 root vboxsf 0 Aug 28 12:45 tests
drwxrwx--- 1 root vboxsf 4096 Aug 28 12:56 vendor
This is my first time with nginx and cannot get laravel welcome page to show. I am using ubuntu 14.04 and VBox 5.
I have my server configured in /var/nginx/sites-enabled/default as
server {
listen 80 default_server;
charset utf-8;
server_name doimain.app www.domain.app;
root /var/www/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Inside /var/www/public I can list the laravel public folder files
$ ls -l /var/www/public
total 3
-rwxrwx--- 1 root vboxsf 0 Aug 28 12:45 favicon.ico
-rwxrwx--- 1 root vboxsf 1786 Aug 28 12:45 index.php
-rwxrwx--- 1 root vboxsf 24 Aug 28 12:45 robots.txt
But I get 404 when I go to domain.app. The nginx error log shows:
2015/08/28 14:29:35 [crit] 1487#0: *14 stat() "/var/www/public/index.php" failed (13: Permission denied), client: 10.0.0.18, server: domain.app, request: "GET / HTTP/1.1", host: "domain.app"
I have tried without success the following:
Ensure www-data owns the folder structure /var/www
$ sudo chown www-data:www-data /var/www
Changed access rights to /var/www
$ sudo chmod -R 0755 /var/www
Thanks!

The public directory is owned by root and is not readable to others. You either need to change the ownership to www-data or chmod all of the folder and files. The folder should be 0755 and files be 0644 for most configurations. You can leave it how you have it if the files are owned by the same user running nginx and php (I assume www-data).
Changing the ownership of /var/www by itself does nothing, you have to change all the folders and files in the web directory.
You can chmod and chown recursively with the -R flag.
chown -R www-data:www-data /var/www/public

Solved it by addig www-data user to vboxsf group and restarting the server.
$sudo usermod -G vboxsf -a www-data

Related

Not Found from php:apache (run without a Dockerfile)

Can not serve even a static files from this container. What I'm doing wrong?
I'm running
docker run -d -p 8081:80 --name test -v "$PWD":/var/www/html php:apache
and reciving the next output trying to request any file from $PWD
Not Found
The requested URL was not found on this server.
Apache/2.4.51 (Debian) Server at 0.0.0.0 Port 8081
the $PWD content gets inside a container, but is not served
docker exec -it test ls -l /var/www/html
total 44
-rw-r--r-- 1 root root 65 Sep 22 12:59 checkserver.php
-rw-r--r-- 1 root root 16093 Sep 22 12:59 crest.php
-rw-r--r-- 1 root root 1024 Sep 22 12:59 crestcurrent.php
-rw-r--r-- 1 root root 217 Oct 14 08:45 index.html
-rw-r--r-- 1 root root 516 Sep 22 12:59 index.php
-rw-r--r-- 1 root root 488 Sep 22 12:59 install.php
-rw-r--r-- 1 root root 650 Sep 22 12:59 settings.php
-rw-r--r-- 1 root root 5 Oct 13 17:32 test.txt
I used nginx as a reverse proxy before an Apache container. The problem was in nginx configuration. It started to work after I added the next lines to the configuration.
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://0.0.0.0:8081;
}

Where can I find php-fpm.log and php-fpm.conf on my server?

I think I am having problems with the max children limit for php-fpm. I am trying to find something in the logs. Where can I find php-fpm.log on my server? Running phpinfo() shows this:
I cannot find anything related to php-fpm in /var/log/.
I am also trying to find the php-fpm.conf that is mentioned at https://www.php.net/manual/en/install.fpm.configuration.php. Thank you.
UPDATE 1: I found at https://github.com/rlerdorf/php7dev/issues/48 that it asks to edit /usr/local/etc/php-fpm.d/www.conf. In my case, I cannot find that file:
root#jai [/usr/local/etc]# pwd
/usr/local/etc
root#jai [/usr/local/etc]# ls -al
total 8
drwxr-xr-x. 2 root root 4096 Sep 23 2011 ./
drwxr-xr-x. 15 root root 4096 Apr 7 15:02 ../
Do I need to create it at /usr/local/etc/php-fpm.d/www.conf?
UPDATE 2: I see I have a folder called ApachePHPFPM but the file inside (default_accounts_to_fpm) is empty:
root#jai [/var/cpanel/ApachePHPFPM]# pwd
/var/cpanel/ApachePHPFPM
root#jai [/var/cpanel/ApachePHPFPM]# ls -al
total 16
drwxr-xr-x 2 root root 4096 Mar 26 04:44 ./
drwx--x--x 108 root root 12288 Apr 17 13:44 ../
-rw-r--r-- 1 root root 0 Mar 26 04:44 default_accounts_to_fpm
root#jai [/var/cpanel/ApachePHPFPM]#
UPDATE 3: My server had this file:
/usr/local/cpanel/etc/php-fpm.conf
The file contains this:
; Error log file
; Default Value: /var/log/php-fpm.log
error_log = /usr/local/cpanel/logs/php-fpm/error.log
That means that my error logs for php-fpm are located in this file: /usr/local/cpanel/logs/php-fpm/error.log.
I navigated to /usr/local/cpanel/logs/php-fpm/ but I could not find error.log:
root#jai [/usr/local/cpanel/etc]# cd /usr/local/cpanel/logs/php-fpm/
root#jai [/usr/local/cpanel/logs/php-fpm]# ls -al
total 8
drwx------ 2 root root 4096 Mar 30 2018 ./
drwx--x--x 6 root root 4096 Apr 16 15:24 ../
root#jai [/usr/local/cpanel/logs/php-fpm]#
In /opt/cpanel/ea-php73/root/etc/php-fpm.conf I found this line:
error_log = /opt/cpanel/ea-php73/root/usr/var/log/php-fpm/error.log
I see the error log files there:
root#jai [/opt/cpanel/ea-php73/root/usr/var/log/php-fpm]# pwd
/opt/cpanel/ea-php73/root/usr/var/log/php-fpm
root#jai [/opt/cpanel/ea-php73/root/usr/var/log/php-fpm]# ls -al
total 151456
drwxrwx--- 2 nobody root 4096 Apr 14 17:36 ./
drwxr-xr-x 3 root root 4096 Mar 26 04:42 ../
-rw------- 1 root root 31536068 Apr 17 17:05 error.log
-rw------- 1 root root 32102325 Mar 29 03:26 error.log-20200329
-rw------- 1 root root 51453659 Apr 5 03:36 error.log-20200405
-rw------- 1 root root 39966549 Apr 12 02:55 error.log-20200412
root#jai [/opt/cpanel/ea-php73/root/usr/var/log/php-fpm]#

Laravel Dusk - can't make it run on GitLab CI

Did anyone get to make Laravel Dusk to work on GitLab CI?
I'm using this docker image, which is amazing, but I simply can't execute ./vendor/laravel/dusk/bin/chromedriver-linux, it says:
/bin/bash: line 102: ./vendor/laravel/dusk/bin/chromedriver-linux: No such file or directory
When I enter at ./vendor/laravel/dusk/bin I can see that chromedriver-linux is there and it's executable, but can't make it run.
By now, the script lines that compose this phase are:
- mv .env.testing .env
- php artisan key:generate
- ./vendor/bin/phpunit --colors=never
- php artisan dusk:install
- chmod -R 0755 vendor/laravel/dusk/bin
- ./vendor/laravel/dusk/bin/chromedriver-linux
- php artisan dusk
I've also tried the approaches on documentation, even though they're not for GitLab CI, but none of them worked.
Update:
Running ls -l ./vendor/laravel/dusk/bin returns:
total 33560
-rwxr-xr-x 1 root root 10885776 Jun 26 13:10 chromedriver-linux
-rwxr-xr-x 1 root root 14994520 Jun 26 13:10 chromedriver-mac
-rwxr-xr-x 1 root root 8393728 Jun 26 13:10 chromedriver-win.exe
-rwxr-xr-x 1 root root 69309 Jun 25 22:59 jquery.js
I've tried to copy the file to the machine's current PATH but didn't work either:
Testing the $PATH variable
$ echo $PATH
./vendor/bin:/composer/vendor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Copying the binary to /usr/local/bin
$ CHROME_DRIVER_PATH_BIN=./vendor/laravel/dusk/bin/chromedriver-linux
$ cp $CHROME_DRIVER_PATH_BIN /usr/local/bin
Testing if the file is really there
$ ls -lha /usr/local/bin
total 56564
drwxr-xr-x 1 root root 4.0K Jun 26 17:33 .
drwxr-xr-x 1 root root 4.0K Feb 21 23:08 ..
-rwxr-xr-x 1 root root 10.4M Jun 26 17:33 chromedriver-linux
-rwxr-xr-x 1 root root 1.8M Feb 22 06:40 composer
-rwxrwxr-x 1 root root 118 Feb 21 23:02 docker-php-entrypoint
-rwxrwxr-x 1 root root 1.4K Feb 21 23:02 docker-php-ext-configure
-rwxrwxr-x 1 root root 2.4K Feb 21 23:02 docker-php-ext-enable
-rwxrwxr-x 1 root root 2.3K Feb 21 23:02 docker-php-ext-install
-rwxrwxr-x 1 root root 587 Feb 9 01:57 docker-php-source
lrwxrwxrwx 1 root root 32 Jun 26 17:33 heroku -> /usr/local/lib/heroku/bin/heroku
-rwxr-xr-x 1 root root 817 Feb 21 23:08 pear
-rwxr-xr-x 1 root root 838 Feb 21 23:08 peardev
-rwxr-xr-x 1 root root 751 Feb 21 23:08 pecl
lrwxrwxrwx 1 root root 9 Feb 21 23:08 phar -> phar.phar
-rwxr-xr-x 1 root root 14.5K Feb 21 23:08 phar.phar
-rwxr-xr-x 1 root root 14.3M Feb 21 23:08 php
-rwxr-xr-x 1 root root 14.2M Feb 21 23:08 php-cgi
-rwxr-xr-x 1 root root 2.6K Feb 21 23:08 php-config
-rwxr-xr-x 1 root root 14.4M Feb 21 23:08 phpdbg
-rwxr-xr-x 1 root root 4.5K Feb 21 23:08 phpize
Either way, running chromedriver-linux does not work, I got the error
nohup: can't execute 'chromedriver-linux': No such file or directory
I've tested the same concept on my macOS: created an executable, put it into a folder which is on my PATH variable using a symlink and it works perfectly.
I could solve that installing chromium and chromium-chromedriver packages since they are available on Alpine Linux.
Below is the relevant part of my .gitlab-ci.yml file:
image: lorisleiva/laravel-docker
before_script:
- apk add chromium-chromedriver -y
- apk add chromium -y
phptest:
stage: test
script:
- mv .env.testing .env
- php artisan key:generate
- ./vendor/bin/phpunit --colors=never
- chromedriver 2>&1 &
- sleep 5
- nohup php artisan serve &
- php artisan dusk
Also, a really important part is to add --no-sandbox argument when creating the RemoteWebDriver. This can be done changing the function driver on tests/DuskTestCase.php file:
<?php
// tests/DuskTestCase.php
protected function driver()
{
$options = (new ChromeOptions)->addArguments([
'--disable-gpu',
'--headless',
'--no-sandbox', // # Add this # //
'--window-size=1920,1080',
]);
return RemoteWebDriver::create(
'http://localhost:9515',
DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY,
$options
)
);
}
Just this solved my problem and now I can test with Dusk on GitLab CI using lorisleiva/laravel-docker Docker image.
The Dockerfile for that lorisleiva/laravel-docker image does:
ENV PATH ./vendor/bin:/composer/vendor/bin:$PATH
...
WORKDIR /var/www
So when your script does execute, the '.' in './vendor' might not reference the current working directory you expect.
Since PATH is set, it would be best if chromedriver-linux was in ./vendor/bin instead.
That way, your script can simply call chromedriver-linux (no leading path)

CentOS, Nginx: 403 Forbidden in Laravel's folder

I use laravel new test to establish the Laravel project and move all directories into /usr/share/nginx/html/, the default root directory of Nginx.
In order to check if the config of nginx is correct, I simply the config, trun on autoindex, and put index,html into /usr/share/nginx/html/test/public/, the location of index.php of laravel.
defaul.conf of nginx
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
root /usr/share/nginx/html/test;
index index.html index.htm index.php;
location / {
autoindex on;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
When I access the index.html by localhost/public/, nginx returns me 403. I copy index.html into a new folder named /usr/share/nginx/html/test/public_b, and try to access the new index.html by localhost/public_b/. Nginx returns me the correct content! It is like a miracle. The stats of my directories as the follows.
$ll /usr/share/html/test
total 432
drwxrwxr-x. 6 nginx nginx 84 Feb 26 15:39 app
-rw-rw-r--. 1 nginx nginx 1686 Feb 26 15:39 artisan
drwxrwxr-x. 3 nginx nginx 34 Feb 26 15:39 bootstrap
-rw-rw-r--. 1 nginx nginx 1512 Feb 26 15:39 composer.json
-rw-rw-r--. 1 nginx nginx 145089 Feb 26 15:39 composer.lock
drwxrwxr-x. 2 nginx nginx 247 Feb 26 15:39 config
drwxrwxr-x. 5 nginx nginx 72 Feb 26 15:39 database
-rwxrwxr-x. 1 nginx nginx 13 Feb 26 17:46 index.html
-rw-rw-r--. 1 nginx nginx 1150 Feb 26 15:39 package.json
-rw-rw-r--. 1 nginx nginx 1040 Feb 26 15:39 phpunit.xml
drwxr-xr-x. 4 root root 116 Feb 26 18:05 public
drwxr-xr-x. 2 root root 24 Feb 26 17:50 public_c
drwxrwxr-x. 5 nginx nginx 45 Feb 26 15:39 resources
drwxrwxr-x. 2 nginx nginx 75 Feb 26 16:50 routes
-rw-rw-r--. 1 nginx nginx 563 Feb 26 15:39 server.php
drwxr-xr-x. 5 nginx nginx 46 Feb 26 15:39 storage
drwxrwxr-x. 4 nginx nginx 83 Feb 26 15:39 tests
drwxrwxr-x. 37 nginx nginx 4096 Feb 26 15:40 vendor
-rw-rw-r--. 1 nginx nginx 549 Feb 26 15:39 webpack.mix.js
-rw-rw-r--. 1 nginx nginx 258941 Feb 26 15:39 yarn.lock
$ ll /usr/share/nginx/html/test/public
total 12
drwxrwxr-x. 2 nginx nginx 21 Feb 26 15:39 css
-rw-rw-r--. 1 nginx nginx 0 Feb 26 15:39 favicon.ico
-rwxr-xr-x. 1 root root 13 Feb 26 17:49 index.html
-rw-rw-r--. 1 nginx nginx 1823 Feb 26 15:39 index.php
drwxrwxr-x. 2 nginx nginx 20 Feb 26 15:39 js
-rw-rw-r--. 1 nginx nginx 24 Feb 26 15:39 robots.txt
$ ll /usr/share/nginx/html/test/public_c/
total 4
-rwxr-xr-x. 1 root root 13 Feb 26 17:50 index.html
I have read a lot of relative questions and pages, but nothing help against this problem. What is wrong in my actions or settings?
Update
Thanks #Adam Kozlowski. I tried chmod 777 public -R and changing owner to both of root and nginx, but the problem was not solved.
I found the problem: SELinux blocked Nginx to access the folders.
$ ls /usr/share/nginx/html/test/ -Z
drwxr-xr-x. root root unconfined_u:object_r:config_home_t:s0 public
drwxr-xr-x. root root unconfined_u:object_r:httpd_sys_content_t:s0 public_c
Only the files with the tag, httpd_sys_content_t, can be accessed by HTTP.
Command:
chcon -R -t httpd_sys_content_t /usr/share/nginx/html/test
And I also need to add httpd_sys_rw_content_t to /usr/share/nginx/html/test/storage to let Laravel work.
Command:
chcon -R -t httpd_sys_rw_content_t/usr/share/nginx/html/test/storage
Referring Permissions Issue with Laravel on CentOS
Set proper permission for directory, as a root user:
chmod a+rwx directory-name -R

Nginx virtual hosts not working

I recorded a video https://youtu.be/dmezVzASr5A
I have:
linux ubuntu 16.04 (Lubuntu)
nginx 1.10
php7.0-fpm
php7.0
mysql 5.7
I did:
created domain /etc/hosts (test2.test)
created virtual hosts withing sites-available folder (test2.test file)
restarted, reloaded nginx server (sudo service nginx stop...restart...reload)
created symlink ln -s /etc/nginx/sites-available/test2.test /etc/nginx/sites-enabled/
symlink proof:
dima#dima-Lenovo-G50-30:~/www/nginx/test2.ru$ ls -ls /etc/nginx/sites-enabled
total 0
0 lrwxrwxrwx 1 root root 34 май 21 16:33 default -> /etc/nginx/sites-available/default
0 lrwxrwxrwx 1 root root 37 май 21 16:44 test2.test -> /etc/nginx/sites-available/test2.test
Problem is when i try to open in browser http://test2.test, i get:
404 Not Found
nginx/1.10.0 (Ubuntu)
This files are not opening:
index.html
test.html
index.php
within /var/www/html i have info.php with content <?php echo phpinfo(); ?>. http://localhost/info.php successfully displays php info.
My permissions:
dima#dima-Lenovo-G50-30:~/www/nginx/test2.ru$ ls -la
total 44
drwxr-xr-x 2 www-data www-data 4096 май 21 16:59 .
drwxrwxr-x 4 dima dima 4096 май 21 13:14 ..
-rw-rw-r-- 1 www-data www-data 111 фев 21 13:34 index.html
-rw-rw-r-- 1 www-data www-data 26 май 21 13:15 index.php
-rwxr-xr-x 1 www-data www-data 5 май 21 16:59 test.html
dima#dima-Lenovo-G50-30:~/www/nginx/test2.ru$
My virtual hosts:
server {
listen 80;
listen [::]:80;
server_name test2.test;
root /home/dima/www/nginx/test2.ru;
index index.html;
location / {
try_files $uri $uri/ =404;
#autoindex on;
}
}
nginx logs:
error.log.1:
many errors like:
2016/05/26 08:46:28 [crit] 1066#1066: *1 stat() "/home/dima/www/nginx/test2.ru/" failed (13: Permission denied), client: 127.0.0.1, server: test2.test, request: "GET / HTTP/1.1", host: "test2.test"
ls -la:
dima#dima-Lenovo-G50-30:~/www/nginx$ ls -la
total 16
drwxrwxr-x 4 dima dima 4096 май 21 13:14 .
drwxrwxr-x 10 dima dima 4096 май 21 12:52 ..
drwxrwxr-x 5 dima dima 4096 май 21 12:52 test1.ru
drwxr-xr-x 2 www-data www-data 4096 май 21 16:59 test2.ru
dima#dima-Lenovo-G50-30:~/www/nginx$
within test2.ru folder:
dima#dima-Lenovo-G50-30:~/www/nginx/test2.ru$ ls -la
total 44
drwxr-xr-x 2 www-data www-data 4096 май 21 16:59 .
drwxrwxr-x 4 dima dima 4096 май 21 13:14 ..
-rw-rw-r-- 1 www-data www-data 111 фев 21 13:34 index.html
-rw-rw-r-- 1 www-data www-data 26 май 21 13:15 index.php
-rwxr-xr-x 1 www-data www-data 5 май 21 16:59 test.html
dima#dima-Lenovo-G50-30:~/www/nginx/test2.ru$
UPD I have fixed. It was permissions problem. I changed some permisisions and it worked, but i don't know and remvemebr exactly what i did, but it works
Maybe you can try to give execute access to the files in that /home/dima/www/nginx/test2.ru folder. Nginx needs to execute the php files, not only read the files.

Categories