摘要:界面展示一下源碼集成包下載,關(guān)于這個(gè)軟件的講座,自己做個(gè)的集成環(huán)境原因平常工作中用比較多,網(wǎng)上雖然也有集成環(huán)境,但是感覺(jué)界面不好看,用起來(lái)不舒服,所有決定自己做一個(gè)吧。
界面展示一下:
源碼:SalamanderWnmp
集成包下載 ,關(guān)于這個(gè)軟件的講座,自己做個(gè)Nginx+PHP+MySQL的集成環(huán)境
平常工作中用Nginx比較多,網(wǎng)上雖然也有wnmp集成環(huán)境,但是感覺(jué)界面不好看,用起來(lái)不舒服,所有決定自己做一個(gè)吧。
特點(diǎn)免安裝,界面簡(jiǎn)潔
原料軟件用的是C#,GUI框架是WPF(這個(gè)做出來(lái)更好看一點(diǎn)),先去官網(wǎng)下載PHP,用的是NTS版本的(因?yàn)檫@里PHP是以CGi的形式跑的),再去下載Windows版的Nginx和Mysql
代碼 基類(lèi)(BaseProgram.cs)public abstract class BaseProgram: INotifyPropertyChanged { ///開(kāi)啟mysql代碼(Mysql.cs)/// exe 執(zhí)行文件位置 /// public string exeFile { get; set; } ////// 進(jìn)程名稱(chēng) /// public string procName { get; set; } ////// 進(jìn)程別名,用來(lái)在日志窗口顯示 /// public string programName { get; set; } ////// 進(jìn)程工作目錄(Nginx需要這個(gè)參數(shù)) /// public string workingDir { get; set; } ////// 進(jìn)程日志前綴 /// public Log.LogSection progLogSection { get; set; } ////// 進(jìn)程開(kāi)啟的參數(shù) /// public string startArgs { get; set; } ////// 關(guān)閉進(jìn)程參數(shù) /// public string stopArgs { get; set; } ////// /// public bool killStop { get; set; } ////// 進(jìn)程配置目錄 /// public string confDir { get; set; } ////// 進(jìn)程日志目錄 /// public string logDir { get; set; } ////// 進(jìn)程異常退出的記錄信息 /// protected string errOutput = ""; public Process ps = new Process(); public event PropertyChangedEventHandler PropertyChanged; // 是否在運(yùn)行 private bool running = false; public bool Running { get { return this.running; } set { this.running = value; if(PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("Running")); } } } ////// 設(shè)置狀態(tài) /// public void SetStatus() { if (IsRunning()) { this.Running = true; } else { this.Running = false; } } ////// 啟動(dòng)進(jìn)程 /// /// /// /// public void StartProcess(string exe, string args, EventHandler exitedHandler = null) { ps = new Process(); ps.StartInfo.FileName = exe; ps.StartInfo.Arguments = args; ps.StartInfo.UseShellExecute = false; ps.StartInfo.RedirectStandardOutput = true; ps.StartInfo.RedirectStandardError = true; ps.StartInfo.WorkingDirectory = workingDir; ps.StartInfo.CreateNoWindow = true; ps.Start(); // ErrorDataReceived event signals each time the process writes a line // to the redirected StandardError stream ps.ErrorDataReceived += (sender, e) => { errOutput += e.Data; }; ps.Exited += exitedHandler != null ? exitedHandler : (sender, e) => { if (!String.IsNullOrEmpty(errOutput)) { Log.wnmp_log_error("Failed: " + errOutput, progLogSection); errOutput = ""; } }; ps.EnableRaisingEvents = true; ps.BeginOutputReadLine(); ps.BeginErrorReadLine(); } public virtual void Start() { if(IsRunning()) { return; } try { StartProcess(exeFile, startArgs); Log.wnmp_log_notice("Started " + programName, progLogSection); } catch (Exception ex) { Log.wnmp_log_error("Start: " + ex.Message, progLogSection); } } public virtual void Stop() { if(!IsRunning()) { return; } if (killStop == false) StartProcess(exeFile, stopArgs); var processes = Process.GetProcessesByName(procName); foreach (var process in processes) { process.Kill(); } Log.wnmp_log_notice("Stopped " + programName, progLogSection); } ////// 殺死進(jìn)程 /// /// protected void KillProcess(string procName) { var processes = Process.GetProcessesByName(procName); foreach (var process in processes) { process.Kill(); } } public void Restart() { this.Stop(); this.Start(); Log.wnmp_log_notice("Restarted " + programName, progLogSection); } ////// 判斷程序是否運(yùn)行 /// ///public virtual bool IsRunning() { var processes = Process.GetProcessesByName(procName); return (processes.Length != 0); } /// /// 設(shè)置初始參數(shù) /// public abstract void Setup(); }
class MysqlProgram : BaseProgram { private readonly ServiceController mysqlController = new ServiceController(); public const string ServiceName = "mysql-salamander"; public MysqlProgram() { mysqlController.MachineName = Environment.MachineName; mysqlController.ServiceName = ServiceName; } ///開(kāi)啟php代碼(PHP.cs)/// 移除服務(wù) /// public void RemoveService() { StartProcess("cmd.exe", stopArgs); } ////// 安裝服務(wù) /// public void InstallService() { StartProcess(exeFile, startArgs); } ////// 獲取my.ini中mysql的端口 /// ///private static int GetIniMysqlListenPort() { string path = Common.APP_STARTUP_PATH + Common.Settings.MysqlDirName.Value + "/my.ini"; Regex regPort = new Regex(@"^s*ports*=s*(d+)"); Regex regMysqldSec = new Regex(@"^s*[mysqld]"); using (var sr = new StreamReader(path)) { bool isStart = false;// 是否找到了"[mysqld]" string str = null; while ((str = sr.ReadLine()) != null) { if (isStart && regPort.IsMatch(str)) { MatchCollection matches = regPort.Matches(str); foreach (Match match in matches) { GroupCollection groups = match.Groups; if (groups.Count > 1) { try { return Int32.Parse(groups[1].Value); } catch { return -1; } } } } // [mysqld]段開(kāi)始 if (regMysqldSec.IsMatch(str)) { isStart = true; } } } return -1; } /// /// 服務(wù)是否存在 /// ///public bool ServiceExists() { ServiceController[] services = ServiceController.GetServices(); foreach (var service in services) { if (service.ServiceName == ServiceName) return true; } return false; } public override void Start() { if (IsRunning()) return; try { if (!File.Exists(Common.APP_STARTUP_PATH + Common.Settings.MysqlDirName.Value + "/my.ini")) { Log.wnmp_log_error("my.ini file not exist", progLogSection); return; } int port = GetIniMysqlListenPort();// -1表示提取出錯(cuò) if (port != -1 && PortScanHelper.IsPortInUseByTCP(port)) { Log.wnmp_log_error("Port " + port + " is used", progLogSection); return; } mysqlController.Start(); Log.wnmp_log_notice("Started " + programName, progLogSection); } catch (Exception ex) { Log.wnmp_log_error("Start(): " + ex.Message, progLogSection); } } public override void Stop() { if(!IsRunning()) { return; } try { mysqlController.Stop(); mysqlController.WaitForStatus(ServiceControllerStatus.Stopped); Log.wnmp_log_notice("Stopped " + programName, progLogSection); } catch (Exception ex) { Log.wnmp_log_error("Stop(): " + ex.Message, progLogSection); } } /// /// 通過(guò)ServiceController判斷服務(wù)是否在運(yùn)行 /// ///public override bool IsRunning() { mysqlController.Refresh(); try { return mysqlController.Status == ServiceControllerStatus.Running; } catch { return false; } } public override void Setup() { this.exeFile = Common.APP_STARTUP_PATH + String.Format("{0}/bin/mysqld.exe", Common.Settings.MysqlDirName.Value); this.procName = "mysqld"; this.programName = "MySQL"; this.workingDir = Common.APP_STARTUP_PATH + Common.Settings.MysqlDirName.Value; this.progLogSection = Log.LogSection.WNMP_MARIADB; this.startArgs = "--install-manual " + MysqlProgram.ServiceName + " --defaults-file="" + Common.APP_STARTUP_PATH + String.Format("{0}my.ini"", Common.Settings.MysqlDirName.Value); this.stopArgs = "/c sc delete " + MysqlProgram.ServiceName; this.killStop = true; this.confDir = "/mysql/"; this.logDir = "/mysql/data/"; } /// /// 打開(kāi)MySQL Client命令行 /// public static void OpenMySQLClientCmd() { Process ps = new Process(); ps.StartInfo.FileName = Common.APP_STARTUP_PATH + String.Format("{0}/bin/mysql.exe", Common.Settings.MysqlDirName.Value); ps.StartInfo.Arguments = String.Format("-u{0} -p{1}", Common.Settings.MysqlClientUser.Value, Common.Settings.MysqlClientUserPass.Value); ps.StartInfo.UseShellExecute = false; ps.StartInfo.CreateNoWindow = false; ps.Start(); } }
class PHPProgram : BaseProgram { private const string PHP_CGI_NAME = "php-cgi"; private const string PHP_MAX_REQUEST = "PHP_FCGI_MAX_REQUESTS"; private Object locker = new Object(); private uint FCGI_NUM = 0; private bool watchPHPFCGI = true; private Thread watchThread; private void DecreaseFCGINum() { lock (locker) { FCGI_NUM--; } } private void IncreaseFCGINum() { lock (locker) { FCGI_NUM++; } } public PHPProgram() { if (Environment.GetEnvironmentVariable(PHP_MAX_REQUEST) == null) Environment.SetEnvironmentVariable(PHP_MAX_REQUEST, "300"); } public override void Start() { if(!IsRunning() && PortScanHelper.IsPortInUseByTCP(Common.Settings.PHP_Port.Value)) { Log.wnmp_log_error("Port " + Common.Settings.PHP_Port.Value + " is used", progLogSection); } else if(!IsRunning()) { for (int i = 0; i < Common.Settings.PHPProcesses.Value; i++) { StartProcess(this.exeFile, this.startArgs, (s, args) => { DecreaseFCGINum(); }); IncreaseFCGINum(); } WatchPHPFCGINum(); Log.wnmp_log_notice("Started " + programName, progLogSection); } } ///開(kāi)啟nginx(Nginx.cs)/// 異步查看php-cgi數(shù)量 /// /// ///private void WatchPHPFCGINum() { watchPHPFCGI = true; watchThread = new Thread(() => { while (watchPHPFCGI) { uint delta = Common.Settings.PHPProcesses.Value - FCGI_NUM; for (int i = 0; i < delta; i++) { StartProcess(this.exeFile, this.startArgs, (s, args) => { DecreaseFCGINum(); }); IncreaseFCGINum(); Console.WriteLine("restart a php-cgi"); } } }); watchThread.Start(); } public void StopWatchPHPFCGINum() { watchPHPFCGI = false; } public override void Stop() { if (!IsRunning()) { return; } StopWatchPHPFCGINum(); KillProcess(PHP_CGI_NAME); Log.wnmp_log_notice("Stopped " + programName, progLogSection); } public override void Setup() { string phpDirPath = Common.APP_STARTUP_PATH + Common.Settings.PHPDirName.Value; this.exeFile = string.Format("{0}/php-cgi.exe", phpDirPath); this.procName = PHP_CGI_NAME; this.programName = "PHP"; this.workingDir = phpDirPath; this.progLogSection = Log.LogSection.WNMP_PHP; this.startArgs = String.Format("-b 127.0.0.1:{0} -c {1}/php.ini", Common.Settings.PHP_Port.Value, phpDirPath); this.killStop = true; this.confDir = "/php/"; this.logDir = "/php/logs/"; } }
這里要注意WorkingDirectory屬性設(shè)置成nginx目錄
class NginxProgram : BaseProgram { public override void Setup() { this.exeFile = Common.APP_STARTUP_PATH + String.Format("{0}/nginx.exe", Common.Settings.NginxDirName.Value); this.procName = "nginx"; this.programName = "Nginx"; this.workingDir = Common.APP_STARTUP_PATH + Common.Settings.NginxDirName.Value; this.progLogSection = Log.LogSection.WNMP_NGINX; this.startArgs = ""; this.stopArgs = "-s stop"; this.killStop = false; this.confDir = "/conf/"; this.logDir = "/logs/"; } ///其他功能/// 打開(kāi)命令行 /// public static void OpenNginxtCmd() { Process ps = new Process(); ps.StartInfo.FileName = "cmd.exe"; ps.StartInfo.Arguments = ""; ps.StartInfo.UseShellExecute = false; ps.StartInfo.CreateNoWindow = false; ps.StartInfo.WorkingDirectory = Common.APP_STARTUP_PATH + Common.Settings.NginxDirName.Value; ps.Start(); } }
配置nginx,php,mysql目錄名,管理php擴(kuò)展
編程語(yǔ)言面板 注意php 版本為7.1.12 64位版本,需要MSVC14 (Visual C++ 2015)運(yùn)行庫(kù)支持,下載:https://download.microsoft.co...
其實(shí)用戶(hù)完全可以選擇自己想要的php版本,放到集成環(huán)境的目錄下即可(改一下配置,重啟)
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/39372.html
摘要:界面展示一下源碼集成包下載,關(guān)于這個(gè)軟件的講座,自己做個(gè)的集成環(huán)境原因平常工作中用比較多,網(wǎng)上雖然也有集成環(huán)境,但是感覺(jué)界面不好看,用起來(lái)不舒服,所有決定自己做一個(gè)吧。 界面展示一下:showImg(https://segmentfault.com/img/bV1sdE?w=614&h=432); 源碼:SalamanderWnmp集成包下載 ,關(guān)于這個(gè)軟件的講座,自己做個(gè)Nginx+...
摘要:視覺(jué)組接觸的軟件進(jìn)行視覺(jué)開(kāi)發(fā)會(huì)用到各種各樣的軟件開(kāi)發(fā)環(huán)境輔助工具等,所以很有必要了解一些相關(guān)的快捷鍵命令使用技巧。沒(méi)有這樣保姆級(jí)的,并不存在一款能夠自動(dòng)為你生成的軟件。一款錄制屏幕的軟件。 --NeoZng【[email protected]】 3.視覺(jué)組接觸的軟件 進(jìn)行視覺(jué)開(kāi)發(fā)會(huì)用到...
摘要:我之前剛開(kāi)始也是用的服務(wù)器,當(dāng)然我用的是配置較低的學(xué)生云服務(wù)器,剛開(kāi)始掛幾個(gè)網(wǎng)頁(yè)是沒(méi)有任何問(wèn)題的,但是當(dāng)我把我的一個(gè)小項(xiàng)目掛載到服務(wù)器端后,一星期崩了三回。哪個(gè)主機(jī)管理系統(tǒng)好用?我現(xiàn)在用的是zkeys,以前叫宏杰系統(tǒng),它可以管理包括計(jì)算、網(wǎng)絡(luò)、存儲(chǔ)等資源,功能模塊涵蓋云服務(wù)器、虛擬主機(jī)、托管等業(yè)務(wù)等,支持一鍵安裝Linux及Windows等多種環(huán)境,然后系統(tǒng)集成了完善的財(cái)務(wù)系統(tǒng)、工單系統(tǒng)、備...
閱讀 3089·2021-11-25 09:43
閱讀 2266·2021-09-07 10:28
閱讀 3604·2021-08-11 11:14
閱讀 2788·2019-08-30 13:49
閱讀 3554·2019-08-29 18:41
閱讀 1174·2019-08-29 11:26
閱讀 1983·2019-08-26 13:23
閱讀 3382·2019-08-26 10:43