PHP源码编译安装管理常用脚本
#!/bin/sh# 编译安装管理PHPApp=phpAppName=PHPAppBase=/AppAppDir=$AppBase/$AppAppProg=$AppDir/sbin/php-fpmAppIni=$AppDir/etc/php.iniAppConf=$AppDir/etc/php-fpm.confExtensionDir=$($AppDir/bin/php-config --extension-dir)AppSrcBase=/App/srcAppSrcFile=$App-*.tar.*AppSrcDir=$(find $AppSrcBase -maxdepth 1 -name "$AppSrcFile" -type f 2> /dev/null | sed -e 's/.tar.*$//' -e 's/^.\///')AppUser=$(grep "^[[:space:]]*user" $AppConf 2> /dev/null | awk -F= '{print $2}' | sed -e 's/[[:space:]]//g' -e 's/"//g' -e "s/'//g")AppGroup=$(grep "^[[:space:]]*group" $AppConf 2> /dev/null | awk -F= '{print $2}' | sed -e 's/[[:space:]]//g' -e 's/"//g' -e "s/'//g")AppPidDir=$(dirname $(grep "^[[:space:]]*pid" $AppConf 2> /dev/null | awk -F= '{print $2}' | sed -e 's/[[:space:]]//g' -e 's/"//g' -e "s/'//g") 2> /dev/null)AppErrorLogDir=$(dirname $(grep "^[[:space:]]*error_log" $AppConf 2> /dev/null | awk -F= '{print $2}' | sed -e 's/[[:space:]]//g' -e 's/"//g' -e "s/'//g") 2> /dev/null)AppSlowLogDir=$(dirname $(grep "^[[:space:]]*slowlog" $AppConf 2> /dev/null | awk -F= '{print $2}' | sed -e 's/[[:space:]]//g' -e 's/"//g' -e "s/'//g") 2> /dev/null)UploadTmpDir=$(grep "^[[:space:]]*upload_tmp_dir" $AppIni 2> /dev/null | awk -F= '{print $2}' | sed -e 's/[[:space:]]//g' -e 's/"//g' -e "s/'//g")grep "^session.save_handler" $AppIni 2> /dev/null | grep -q "files"[ $? -eq 0 ] && SessionDir=$(grep "^[[:space:]]*session.save_path" $AppIni 2> /dev/null | awk -F= '{print $2}' | sed -e 's/[[:space:]]//g' -e 's/"//g' -e "s/'//g")CacheDir=$(grep "^[[:space:]]*eaccelerator.cache_dir" $AppIni 2> /dev/null | awk -F= '{print $2}' | sed -e 's/[[:space:]]//g' -e 's/"//g' -e "s/'//g")AppUser=${AppUser:-nobody}AppGroup=${AppGroup:-nobody}AppPidDir=${AppPidDir:=$AppDir/var/run}AppErrorLogDir=${AppErrorLogDir:-$AppDir/var/log}AppSlowLogDir=${AppSlowLogDir:-$AppDir/var/log}RemoveFlag=0InstallFlag=0# 获取PIDfpid(){ AppMasterPid=$(ps ax | grep "php-fpm: master process" | grep -v "grep" | awk '{print $1}' 2> /dev/null) AppWorkerPid=$(ps ax | grep "php-fpm: pool" | grep -v "grep" | awk '{print $1}' 2> /dev/null)}# 查询状态fstatus(){ fpid if [ ! -f "$AppProg" ]; then echo "$AppName 未安装" else echo "$AppName 已安装" if [ -z "$AppMasterPid" ]; then echo "$AppName 未启动" else echo "$AppName 正在运行" fi fi}# 删除fremove(){ fpid RemoveFlag=1 if [ -z "$AppMasterPid" ]; then if [ -d "$AppDir" ]; then rm -rf $AppDir && echo "删除 $AppName" else echo "$AppName 未安装" fi else echo "$AppName 正在运行" && exit fi}# 备份fbackup(){ Day=$(date +%Y-%m-%d) BackupFile=$App.$Day.tgz if [ -f "$AppProg" ]; then cd $AppBase tar zcvf $BackupFile --exclude=var/log/* --exclude=var/run/* $App --backup=numbered [ $? -eq 0 ] && echo "$AppName 备份成功" || echo "$AppName 备份失败" else echo "$AppName 未安装" fi}# 安装finstall(){ fpid InstallFlag=1 if [ -z "$AppMasterPid" ]; then test -f "$AppProg" && echo "$AppName 已安装" [ $? -ne 0 ] && fupdate && fcpconf else echo "$AppName 正在运行" fi}# 拷贝配置fcpconf(){ cp -vf --backup=numbered $ScriptDir/php.ini $AppIni cp -vf --backup=numbered $ScriptDir/php-fpm.conf $AppConf}# 更新fupdate(){ Operate="更新" [ $InstallFlag -eq 1 ] && Operate="安装" [ $RemoveFlag -ne 1 ] && fbackup cd $AppSrcBase test -d "$AppSrcDir" && rm -rf $AppSrcDir tar Jxf $AppSrcFile || tar jxf $AppSrcFile || tar zxf $AppSrcFile cd $AppSrcDir ./configure \ "--prefix=$AppDir" \ "--disable-all" \ "--enable-fpm" \ "--enable-opcache" \ "--enable-pdo" \ "--enable-session" \ "--with-pcre-dir" \ "--with-pdo-mysql=mysqlnd" [ $? -eq 0 ] && make && make install if [ $? -eq 0 ];then echo "$AppName $Operate成功" else echo "$AppName $Operate失败" exit 1 fi}# 初始化finit(){ echo "初始化 $AppName" id -gn $AppGroup &> /dev/null if [ $? -ne 0 ]; then groupadd $AppGroup && echo "新建 $AppName 运行组:$AppGroup" else echo "$AppName 运行组:$AppGroup 已存在" fi id -un $AppUser &> /dev/null if [ $? -ne 0 ]; then useradd -s /bin/false -g $AppGroup -M $AppUser if [ $? -eq 0 ]; then echo "新建 $AppName 运行用户:$AppUser" echo "S0nGPhb693$" | passwd --stdin $AppUser &> /dev/null fi else echo "$AppName 运行用户:$AppUser 已存在" fi echo $AppPidDir | grep -q "^/" if [ $? -eq 1 ]; then AppPidDir=$AppDir/var/$AppPidDir fi if [ ! -e "$AppPidDir" ]; then mkdir -p $AppPidDir && echo "新建 $AppName PID文件存放目录:$AppPidDir" else echo "$AppName PID文件存放目录:$AppPidDir 已存在" fi echo $AppErrorLogDir | grep -q "^/" if [ $? -eq 1 ]; then AppErrorLogDir=$AppDir/var/$AppErrorLogDir fi if [ ! -e "$AppErrorLogDir" ]; then mkdir -p $AppErrorLogDir && echo "新建 $AppName 错误日志目录:$AppErrorLogDir" else echo "$AppErrorLogDir 错误日志目录:$AppErrorLogDir 已存在" fi echo $AppSlowLogDir | grep -q "^/" if [ $? -eq 1 ]; then AppSlowLogDir=$AppDir/$AppSlowLogDir fi if [ ! -e "$AppSlowLogDir" ]; then mkdir -p $AppSlowLogDir && echo "新建 $AppName 慢日志目录:$AppSlowLogDir" else echo "$AppSlowLogDir 慢日志目录:$AppSlowLogDir 已存在" fi printf "\n" if [ -n "$UploadTmpDir" ]; then echo $UploadTmpDir | grep -q "^/" if [ $? -eq 0 ]; then if [ ! -e "$UploadTmpDir" ]; then mkdir -p $UploadTmpDir && echo "新建 $AppName 文件上传临时存储目录:$UploadTmpDir" else echo "$AppName 文件上传临时存储目录:$UploadTmpDir 已存在" fi chown -R $AppUser:$AppGroup $UploadTmpDir && echo "修改 $AppName 文件上传临时存储目录拥有者为 $AppUser,属组为 $AppGroup" printf "\n" fi fi if [ -n "$SessionDir" ]; then echo $SessionDir | grep -q "^/" if [ $? -eq 0 ]; then if [ ! -e "$SessionDir" ]; then mkdir -p $SessionDir && echo "新建 $AppName 会话存储目录:$SessionDir" else echo "$AppName 会话存储目录:$SessionDir 已存在" fi chown -R $AppUser:$AppGroup $SessionDir && echo "修改 $AppName 会话存储目录拥有者为 $AppUser,属组为 $AppGroup" printf "\n" fi fi if [ -n "$CacheDir" ]; then echo $CacheDir | grep -q "^/" if [ $? -eq 0 ]; then if [ ! -e "$CacheDir" ]; then mkdir -p $CacheDir && echo "新建 eAccelerator 缓存目录:$CacheDir" else echo "eAccelerator 缓存目录:$CacheDir 已存在" fi chown -R $AppUser:$AppGroup $CacheDir && echo "修改 eAccelerator 缓存目录拥有者为 $AppUser,属组为 $AppGroup" fi fi sed -i "s|extension_dir.*$|extension_dir = \"$ExtensionDir\"|" $AppIni}# 检查配置ftest(){ $AppProg -t && echo "$AppName 配置正确" || echo "$AppName 配置错误"}# 启动fstart(){ fpid if [ -n "$AppMasterPid" ]; then echo "$AppName 正在运行" else $AppProg -c $AppIni && echo "启动 $AppName" || echo "$AppName 启动失败" fi}# 停止fstop(){ fpid if [ -n "$AppMasterPid" ]; then kill -INT $AppMasterPid && echo "停止 $AppName" || echo "$AppName 停止失败" else echo "$AppName 未启动" fi}# 重载配置freload(){ fpid if [ -n "$AppMasterPid" ]; then kill -USR2 $AppMasterPid && echo "重载 $AppName 配置" || echo "$AppName 重载配置失败" else echo "$AppName 未启动" fi}# 重启frestart(){ fpid [ -n "$AppMasterPid" ] && fstop && sleep 1 fstart}# 终止进程fkill(){ fpid if [ -n "$AppMasterPid" ]; then echo "$AppMasterPid" | xargs kill -9 if [ $? -eq 0 ]; then echo "终止 $AppName 主进程" else echo "终止 $AppName 主进程失败" fi else echo "$AppName 主进程未运行" fi if [ -n "$AppWorkerPid" ]; then echo "$AppWorkerPid" | xargs kill -9 if [ $? -eq 0 ]; then echo "终止 $AppName 工作进程" else echo "终止 $AppName 工作进程失败" fi else echo "$AppName 工作进程未运行" fi}ScriptDir=$(cd $(dirname $0); pwd)ScriptFile=$(basename $0)case "$1" in "install" ) finstall;; "update" ) fupdate;; "reinstall" ) fremove && finstall;; "remove" ) fremove;; "backup" ) fbackup;; "init" ) finit;; "start" ) fstart;; "stop" ) fstop;; "restart" ) frestart;; "status" ) fstatus;; "cpconf" ) fcpconf;; "test" ) ftest;; "reload" ) freload;; "kill" ) fkill;; * ) echo "$ScriptFile install 安装 $AppName" echo "$ScriptFile update 更新 $AppName" echo "$ScriptFile reinstall 重装 $AppName" echo "$ScriptFile remove 删除 $AppName" echo "$ScriptFile backup 备份 $AppName" echo "$ScriptFile init 初始化 $AppName" echo "$ScriptFile start 启动 $AppName" echo "$ScriptFile stop 停止 $AppName" echo "$ScriptFile restart 重启 $AppName" echo "$ScriptFile status 查询 $AppName 状态" echo "$ScriptFile cpconf 拷贝 $AppName 配置" echo "$ScriptFile test 检查 $AppName 配置" echo "$ScriptFile reload 重载 $AppName 配置" echo "$ScriptFile kill 终止 $AppName 进程" ;;esac

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
