摘要:界面展示一下源碼集成包下載,關于這個軟件的講座,自己做個的集成環境原因平常工作中用比較多,網上雖然也有集成環境,但是感覺界面不好看,用起來不舒服,所有決定自己做一個吧。
界面展示一下:
源碼:SalamanderWnmp
集成包下載 ,關于這個軟件的講座,自己做個Nginx+PHP+MySQL的集成環境
平常工作中用Nginx比較多,網上雖然也有wnmp集成環境,但是感覺界面不好看,用起來不舒服,所有決定自己做一個吧。
特點免安裝,界面簡潔
原料軟件用的是C#,GUI框架是WPF(這個做出來更好看一點),先去官網下載PHP,用的是NTS版本的(因為這里PHP是以CGi的形式跑的),再去下載Windows版的Nginx和Mysql
代碼 基類(BaseProgram.cs)public abstract class BaseProgram: INotifyPropertyChanged { ///開啟mysql代碼(Mysql.cs)/// exe 執行文件位置 /// public string exeFile { get; set; } ////// 進程名稱 /// public string procName { get; set; } ////// 進程別名,用來在日志窗口顯示 /// public string programName { get; set; } ////// 進程工作目錄(Nginx需要這個參數) /// public string workingDir { get; set; } ////// 進程日志前綴 /// public Log.LogSection progLogSection { get; set; } ////// 進程開啟的參數 /// public string startArgs { get; set; } ////// 關閉進程參數 /// public string stopArgs { get; set; } ////// /// public bool killStop { get; set; } ////// 進程配置目錄 /// public string confDir { get; set; } ////// 進程日志目錄 /// public string logDir { get; set; } ////// 進程異常退出的記錄信息 /// protected string errOutput = ""; public Process ps = new Process(); public event PropertyChangedEventHandler PropertyChanged; // 是否在運行 private bool running = false; public bool Running { get { return this.running; } set { this.running = value; if(PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("Running")); } } } ////// 設置狀態 /// public void SetStatus() { if (IsRunning()) { this.Running = true; } else { this.Running = false; } } ////// 啟動進程 /// /// /// /// 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); } ////// 殺死進程 /// /// 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); } ////// 判斷程序是否運行 /// ///public virtual bool IsRunning() { var processes = Process.GetProcessesByName(procName); return (processes.Length != 0); } /// /// 設置初始參數 /// 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; } ///開啟php代碼(PHP.cs)/// 移除服務 /// public void RemoveService() { StartProcess("cmd.exe", stopArgs); } ////// 安裝服務 /// 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]段開始 if (regMysqldSec.IsMatch(str)) { isStart = true; } } } return -1; } /// /// 服務是否存在 /// ///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表示提取出錯 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); } } /// /// 通過ServiceController判斷服務是否在運行 /// ///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/"; } /// /// 打開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); } } ///開啟nginx(Nginx.cs)/// 異步查看php-cgi數量 /// /// ///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屬性設置成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/"; } ///其他功能/// 打開命令行 /// 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擴展
編程語言面板 注意php 版本為7.1.12 64位版本,需要MSVC14 (Visual C++ 2015)運行庫支持,下載:https://download.microsoft.co...
其實用戶完全可以選擇自己想要的php版本,放到集成環境的目錄下即可(改一下配置,重啟)
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/39372.html
摘要:界面展示一下源碼集成包下載,關于這個軟件的講座,自己做個的集成環境原因平常工作中用比較多,網上雖然也有集成環境,但是感覺界面不好看,用起來不舒服,所有決定自己做一個吧。 界面展示一下:showImg(https://segmentfault.com/img/bV1sdE?w=614&h=432); 源碼:SalamanderWnmp集成包下載 ,關于這個軟件的講座,自己做個Nginx+...
摘要:視覺組接觸的軟件進行視覺開發會用到各種各樣的軟件開發環境輔助工具等,所以很有必要了解一些相關的快捷鍵命令使用技巧。沒有這樣保姆級的,并不存在一款能夠自動為你生成的軟件。一款錄制屏幕的軟件。 --NeoZng【neozng1@hnu.edu.cn】 3.視覺組接觸的軟件 進行視覺開發會用到...
摘要:我之前剛開始也是用的服務器,當然我用的是配置較低的學生云服務器,剛開始掛幾個網頁是沒有任何問題的,但是當我把我的一個小項目掛載到服務器端后,一星期崩了三回。哪個主機管理系統好用?我現在用的是zkeys,以前叫宏杰系統,它可以管理包括計算、網絡、存儲等資源,功能模塊涵蓋云服務器、虛擬主機、托管等業務等,支持一鍵安裝Linux及Windows等多種環境,然后系統集成了完善的財務系統、工單系統、備...
閱讀 3072·2021-11-25 09:43
閱讀 2251·2021-09-07 10:28
閱讀 3543·2021-08-11 11:14
閱讀 2777·2019-08-30 13:49
閱讀 3544·2019-08-29 18:41
閱讀 1163·2019-08-29 11:26
閱讀 1976·2019-08-26 13:23
閱讀 3372·2019-08-26 10:43