How to quickly deploy PHP Web environment (nginx php mysql redis)
First look at the final effect, as follows:
What is it?
It is docker container virtualization technology . There are only a few KB description files in total, which define what to install and what to configure, and it will be automatically processed once it is executed.
what's it for?
Enter the detailed explanation (this script is for debian operating system, such as deepin, ubuntu)
As shown in the figure, four files:
FROM php:7.4-fpm
# system update
RUN apt-get update \
# Install the sql extension
&& docker-php-ext-install pdo_mysql\
# Install the graphics processing extension
&& apt install libjpeg62-turbo-dev libfreetype6-dev -y \
&& docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg \
&& docker-php-ext-install gd \
# Install the redis extension
&& pecl install -o -f redis \
# delete temporary files
&& rm -rf /tmp/pear \
# enable redis extension
&& docker-php-ext-enable redis
version: '3'
services:
php:
build:
context: ./
dockerfile: Dockerfile-php7.4 #Build php from this file name
ports:
- "9100:9000"
container_name: common_1.0_php #container name
volumes:
- "/opt/wwwroot/www:/www" #Mount the host's /opt/wwwroot/www directory to the container's /www directory
restart: always #automatic start
nginx:
image: nginx:1.23 #Based on the official image nginx:1.23
ports:
- "80:80"
container_name: common_1.0_nginx
restart: always
volumes:
- "/opt/wwwroot/www:/www"
- "/opt/wwwroot/nginx/conf.d:/etc/nginx/conf.d"
- "/opt/wwwroot/nginx/logs:/etc/nginx/logs"
redis:
image:redis:7.0
ports:
- "6179:6379"
container_name: common_1.0_redis
restart: always
mysql:
image: mysql:8.0
ports:
- "3106:3306"
container_name: common_1.0_mysql
restart: always
volumes:
- "/opt/wwwroot/mysql:/var/lib/mysql"
environment:
MYSQL_ROOT_PASSWORD: 123qwe.
#!/bin/bash
echo "Excuse me, what do you want to do? This is the PHP general development environment. Enter exit to exit."
echo "Install docker: install docker"
echo "Uninstall docker: remove docker"
echo "Install docker-compose: install compose"
echo "Uninstall docker-compose: remove compose"
echo "Generate PHP environment: build php env"
echo "View container list: docker ps"
echo "View image list: docker images"
echo ""
function go(){
if [ "$install_type" ]
then
if [ "$install_type" == "install docker" ]
then
sudo curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
elif [ "$install_type" == "remove docker" ]
then
sudo apt-get purge docker-ce
sudo rm -rf /var/lib/docker
elif [ "$install_type" == "install compose" ]
then
sudo curl -L "https://github.com/docker/compose/releases/download/v2.14.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/ bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose version
elif [ "$install_type" == "remove compose" ]
then
sudo /usr/local/bin/docker-compose
elif [ "$install_type" == "build php env" ]
then
sudo docker-compose up -d
elif [ "$install_type" == "docker ps" ]
then
sudo docker ps
elif [ "$install_type" == "docker images" ]
then
sudo docker images
else
echo "Please enter the correct value"
the fi
else
echo "Please enter a value"
the fi
}
# Infinite loop, so it can be processed multiple times
while [true]
do
read -p "Please enter a value:" install_type
if [ "$install_type" ] && [ "$install_type" == "exit" ]
then
break
the fi
go $install_type
done
Build a PHP Web environment
Add a new website
# server configuration node
server {
# Listening port. This port cannot be used
listen 80;
# The domain name of this site. Configure a host domain name directly on the host machine, or resolve it from cloud service providers such as Alibaba Cloud.
server_name sdt.com;
# The entry directory of this site, which is the directory of the php container. The host machine mounts the directory inside the container.
root /www/shangdiantuanfenxiao/public;
# Recognizable entry files in the entry directory
index index.html index.htm index.php;
# Configure urls. Thinkphp's pseudo-static settings. This is fastadmin, using thinkphp5.0
location / {
#If the file in the access path does not exist, rewrite the URL and hand it over to ThinkPHP for processing
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
# Configure url, process and forward PHP requests
location ~ \.php(/|$) {
# You can directly write the container name, or you can directly write the IP of the host machine
fastcgi_pass common_1.0_php:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
# The directory will be automatically generated.
access_log /etc/nginx/logs/sdt.com.log;
# error log
error_log /etc/nginx/logs/sdt.com.error.log;
}
Note that to add a website, just add a configuration file in /opt/wwwroot/nginx/conf.d, and nginx will automatically read all configuration files in this directory.
0 Comments