I am using docker with php and nginx to create server to printhello world
with php script on localhost. I Here are my files:
FROM nginx:1.17.8-alpine
# Copy the public directory
# COPY ./public/ /app/public/
COPY . /app/
# Copy the nginx config file
COPY ./docker/nginx/nginx.conf /etc/nginx/conf.d/default.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
server_tokens off;
root /app/;
index index.php;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass php:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
-php dockerfile:
FROM php:7.4.3-fpm-alpine3.11
COPY . /app
VOLUME ["/app"]
version: '3'
services:
web:
build:
context: .
dockerfile: docker/nginx/Dockerfile
ports:
- "8080:80"
volumes:
- .:/app/
links:
- php
php:
build:
context: .
dockerfile: docker/php/Dockerfile
volumes:
- .:/app/
<?php
echo 'Hellow World!!';
When i run docker and try to open localhost::8080 i get this error:
web_1 | 2022/11/07 23:37:59 \[error\] 7#7: \*1 connect() failed (111: Connection refused) while connecting to upstream, client:, server: \_, request: "GET / HTTP/1.1", upstream: "fastcgi://", host:"localhost:8080"
web_1 | 172.18.0.1 - - \[07/Nov/2022:23:37:59 +0000\] "GET / HTTP/1.1" 502 552 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36" "-"
web_1 | 2022/11/07 23:37:59 \[error\] 7#7: \*1 connect() failed (111: Connection refused) while connecting to upstream, client:, server: \_, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://", host: "localhost:8080", referrer: "http://localhost:8080/"
web_1 |- - \[07/Nov/2022:23:37:59 +0000\] "GET /favicon.ico HTTP/1.1" 502 552 "http://localhost:8080/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36" "-"
I expect to see result of php script on localhost server. I tried to add following string to nginx conf but i did not helpfastcgi_pass unix:/var/run/php5-fpm.sock;
.
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.