环境部署

ubuntu/debian编译安装nginx

1. 一键脚本

bash <(curl -Lso- https://files.kkktu.com/nginx/install.sh)

2. 脚本详情

install.sh

#!/bin/bash
echo -n "entry nginx version: (default:1.25.3)"

read nginx_version

#更新并安装依赖
sudo apt-get update -y

sudo apt-get install build-essential libpcre3 libpcre3-dev zlib1g-dev libssl-dev -y

#下载指定版本nginx

if [ -z $nginx_version]; then
        nginx_version="1.25.3"
fi

curl -o /tmp/nginx-$nginx_version.tar.gz https://nginx.org/download/nginx-$nginx_version.tar.gz

echo "download completed"

tar zxvf /tmp/nginx-$nginx_version.tar.gz -C /tmp

cd /tmp/nginx-$nginx_version
#开始编译安装
./configure --prefix=/usr/local/lib/nginx --with-http_ssl_module

make

sudo make install

sudo rm /usr/bin/nginx
sudo ln -s /usr/local/lib/nginx/sbin/nginx /usr/bin/nginx

sudo rm -rf /tmp/nginx-$nginx_version

sudo rm -rf /tmp/nginx-$nginx_version.tar.gz
#创建用户
useradd www
#生成配置文件目录
sudo mkdir -p /home/www/nginx/conf.d

sudo chmod 777 /home/www/nginx/conf.d
#相关配置
curl -o /tmp/nginx.conf https://files.kkktu.com/nginx/nginx.conf
curl -o /tmp/example.conf https://files.kkktu.com/nginx/example.conf

sudo mv /tmp/nginx.conf /usr/local/lib/nginx/conf
mv /tmp/example.conf /home/www/nginx/conf.d

#nginx服务
curl -o /tmp/nginx.service https://files.kkktu.com/nginx/nginx.service
sudo mv /tmp/nginx.service /lib/systemd/system/nginx.service

sudo mkdir -p /var/log/nginx

sudo systemctl enable nginx
sudo systemctl start nginx

/usr/local/lib/nginx/conf/nginx.conf

user  www;
worker_processes  auto;

error_log  /var/log/nginx/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        /run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;

    include /home/www/nginx/conf.d/*.conf;
}

/lib/systemd/system/nginx.service

# Stop dance for nginx
# =======================
#
# ExecStop sends SIGSTOP (graceful stop) to the nginx process.
# If, after 5s (--retry QUIT/5) nginx is still running, systemd takes control
# and sends SIGTERM (fast shutdown) to the main process.
# After another 5s (TimeoutStopSec=5), and if nginx is alive, systemd sends
# SIGKILL to all the remaining processes in the process group (KillMode=mixed).
#
# nginx signals reference doc:
# http://nginx.org/en/docs/control.html
#
[Unit]
Description=A high performance web server and a reverse proxy server
Documentation=man:nginx(8)
After=network.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/bin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/bin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/bin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid
TimeoutStopSec=5
KillMode=mixed

[Install]
WantedBy=multi-user.target

3. nginx服务指令

sudo systemctl enable nginx #开机启动nginx
sudo systemctl restart nginx #重启nginx
sudo systemctl reload nginx #重载nginx配置
sudo systemctl restart nginx #启动nginx
sudo systemctl status nginx #查看nginx服务状态

部署纯静态php-cli、php-fpm、composer-无需编译环境

1. 纯静态项目

项目:crazywhalecc/static-php-cli

下载地址:纯净态php

2. 安装脚本

bash <(curl -Lso- https://files.kkktu.com/php/install.sh)

3. 脚本详情

#!/bin/bash

user=$(id -un)

echo -n "Entry php version: (default:8.2.12)"

read version

echo -n "Entry php install path:(default:/home/$user/php/8.2)"

read path

if [ -z $version]; then
        version="8.2.12"
fi

if [ -z $path]; then
        path="/home/$user/php/8.2"
fi
# 下载静态化php包
curl -o /tmp/php-$version-cli-linux-x86_64.tar.gz https://files.kkktu.com/php/php-8.2.12-cli-linux-x86_64.tar.gz

curl -o /tmp/php-$version-fpm-linux-x86_64.tar.gz https://files.kkktu.com/php/php-8.2.12-fpm-linux-x86_64.tar.gz

echo "download completed"

tar zxvf /tmp/php-$version-cli-linux-x86_64.tar.gz -C /tmp
tar zxvf /tmp/php-$version-fpm-linux-x86_64.tar.gz -C /tmp

rm /tmp/php-$version-cli-linux-x86_64.tar.gz
rm /tmp/php-$version-fpm-linux-x86_64.tar.gz

mkdir -p $path

mv /tmp/php $path
mv /tmp/php-fpm $path

sudo rm /usr/bin/php
sudo rm /usr/bin/php-fpm
sudo ln -s $path/php /usr/bin/php
sudo ln -s $path/php-fpm /usr/bin/php-fpm
# 下载composer静态化包
curl -o $path/composer.phar https://files.kkktu.com/php/composer.phar

sudo rm /usr/bin/composer
sudo ln -s $path/composer.phar /usr/bin/composer

php -v
php-fpm -v

useradd www
# 下载fpm相关配置
curl -o $path/php-fpm.conf https://files.kkktu.com/php/php-fpm.conf
curl -o $path/www.conf https://files.kkktu.com/php/www.conf

sed -i "s,{include_www_path},$path," $path/php-fpm.conf

fpm相关配置:

https://files.kkktu.com/php/php-fpm.conf

https://files.kkktu.com/php/www.conf

4. 安装目录

php
└── 8.2
    ├── composer.phar  # composer
    ├── php            # 静态php
    ├── php-fpm        # 静态php-fpm
    ├── php-fpm.conf   # php-fpm配置
    └── www.conf       # p'h'p

1 directory, 5 files

5. 执行指令

php

$ php -v
PHP 8.2.12 (cli) (built: Nov 21 2023 15:54:41) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.12, Copyright (c) Zend Technologies

php-fpm

$ php-fpm -v
PHP 8.2.12 (fpm-fcgi) (built: Nov 21 2023 15:54:55)
Copyright (c) The PHP Group
Zend Engine v4.2.12, Copyright (c) Zend Technologies

php-fpm运行方式

sudo php-fpm -y $path/php-fpm.conf
# -y 指定fpm config 目录,$path为安装php时目录