<?php
$servername="mysql";$username="root";$password="123456";$dbname="user1";$conn= new mysqli($servername, $username, $password, $dbname);$sql="select * from student";$result=$conn->query($sql);
while($row=$result->fetch_assoc()){echo"id: ".$row["id"]."<br>";}
?>
2,建立redis.php文件,进入redis服务,set Hu 'moon'
怎么进入redis服务
docker exec -it redis服务id redis-cli
然后 set Hu ‘moon’
<?php
$redis= new Redis();$redis->connect('redis', 6379);#这里connect()中一定要是redis,使用127.0.0.1会出错echo"<br />";echo$redis->get('Hu');
?>
3,建立index.html和test.php文件
vi test.php
输入: <?php phpinfo(); ?>vi index.html
输入:Welcome to docker nginx or httpd
3:建立nginx.conf文件并输入以下内容
worker_processes 1;
events {
worker_connections 1024;}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80 default_server;
listen [::]:80 default_server;# SSL configuration## listen 443 ssl default_server;# listen [::]:443 ssl default_server;## Note: You should disable gzip for SSL traffic.# See: https://bugs.debian.org/773332## Read up on ssl_ciphers to ensure a secure configuration.# See: https://bugs.debian.org/765782## Self signed certs generated by the ssl-cert package# Don't use them in a production server!## include snippets/snakeoil.conf;
root /usr/share/nginx/html;# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
server_name localhost;
location / {# First attempt to serve request as file, then# as directory, then fall back to displaying a 404.
try_files $uri$uri/ =404;}# pass PHP scripts to FastCGI server#
location ~ \.php$ {# With php-fpm (or other unix sockets):
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
include fastcgi_params;}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}}