How to set up a general php5.4 and mysql5.6 service in docker
# How to set up a php5.4 project under linux
## Install php and mysql
```
#/root/docker-compose.yaml
version: "3.9"
services:
old_php_5.4:
image: yeszao/php:5.4.45-fpm-alpine
network_mode: "host"
volumes:
- /xp/www:/var/www/html:rw
working_dir: /var/www/html
command: sh -c "php -S [::]:7171 -t ."
restart: always
mysql56_db:
image: mysql:5.6
network_mode: "host"
environment:
MYSQL_ROOT_PASSWORD: "root"
MYSQL_USER: "user"
MYSQL_PASSWORD: "user"
volumes:
- ./mysql_data:/var/lib/mysql
restart: unless-stopped
# old_php:
# image: php:5.4.45-apache
# #network_mode: "host"
# ports:
# - '7071:80'
# volumes
# - .:/var/www/html:rw
# restart: always
#
#
# old_my_sql:
# image: yobasystems/alpine-mariadb:10
# network_mode: "host"
# volumes:
# - ./data:/var/lib/mysql:rw
# environment:
# - MYSQL_ROOT_PASSWORD=root_password
# - MYSQL_DATABASE=hu60
# - MYSQL_USER=root
# - MYSQL_PASSWORD=root
# #ports:
# # - '3306:3306'
# restart: always
```
cd /root
docker-compose up -d
```
#/xp/www/index.php
<?php
echo "Hello, World!";
?>
```
Alwasys use 127.0.0.1 in php PDO mysql connector, localhost will not work.
## Set up nginx to forward 80 port to 7171 port
```
#/xp/server/nginx/conf/nginx.conf
http {
server {
listen 80;
server_name _; # Adjust to your domain or IP if needed, e.g., 192.168.49.242
# Assuming /xp/www on the host contains all your web files (PHP, HTML, images, etc.)
# and that the php -S server is responsible for serving everything from that root.
# We do NOT need a 'root' directive here if we are proxying everything.
index index.php index.html index.htm;
location / {
proxy_pass http://127.0.0.1:7171; # Proxy all requests to your php -S server
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Add these if you encounter issues with large request bodies or file uploads
client_max_body_size 100M; # Increase if you need to upload large files
proxy_read_timeout 300s; # Increase if PHP scripts take a long time to execute
}
}
}
```
reboot
Now visit http://127.0.0.1
## Install php and mysql
```
#/root/docker-compose.yaml
version: "3.9"
services:
old_php_5.4:
image: yeszao/php:5.4.45-fpm-alpine
network_mode: "host"
volumes:
- /xp/www:/var/www/html:rw
working_dir: /var/www/html
command: sh -c "php -S [::]:7171 -t ."
restart: always
mysql56_db:
image: mysql:5.6
network_mode: "host"
environment:
MYSQL_ROOT_PASSWORD: "root"
MYSQL_USER: "user"
MYSQL_PASSWORD: "user"
volumes:
- ./mysql_data:/var/lib/mysql
restart: unless-stopped
# old_php:
# image: php:5.4.45-apache
# #network_mode: "host"
# ports:
# - '7071:80'
# volumes
# - .:/var/www/html:rw
# restart: always
#
#
# old_my_sql:
# image: yobasystems/alpine-mariadb:10
# network_mode: "host"
# volumes:
# - ./data:/var/lib/mysql:rw
# environment:
# - MYSQL_ROOT_PASSWORD=root_password
# - MYSQL_DATABASE=hu60
# - MYSQL_USER=root
# - MYSQL_PASSWORD=root
# #ports:
# # - '3306:3306'
# restart: always
```
cd /root
docker-compose up -d
```
#/xp/www/index.php
<?php
echo "Hello, World!";
?>
```
Alwasys use 127.0.0.1 in php PDO mysql connector, localhost will not work.
## Set up nginx to forward 80 port to 7171 port
```
#/xp/server/nginx/conf/nginx.conf
http {
server {
listen 80;
server_name _; # Adjust to your domain or IP if needed, e.g., 192.168.49.242
# Assuming /xp/www on the host contains all your web files (PHP, HTML, images, etc.)
# and that the php -S server is responsible for serving everything from that root.
# We do NOT need a 'root' directive here if we are proxying everything.
index index.php index.html index.htm;
location / {
proxy_pass http://127.0.0.1:7171; # Proxy all requests to your php -S server
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Add these if you encounter issues with large request bodies or file uploads
client_max_body_size 100M; # Increase if you need to upload large files
proxy_read_timeout 300s; # Increase if PHP scripts take a long time to execute
}
}
}
```
reboot
Now visit http://127.0.0.1