Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
even the example from laravel does not work
Route::get('/greeting', function () {
return 'Hello World';
}); -
@C0D4 I tried both
Later decided to try this url
http://localhost/index.php/...
and now it finds. Wtf - why do I need index.php?
I used same nginx config from symfony application and in symfony applications I did not need index.php -
C0D4669023y@Angry-dev sounds like a .htaccess issue.
Are you using a web server (apache / Ngnx) or just php -S ?
If it's php's built in server you'll be limiting yourself. -
I am using nginx. I do not get how this is different from symfony, when this nginx config was working on symfony apps
-
C0D4669023y@Angry-dev
Go down to Nginx config and double check your config.
https://digitalocean.com/community/... -
@C0D4
Based on digital ocean, made such config:
server {
listen 80;
server_name localhost;
root /app/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
Now I get
502 Bad Gateway
nginx/1.15.0
when going to
http://localhost:8000/greeting -
C0D4669023yIs /app at the root directory?
Usually it's /var/www/path/to/public
Or is this a docker container you're trying to get this running on?
Either way, revert it back to old config, share if you can aswell, it was closer then DO got you.
(let's pray you saved it 👀) -
It is docker:
FROM php:8.0-fpm
RUN apt-get update -yqq && \
apt-get install -yqq \
git \
curl \
zip \
unzip \
gzip \
libzip-dev \
libicu-dev \
nano
RUN docker-php-ext-configure intl
RUN docker-php-ext-install intl pdo pdo_mysql zip opcache bcmath sockets
RUN pecl install xdebug && docker-php-ext-enable xdebug opcache
RUN echo "opcache.max_accelerated_files = 20000" >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php composer-setup.php && \
php -r "unlink('composer-setup.php');" && \
mv composer.phar /usr/local/bin/composer && \
chmod +x /usr/local/bin/composer
WORKDIR /app -
@MoistGrass :D I read comments that laravel is better. Symfony is shit for its shitty documentation. But the company asked to do in laravel, and I also want to try and see what is better these days - symfony or laravel
-
C0D4669023y@MoistGrass it's shit to setup, but sadly the better of the options.
@Angry-dev hmm, I can't see anything bleeding obvious with this.
Did this not work on the location?
try_files $uri $uri/ /index.php?$query_string; -
@Angry-dev if the company asked, I understand. I 100% like Symfony (including docs).
-
@MoistGrass I am surprised that you like symfony docs. Only advantage is that once you figure out, others cant catch you so fast by reading docs, so you have edge :)
-
@C0D4 it did not work, as I wrote I was getting
Now I get
502 Bad Gateway
nginx/1.15.0
when going to
http://localhost:8000/greeting -
@Angry-dev tbh there are two types of Symfony docs. The normal docs and the cookbook. The cookbook has practical examples and that’s what I use most of the time. And Google ofc.
-
@C0D4 @MoistGrass
The error lies in the PHP FPM Setup and argument parsing.
https://pastebin.com/AYh6Sbpg
try_files $uri /index.php$is_args$args;
https://nginx.com/resources/wiki/...
nginx -T should print the whole configuration to std out.
That's whats interesting, as the server / nginx.conf isn't everything. -
Ugh. Brain is fuckity.
The port in the listen directive needs to match or be forwarded via Docker.
Decide if you want to use index.php as a default script path for Fast CGI pass - then you need _one_ appropriate location block (you have currently multiple, which can lead to a lot of confusion)
Decide how Fast CGI pass should be configured.
The problem at the moment seems to be that you have multiple matching locations and the FCGI argument passing gets wrong... -
@IntrusionCM
nginx -T > tmp/nginx-t.txt
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
https://pastebin.com/u0tfpBY1 -
@IntrusionCM by decide you mean remove one of the blocks probably, so I commented
location / {
...
}
but it does not return response - chrome shows - "Failed to load resoponse data" -
@Angry-dev less... barbaric brute force.
More thinking.
Each endpoint location defines in NGINX what should flow where.
Check the nginx log.
My main concern was that you have a location for '/'… a default location (try_files) ... And a location for '.php'... and a location for '.?!well-known' (whatever the fuck that is).
Instead of trying to just doing a wild goose chase, start small.
Docker - NGINX listen directive… Port correct?
Then add one location for PHP blocks matching the recommended configuration, generate a PHP PHP info(); script at a fixed file server location (eg /test.php)… try to call the PHP script directly, see if it works.
Otherwise check the logs.
What you're doing wrong at the moment is just trying to scramble together a configuration without trying to understand it. ;) :)
I know, frustrating and bothersome...
But the more you try to just brute force it. The less it will work. -
@fruitfcker can you paste whole config, not clear where to put 2nd part, or maybe even first I would put in wrong place
-
@IntrusionCM this configuration was working perfectly with symfony multiple applicaitons. I do not get what is different in laravel :) WIl try as you say
-
cat /var/log/nginx/error.log
same with access.log
they are empty
But the cat command do not exit, what is weird. Only ctrl + c exit it -
@IntrusionCM
Port I think should be correct: https://pastebin.com/q9fSyD4z
in .env file I have defined:
NGINX_PORT=8000
And in Makefile there are those
include .env
export $(shell sed 's/=.*//' .env)
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
832f76903795 nginx:1.15.0 "nginx -g 'daemon of…" 4 days ago Up About a minute 127.0.0.1:8000->80/tcp laravel_vue_companies_nginx
00e602e07268 laravel-vue-companies_php "docker-php-entrypoi…" 4 days ago Up About a minute 9000/tcp laravel_vue_companies_php
2f5916308bd7 mysql:8.0 "docker-entrypoint.s…" 4 days ago Up About a minute 33060/tcp, 127.0.0.1:3000->3306/tcp 2f5916308bd7_laravel_vue_companies_mysql -
@IntrusionCM "Then add one location for PHP blocks matching the recommended configuration"
you mean the one from digital ocean? -
@IntrusionCM I took example config from laravel docs https://laravel.com/docs/8.x/...
modified it and this is how it looks
https://pastebin.com/2yjWLABF
I have example.com in hosts file.
I get
502 Bad Gateway
nginx/1.15.0
nginx -T shows no errors -
Now I commented all locations and left only first:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
WHen I load my page - it starts downloading laravel index.php file. -
If I comment other /location and leave only this
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
then I get 502 bad gateway -
that is super weird that example even from laravel docs cannot work. Of course I make modificaitons but not that big ones - server name and php version, looks like thats it. This should not cause problems.
This should be 2 minutes job - pastes the condig and change few values. But I am spending hours on this without working. Wtf. How can you have such shitty doc. And nginx itself - why it cannot tell what is wrong. Bad gateway - I do not even set gateway in config, how can it be bad. It should tell what is wrong in config, but nginx -T shows no fucking errors. -
@IntrusionCM what should I give from phpinfo ? the output is very long, pastebin does not allow to publicly share, there in the comments it also does not allow so long texts.
-
I noticed above there where no COPY commands in your Dockerfile.
Did you mean to copy your app to /app? Or are you using a volume to mount with the docker command/docker-compose -
This has nothing to do with Laravel though...
Without a working PHP webserver, no framework can do its job.
Make sure that there is no second webserver running, for example a PHP server on the host while you're trying to run docker.
Once PHP works (try an index.php file with <?php phpinfo(); ?>), then you can move on to making sure Laravel works.
To check routes:
php artisan route:list -
@lungdart I am using docker compose, there is volume:
nginx:
image: nginx:1.15.0
ports:
- 127.0.0.1:${NGINX_PORT}:80
volumes:
- .:/app:cached
- ./docker/nginx/default.conf:///etc/nginx/...
container_name: laravel_vue_companies_nginx
depends_on:
- php -
@bittersweet there is second web server but on different port - 8080 , so should work.
And also there is non docker nginx running but again port 80 probably.
So localhost:8000 should work. When I run other applications I do not turn of server running on port 80 and they work without problems.
WHen I changed the config back so that at least it would work with adding index.php to urls, then I can run phpinfo() in php file. But the output is very long. I could copy some specific info if you specify -
@Angry-dev are you exposing the fpm port in the docker compose file?
Can you exec into your nginx container and hit the fpm container from it? -
@fruitfcker I commented out all location / and added your ones - when I go to some route - it downloads laravel index.php file
Only left
location ~ \.php$ {
return 404;
}
but it would give 404 error if it would be activated as I understand -
@lungdart
https://pastebin.com/2u8bKCut
here is full my docker-compose
looks like there is nothhing with fpm
"Can you exec into your nginx container and hit the fpm container from it?"
what do you mean by hit? I can exec into nginx container -
It doesn't look like your php container has an expose or ports line to grant access to it from nginx.
I also don't see a volume for sharing a UNIX socket if you're going that way. -
@lungdart this config is made from symfony application and in symfony application it works. How can I fix it?
Here is working symfony example
https://pastebin.com/D356EzFg
Checked, they are practically same, just names here and there different. How can symfony work without problems but laravel not? -
I must say... It's astonishing how reluctant you are to learn a topic and instead try to brute force through it
Even an apprentice should understand that it takes time to learn stuff.
You're not willing to learn. You just try to force others to do what you are not able to accomplish.
And you even started a new rant after this was unsuccessful.
Related Rants
Laravel route not found.
Look - so simple :
Route::post('/api/companies', function () {
return 'Hello World';
});
how the fuck it is not found?
Request URL: http://localhost:8000/api/companies
Request Method: POST
Status Code: 404 Not Found
???? I have cleared cache.
How do I check fucking available routes then? In symfony there was router:debug or smth. Cant see like this in laravel
rant
laravel