简体   繁体   English

PHP 脚本不会在 docker localhost 上运行

[英]Php script won't run on docker localhost

I am very new to Docker so please forgive any technical wording mistakes I make regarding this.我对 Docker 很陌生,所以请原谅我在这方面犯的任何技术措辞错误。

I am trying to get a very basic "Hello World!"我正在尝试获得一个非常基本的“Hello World!” php script to run through a localhost docker container. php 脚本通过 localhost docker 容器运行。 I am trying to run this script to test out this image that contains php and oracle: https://hub.docker.com/r/silencesys/php-oci8我正在尝试运行这个脚本来测试这个包含 php 和 oracle 的图像: https ://hub.docker.com/r/silencesys/php-oci8

I pulled it using this command: docker pull silencesys/php-oci8我使用以下命令将其拉出: docker pull quietsys/php-oci8

Then I tried to run it with numerous commands, some of them giving me this:然后我尝试使用许多命令运行它,其中一些命令给了我这个:

[16-Jun-2022 17:57:12] NOTICE: fpm is running, pid 1
[16-Jun-2022 17:57:12] NOTICE: ready to handle connections

And then some of them give a random string of letters and numbers.然后其中一些给出随机的字母和数字字符串。 I don't know what it refers to but I know that it means that it is running the container.我不知道它指的是什么,但我知道这意味着它正在运行容器。 When I open the container's terminal and run 'ls' I can see my index.php file.当我打开容器的终端并运行“ls”时,我可以看到我的 index.php 文件。 I can even run 'cat index.php' and see that it contains the proper code in there to run "Hello World!"我什至可以运行“cat index.php”并查看其中包含运行“Hello World!”的正确代码。 I will even include the code in here as a sanity check:我什至会在此处包含代码作为健全性检查:

<?php 
  echo "Hello World!";
?>

But everytime that I open up the localhost in my browser, I get this:但是每次我在浏览器中打开本地主机时,我都会得到这个:

This page isn’t working right now
localhost didn’t send any data.
ERR_EMPTY_RESPONSE

I have tried so many variations of this base docker run command that I found here :我已经尝试了很多我在这里找到的基本 docker run 命令的变体:

docker run -d -p 80:80 --rm --name temp-container -v "$PWD":/var/www/html silencesys/php-oci8

Any help is greatly appreciated!任何帮助是极大的赞赏!

The docker image you are referring to does contain PHP, but it does not contain a web server.您所指的 docker 映像确实包含 PHP,但它不包含 Web 服务器。

Servers that serve web pages using PHP consist of a webserver software, that accepts HTTP-requests and communicates to PHP running in the background if needed.使用 PHP 提供网页服务的服务器由一个网络服务器软件组成,该软件接受 HTTP 请求并在需要时与在后台运行的 PHP 通信。 It can be thought of an intermediary between the Browser and PHP, and if it is missing the browser cannot access your PHP script.它可以被认为是浏览器和 PHP 之间的中介,如果缺少它,浏览器将无法访问您的 PHP 脚本。

I haven't found an image that could help you right away, however I stumbled upon this , and it tells that for your usecase you should go for a PHP image that has Apache included (ie the name will contain apache in the tag).我还没有找到可以立即帮助您的图像,但是我偶然发现了这个,它告诉您,对于您的用例,您应该选择包含 Apache 的PHP 图像(即名称将在标签中包含apache )。

The way I solved this was by using this image in conjunction with the image I was using in the Question .我解决这个问题的方法是将此图像我在问题中使用的图像结合使用。 Here is a step by step guide of what I did:这是我所做的分步指南:

  1. Create folder in home/[username] directory在 home/[username] 目录中创建文件夹

  2. docker pull soivangoi/nginx-php-adminer-oci8 docker pull soivangoi/nginx-php-adminer-oci8

  3. docker pull silencesys/php-oci8码头工人拉静默系统/php-oci8

  4. docker run -dit -p 8080:80 soivangoi/nginx-php-adminer-oci8 -v "$PWD":/var/www/ silencesys/php-oci8 docker run -dit -p 8080:80 soivangoi/nginx-php-adminer-oci8 -v "$PWD":/var/www/silencesys/php-oci8

    4.1. 4.1。 If that doesn't work try this "docker run -d -it -p 8080:80 -v "$PWD":/var/www/ silencesys/php-oci8"如果这不起作用,试试这个“docker run -d -it -p 8080:80 -v "$PWD":/var/www/silencesys/php-oci8”

  5. docker run -it -p 8080:80 --rm --name test-container -v "$PWD":/var/www/ soivangoi/nginx-php-adminer-oci8 docker run -it -p 8080:80 --rm --name test-container -v "$PWD":/var/www/soivgoi/nginx-php-adminer-oci8

  6. Bash into the container.猛击到容器中。 Either by command line or by clicking the terminal button on the container.通过命令行或单击容器上的终端按钮。

  7. cd to where your php code is stored. cd 到您的 php 代码的存储位置。

  8. Run it!运行!

Just make sure that whatever network you are on has access to the oracle database or else it will not let you run your code still.只要确保您所在的任何网络都可以访问 oracle 数据库,否则它不会让您继续运行您的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM