自做Windows上界面美观的PHP集成环境软件
来源:互联网 发布:mac能用的绘画软件 编辑:程序博客网 时间:2024/05/19 23:57
windows上wnmp集成环境
界面展示一下:
源码:SalamanderWnmp
集成包下载 http://pan.baidu.com/s/1qYnUQZy
原因
平常工作中用Nginx比较多,网上虽然也有wnmp集成环境,但是感觉界面不好看,用起来不舒服,所有决定自己做一个吧。
原料
软件用的是C#,GUI框架是WPF(这个做出来更好看一点),先去官网下载PHP,用的是NTS版本的(因为这里PHP是以CGi的形式跑的),再去下载Windows版的Nginx和Mysql
代码
基类
public class WnmpProgram: INotifyPropertyChanged { public TextBlock statusLabel { get; set; } // Label that shows the programs status public string exeName { get; set; } // Location of the executable file public string procName { get; set; } // Name of the process public string progName { get; set; } // User-friendly name of the program public string workingDir { get; set; } // working directory public Log.LogSection progLogSection { get; set; } // LogSection of the program public string startArgs { get; set; } // Start Arguments public string stopArgs { get; set; } // Stop Arguments if KillStop is false public bool killStop { get; set; } // Kill process instead of stopping it gracefully public string confDir { get; set; } // Directory where all the programs configuration files are public string logDir { get; set; } // Directory where all the programs log files are public Ini Settings { get; set; } //public ContextMenuStrip configContextMenu { get; set; } // Displays all the programs config files in |confDir| //public ContextMenuStrip logContextMenu { get; set; } // Displays all the programs log files in |logDir| 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 WnmpProgram() { //configContextMenu = new ContextMenuStrip(); //logContextMenu = new ContextMenuStrip(); //configContextMenu.ItemClicked += configContextMenu_ItemClicked; //logContextMenu.ItemClicked += logContextMenu_ItemClicked; } /// <summary> /// 设置状态 /// </summary> public void SetStatus() { if (this.IsRunning() == true) { this.Running = true; } else { this.Running = false; } } public void StartProcess(string exe, string args, bool wait = false) { ps.StartInfo.FileName = exe; ps.StartInfo.Arguments = args; ps.StartInfo.UseShellExecute = false; ps.StartInfo.RedirectStandardOutput = true; ps.StartInfo.WorkingDirectory = workingDir; ps.StartInfo.CreateNoWindow = true; ps.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; ps.Start(); if (wait) { ps.WaitForExit(); } } public virtual void Start() { if(IsRunning()) { return; } try { StartProcess(exeName, startArgs); Log.wnmp_log_notice("Started " + progName, progLogSection); } catch (Exception ex) { Log.wnmp_log_error("Start(): " + ex.Message, progLogSection); } } public virtual void Stop() { if(!IsRunning()) { return; } if (killStop == false) StartProcess(exeName, stopArgs, true); var processes = Process.GetProcessesByName(procName); foreach (var process in processes) { process.Kill(); } Log.wnmp_log_notice("Stopped " + progName, progLogSection); } public void Restart() { this.Stop(); this.Start(); Log.wnmp_log_notice("Restarted " + progName, progLogSection); } //public void ConfigButton(object sender) //{ // var btnSender = (Button)sender; // var ptLowerLeft = new Point(0, btnSender.Height); // ptLowerLeft = btnSender.PointToScreen(ptLowerLeft); // configContextMenu.Show(ptLowerLeft); //} //private void logContextMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e) //{ // try { // Process.Start(Settings.Editor.Value, frmMain.StartupPath + logDir + e.ClickedItem.Text); // } catch (Exception ex) { // Log.wnmp_log_error(ex.Message, progLogSection); // } //} public bool IsRunning() { var processes = Process.GetProcessesByName(procName); return (processes.Length != 0); } }
开启mysql代码:
class MysqlProgram : WnmpProgram { private readonly ServiceController MysqlController = new ServiceController(); public const string ServiceName = "mysql-salamander"; public MysqlProgram() { MysqlController.MachineName = Environment.MachineName; MysqlController.ServiceName = ServiceName; } public void RemoveService() { StartProcess("cmd.exe", stopArgs, true); } public void InstallService() { StartProcess(exeName, startArgs, true); } 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(MysqlController.Status == ServiceControllerStatus.Running) { return; } try { MysqlController.Start(); MysqlController.WaitForStatus(ServiceControllerStatus.Running); Log.wnmp_log_notice("Started " + progName, progLogSection); } catch (Exception ex) { Log.wnmp_log_error("Start(): " + ex.Message, progLogSection); } } public override void Stop() { if(MysqlController.Status == ServiceControllerStatus.Stopped) { return; } try { MysqlController.Stop(); MysqlController.WaitForStatus(ServiceControllerStatus.Stopped); Log.wnmp_log_notice("Stopped " + progName, progLogSection); } catch (Exception ex) { Log.wnmp_log_notice("Stop(): " + ex.Message, progLogSection); } } }
开启php代码:
class PHPProgram : WnmpProgram { public PHPProgram() { ps.StartInfo.EnvironmentVariables.Add("PHP_FCGI_MAX_REQUESTS", "0"); // Disable auto killing PHP } private string GetPHPIniPath() { return MainWindow.StartupPath + "/" + Settings.PHPDirName.Value + "/php.ini"; } public override void Start() { if(this.IsRunning()) { return; } uint ProcessCount = Settings.PHP_Processes.Value; short port = Settings.PHP_Port.Value; string phpini = GetPHPIniPath(); try { for (var i = 1; i <= ProcessCount; i++) { StartProcess(exeName, String.Format("-b localhost:{0} -c {1}", port, phpini)); Log.wnmp_log_notice("Starting PHP " + i + "/" + ProcessCount + " on port: " + port, progLogSection); port++; } Log.wnmp_log_notice("PHP started", progLogSection); } catch (Exception ex) { Log.wnmp_log_error("StartPHP(): " + ex.Message, progLogSection); } } }
开启nginx
#这里要注意WorkingDirectory属性设置成nginx目录,这里是setup代码
private readonly WnmpProgram nginx = new WnmpProgram(); private void SetupNginx() { nginx.Settings = Settings; nginx.exeName = StartupPath + String.Format("{0}/nginx.exe", Settings.NginxDirName.Value); nginx.procName = "nginx"; nginx.progName = "Nginx"; nginx.workingDir = StartupPath + Settings.NginxDirName.Value; nginx.progLogSection = Log.LogSection.WNMP_NGINX; nginx.startArgs = ""; nginx.stopArgs = "-s stop"; nginx.killStop = false; nginx.statusLabel = lblNginx; nginx.confDir = "/conf/"; nginx.logDir = "/logs/"; }
其他功能
配置nginx,php,mysql目录名,管理php扩展
编程语言面板
下载后配置
注意
php 版本为7.0.1 64位版本,需要MSVC14 (Visual C++ 2015)运行库支持,下载:https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x64.exe
其实用户完全可以选择自己想要的php版本,放到集成环境的目录下即可(改一下配置,重启)
php
修改php.ini中的extension_dir配置,改为php目录下ext目录的绝对路径
nginx
修改conf目录下nginx.conf中的localhost虚拟主机的root(网站根目录),改为某个目录(譬如D:/web_root)的绝对路径(使用/,使用\会出错)
mysql
修改my.ini文件中base_dir和data_dir的配置,分别修改为mysql目录和mysql目录下的data目录的绝对路径
0 0
- 自做Windows上界面美观的PHP集成环境软件
- Wamp就是Windows Apache Mysql PHP集成安装环境,即在window下的apache、php和mysql的服务器软件。
- Windows 平台搭建 PHP 集成开发环境
- 在liunx环境下的集成 php 阿帕奇 和mysql的软件
- 命令模式之做我的齐天大圣还是奉旨上界
- [PHP学习] Windows下PHP集成环境配置
- WAMP5-v1.7.4 一款Windos Apache Mysql PHP集成安装环境的软件
- PHP-CMS的发展方向:简单,易用,美观
- 几款PHP集成开发环境软件推荐
- windows下安装集成php开发环境以及可能遇到的问题
- 自做的windows mobile地图控件
- wampserver2.0(Windows Apache Mysql PHP集成安装环境)
- windows下常见php集成环境安装包介绍
- windows下常见php集成环境安装包介绍(updated)
- Windows集成服务器环境Apache+Tomcat+Php+Jsp+MySQL
- Windows 7下配置AppSer PHP集成开发环境
- windows R2 2008 搭建Apache+mysql+php 集成环境教程
- windows下php+mysql+apache环境集成 简易版
- c++课本第一章
- Android 按两下退出APK的实现
- Fragment系列(三)------RecyclerFragment之UI部分
- thinkphp5部署于Linux中nginx多站点解决方案
- css常用样式笔记
- 自做Windows上界面美观的PHP集成环境软件
- Git常用指令
- iOS开发中常用的那些工具
- !~!
- iOS10 plist文件常用key值
- CMD命令
- 日志
- java--与君初相识
- VB如何获得本机IP