How to install PHP in Docker
This article is about how to install PHP in Docker. I think it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.
Study
Method 1. Docker pull php
Find the php image on Docker Hub
[root@huixuan nginx] # docker pull webdevops/php-nginx
Using default tag: latest
Trying to pull repository docker.io/webdevops/php-nginx...
Latest: Pulling from docker.io/webdevops/php-nginx
1be7f2b886e8: Pull complete
6fbc4a21b806: Pull complete
C71a6f8e1378: Pull complete
4be3072e5a37: Pull complete
06c6d2f59700: Pull complete
5c1c30789448: Pull complete
42eeae6547fc: Pull complete
3ff6b06497b0: Pull complete
60c69a4834cc: Pull complete
Cbb835cfffc0: Pull complete
604f67c351eb: Pull complete
072984b59472: Pull complete
943570e2b1d3: Pull complete
1e35c99925af: Pull complete
Fbb001c74aae: Pull complete
Digest: sha256:38b9e5a8072f83ae2e7ad47554f58c8ca4c4308adb3909070ad75deb761bb898
Status: Downloaded newer image for docker.io/webdevops/php-nginx:latest
[root@huixuan nginx] #
Use webdevops/php-nginx mirroring
Run the container
[root@huixuan nginx] # docker run-p 9000 name myphp-d webdevops/php-nginx
458820a216542e70d7deaac772713a5149f82be6d35c1e6aafdb5edd6e1ca97e
[root@huixuan nginx] #
Command description:
-p 9000virtual 9000: map port 9000 of the container to port 9000 of the host
-- name myphp-fpm: name the container myphp-fpm
-v ~ / nginx/www:/www: Mount the directory www of the project in the host to the container's / www
-v $PWD/conf:/usr/local/etc/php: Mount the conf directory under the current directory on the host to the container's / usr/local/etc/php
-v $PWD/logs:/phplogs: Mount the logs directory under the current directory on the host to the container's / phplogs
Check the container startup status
[root@huixuan nginx] # docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
458820a21654 webdevops/php-nginx "/ entrypoint super..." 46 seconds ago Up 44 seconds 80/tcp, 443/tcp, 0.0.0.0seconds ago Up 9000-> 9000/tcp myphp
[root@huixuan nginx] #
Access phpinfo () through a browser
PS: here the web service is implemented through nginx+php, and the fastcgi_pass of the nginx configuration file should be configured as the IP of the webdevops/php-nginx container.
Fastcgi_pass 172.17.0.4:9000
The checking method of container IP
Docker inspect container ID or container name | grep'"IPAddress"'
This is how Docker installs PHP. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.