php打包exe

1.集成环境+代码

2.批处理bat文件:设置目录,安装启动mysql,apache,Cache等环境,放集成包根目录下
cd到对应的执行exe 启动并连接
vbs脚本,修改默认安装目录批量替换apache里httpd.conf,httpd-vhosts.conf配置及php里php.ini转exe.安装项目到指定目录

3.htdocs里代码块直接替换更新

4.数据库:新增表,表字段的新增及修改(类型长度)
update.sql放项目根目录,tp框架在行为或者基类里调用执行
system(implode('\',$path).'\MariaDB\bin\mysql.exe -uadmin -p123456 --database databasename < update.sql');

5.inno setup。设置名称版本号,打包
打包 : inno 打开 ipweb-ch.iss 改版本号 删缓存runtime 关debug DB改为DB2, update.sql放到项目根目录

bat,vbs脚本转exe。转exe后看不到源码,相对比较安全(转exe自动运行不会报错)
打包之后安装如果出现权限问题,将exe文件以管理员身份运行

bat文件demo

@echo off
//设置服务目录 数据库账号密码
set mysql_dir=MariaDB\bin\
set mem_dir=memcached\
set nginx_dir=Nginx\
set "ROOT_PATH=%~dp0" //安装目录,这里限制了安装在盘符下。可优化安装在盘符下的子目录
set nginx_conf=%ROOT_PATH%Nginx\conf\
set php=%ROOT_PATH%PHP5\
set username=%1%
set password=%2%
set port=%3%


%php%php.exe %php%/replace.php

if "%1%"=="" set username=admin
if "%2%"=="" set password=123456
if "%3%"=="" set port=3306
set "DATE_STR=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%%TIME:~3,2%%TIME:~6,2%"

//没有则新建数据 ,有则忽略
if exist %ROOT_PATH%\MariaDB\ (rd /s /q %ROOT_PATH%\MariaDB2) else (ren "%ROOT_PATH%\MariaDB2" "MariaDB")
//清缓存日志操作
if exist %ROOT_PATH%\Nginx\logs\*.log (del /f /s %ROOT_PATH%\Nginx\logs\*.log>null)
if exist %ROOT_PATH%\htdocs\Application\Runtime\Cache\Home\*.php (del /f /s %ROOT_PATH%\htdocs\Application\Runtime\Cache\Home\*.php>null)
if exist %ROOT_PATH%\htdocs\Application\Runtime\Data\_fields\*.php (del /f /s %ROOT_PATH%\htdocs\Application\Runtime\Data\_fields\*.php>null)

//查询是否有mysql服务,无则安装,有则停止删除服务再安装
//以下服务检查安装同上
SC QUERY mysql > NUL 
IF ERRORLEVEL 1060 GOTO NOTEXIST 
GOTO EXIST  
  
  
:NOTEXIST  
%~dp0%mysql_dir%mysqld -install
net start UPUPW_Database_N   
GOTO END  
  
:EXIST
net stop mysql  
sc delete mysql
::cd %~dp0%mysql_dir%
%~dp0%mysql_dir%mysqld -install
net start UPUPW_Database_N  
GOTO END  
  
:END
SC QUERY apache > NUL
IF ERRORLEVEL 1060 GOTO NOTEXIST
GOTO EXIST 

:EXIST 
sc stop apache 
sc delete apache 
rd/s/d %ROOT_PATH%/Apache2
GOTO END  
:NOTEXIST
GOTO END

:END
tasklist |findstr /i "php-cgi.exe"
if %errorlevel% == 0 (taskkill /f /im php-cgi.exe) 
SC QUERY UPUPW_Nginx > NUL  
IF ERRORLEVEL 1060 GOTO NOTEXIST  
GOTO EXIST

:EXIST
net stop UPUPW_Nginx
sc delete UPUPW_Nginx
%~dp0%nginx_dir%winsw.exe uninstall 
%~dp0%nginx_dir%winsw.exe install
net start UPUPW_Nginx
GOTO END  
:NOTEXIST
%~dp0%nginx_dir%winsw.exe install
net start UPUPW_Nginx
GOTO END

:END
SC QUERY UPUPW_PHPFPM > NUL  
IF ERRORLEVEL 1060 GOTO NOTEXIST  
GOTO EXIST    
:EXIST  
tasklist |findstr /i "phpfpm.exe"
if %errorlevel% == 0 (taskkill /f /im phpfpm.exe) 
sc delete UPUPW_PHPFPM
%ROOT_PATH%\PHP5\phpfpm\winsw.exe uninstall 
%ROOT_PATH%\PHP5\phpfpm\winsw.exe install
net start UPUPW_PHPFPM
GOTO END  
:NOTEXIST
%ROOT_PATH%\PHP5\phpfpm\winsw.exe install
net start UPUPW_PHPFPM
GOTO END

:END
SC QUERY UPUPW_MemCached_A > NUL  
IF ERRORLEVEL 1060 GOTO NOTEXIST  
GOTO EXIST  
  
:NOTEXIST  
%~dp0%mem_dir%memcached.exe -d install
net start UPUPW_MemCached_A   
GOTO END  
  
:EXIST  
net stop UPUPW_MemCached_A
sc delete UPUPW_MemCached_A
%~dp0%mem_dir%memcached.exe -d install
net start UPUPW_MemCached_A  
GOTO END  
  
:END
explorer http://127.0.0.1

你可能感兴趣的:(php打包exe)