Skip to content

Commit 67e80aa

Browse files
✨ Add option to restart nginx, open valet config
1 parent e683b6b commit 67e80aa

File tree

4 files changed

+85
-19
lines changed

4 files changed

+85
-19
lines changed

README.md

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
# PHP Monitor
22

3-
PHP Monitor (or phpmon) is a macOS utility that runs on your Mac and displays the active PHP version in your status bar.
3+
PHP Monitor (or phpmon) is a macOS utility that runs on your Mac and displays the active PHP version in your status bar. It also gives you quick access to various useful functionality (like switching PHP versions, restarting services, accessing configuration files, and more).
44

55
<img src="./docs/screenshot.png" width="278px" alt="phpmon screenshot"/>
66

77
For me, it comes in handy when running multiple versions of PHP with Homebrew and you wish to be able to see at a glance which version is currently linked & active with Laravel Valet, and switch between versions.
88

99
## System requirements
1010

11-
**Minimal system requirements**
12-
13-
* macOS 10.14 or higher
14-
* PHP 7.4 installed via Homebrew
15-
* Laravel Valet 2.3 or higher installed
16-
17-
**Recommended system**
18-
1911
* macOS 10.15 Catalina
20-
* PHP 7.4 installed with Homebrew 2.2
12+
* PHP 7.4 installed with Homebrew 2.x
2113
- other versions of PHP are optional
2214
- includes support for PHP 5.6 and PHP 7.0 [as well](https://github.com/eXolnet/homebrew-deprecated)
23-
* Laravel Valet 2.5.x installed
15+
* Laravel Valet 2.8
16+
17+
If you're looking to run PHP Monitor in combination with an older version of macOS or Laravel Valet, please check out the older releases of the software.
2418

2519
## Why I built this
2620

@@ -48,8 +42,9 @@ The utility runs the following commands:
4842

4943
- Unlink all detected PHP versions
5044
- Switch to PHP 7.4 (this is done in order to ensure that Valet works, even when attempting to use PHP 5.6)
51-
- Tell Valet to switch to a specific PHP version
45+
- Stop all php-fpm service instances
5246
- Link the desired version of PHP
47+
- Start the correct php-fpm service for the desired PHP version
5348

5449
### Want to know more?
5550

@@ -59,6 +54,8 @@ This app isn't very complicated after all. In the end, this just (conveniently)
5954

6055
## Troubleshooting
6156

57+
---
58+
6259
### Reasons for alerts at startup
6360

6461
PHP Monitor performs some integrity checks to ensure a good experience when using the app. You'll get a message telling you that PHP Monitor won't work correctly in the following scenarios:
@@ -71,12 +68,48 @@ PHP Monitor performs some integrity checks to ensure a good experience when usin
7168

7269
Follow instructions as specified in the alert in order to resolve any issues.
7370

74-
### Still seeing another PHP version (from before switching versions)?
71+
---
72+
73+
### Laravel Valet is using a different version of PHP than what is active in PHP Monitor and in my terminal!
74+
75+
If you're still seeing another version of PHP in your scripts — e.g. when running `phpinfo()` — I recommend you shut down all PHP services that are currently active. You can find out what services are active by running:
76+
77+
sudo brew services list | grep php
78+
79+
This will present to you a list of services, like so (depending on the installed versions of PHP):
7580

76-
If you're still seeing an old version of PHP in your scripts — e.g. when running `phpinfo()` — I recommend you shut down the PHP service by running:
81+
```
82+
php started root /Library/LaunchDaemons/homebrew.mxcl.php.plist
83+
84+
85+
86+
87+
88+
```
89+
90+
You'll want to make sure that **only one service is running** and that it is running **as `root`**. You can terminate a service by running:
91+
92+
sudo brew services stop {service_name}
93+
94+
So in order to disable PHP 7.3, you'd need to run:
95+
96+
sudo brew services stop [email protected]
97+
98+
If you notice that PHP FPM is running as your own user account, you can turn off the service by running:
99+
100+
brew services stop [email protected]
101+
102+
The easiest way to make sure that PHP Monitor works again is to run the following commands:
77103

78104
sudo brew services stop php
105+
sudo brew services stop [email protected]
106+
sudo brew services stop [email protected]
107+
sudo brew services stop [email protected]
108+
sudo brew services stop [email protected]
109+
sudo brew services stop [email protected]
110+
111+
Then, in PHP Monitor, select "Restart php-fpm service", which should start the service. Alternatively, you can run `sudo brew services start php@{x}` where `{x}` is your preferred version of PHP (for the latest version of PHP, you can omit `@{x}`).
79112

80-
Please note that PHP Monitor will not be able to stop this service (it doesn't run as an administrator), so you'll need to handle this yourself.
113+
---
81114

82-
You should only have to do this **once**, and then PHP Monitor should work as usual.
115+
If this software has been useful to you, star the repository so I know that the software is being used. I did not include any tracking or analytics software, so if you encounter issues, let me know via an issue.

docs/screenshot.png

302 KB
Loading

phpmon/Classes/Commands/Actions.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class Actions {
3535
}
3636
}
3737

38+
public static func restartNginx()
39+
{
40+
Shell.user.run("sudo brew services restart nginx")
41+
}
42+
3843
public static func switchToPhpVersion(version: String, availableVersions: [String]) {
3944
availableVersions.forEach { (version) in
4045
// Unlink the current version
@@ -65,6 +70,11 @@ class Actions {
6570
NSWorkspace.shared.activateFileViewerSelecting(files as [URL])
6671
}
6772

73+
public static func openValetConfigFolder() {
74+
let files = [NSURL(fileURLWithPath: NSString(string: "~/.config/valet").expandingTildeInPath)];
75+
NSWorkspace.shared.activateFileViewerSelecting(files as [URL])
76+
}
77+
6878
public static func XdebugFound(_ version: String) -> Bool {
6979
let command = """
7080
grep -q 'zend_extension="xdebug.so"' /usr/local/etc/php/\(version)/php.ini; [ $? -eq 0 ] && echo "YES" || echo "NO"

phpmon/Singletons/MainMenu.swift

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,21 @@ class MainMenu: NSObject, NSWindowDelegate {
5757
menu.addItem(menuItem)
5858
}
5959
menu.addItem(NSMenuItem.separator())
60-
menu.addItem(NSMenuItem(title: "Restart php-fpm service", action: #selector(self.restartService), keyEquivalent: "r"))
60+
menu.addItem(NSMenuItem(title: "Active Services", action: nil, keyEquivalent: ""))
61+
menu.addItem(NSMenuItem(title: "Restart php-fpm service", action: #selector(self.restartPhpFpm), keyEquivalent: "f"))
62+
menu.addItem(NSMenuItem(title: "Restart nginx service", action: #selector(self.restartNginx), keyEquivalent: "n"))
6163
menu.addItem(NSMenuItem.separator())
6264
}
6365
if (App.shared.busy) {
6466
menu.addItem(NSMenuItem(title: "PHP Monitor is busy...", action: nil, keyEquivalent: ""))
6567
menu.addItem(NSMenuItem.separator())
6668
}
6769
if (App.shared.currentVersion != nil) {
70+
menu.addItem(NSMenuItem(title: "Configuration", action: nil, keyEquivalent: ""))
71+
menu.addItem(NSMenuItem(title: "Valet configuration (.config/valet)", action: #selector(self.openValetConfigFolder), keyEquivalent: "v"))
6872
menu.addItem(NSMenuItem(title: "PHP configuration file (php.ini)", action: #selector(self.openActiveConfigFolder), keyEquivalent: "c"))
73+
menu.addItem(NSMenuItem.separator())
74+
menu.addItem(NSMenuItem(title: "Enabled Extensions", action: nil, keyEquivalent: ""))
6975
let xdebugFound = App.shared.currentVersion!.xdebugFound
7076
if (xdebugFound) {
7177
let xdebugOn = App.shared.currentVersion!.xdebugEnabled
@@ -135,12 +141,13 @@ class MainMenu: NSObject, NSWindowDelegate {
135141
}
136142
}
137143

138-
@objc public func restartService() {
144+
private func waitAndExecute(_ execute: @escaping () -> Void)
145+
{
139146
App.shared.busy = true
140147
self.setBusyImage()
141148
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
142149
self.update()
143-
Actions.restartPhpFpm()
150+
execute()
144151
App.shared.busy = false
145152
DispatchQueue.main.async {
146153
self.updatePhpVersionInStatusBar()
@@ -149,6 +156,18 @@ class MainMenu: NSObject, NSWindowDelegate {
149156
}
150157
}
151158

159+
@objc public func restartPhpFpm() {
160+
self.waitAndExecute({
161+
Actions.restartPhpFpm()
162+
})
163+
}
164+
165+
@objc public func restartNginx() {
166+
self.waitAndExecute({
167+
Actions.restartNginx()
168+
})
169+
}
170+
152171
@objc public func openAbout() {
153172
NSApplication.shared.activate(ignoringOtherApps: true)
154173
NSApplication.shared.orderFrontStandardAboutPanel()
@@ -158,6 +177,10 @@ class MainMenu: NSObject, NSWindowDelegate {
158177
Actions.openPhpConfigFolder(version: App.shared.currentVersion!.short)
159178
}
160179

180+
@objc public func openValetConfigFolder() {
181+
Actions.openValetConfigFolder()
182+
}
183+
161184
@objc public func switchToPhpVersion(sender: AnyObject) {
162185
self.setBusyImage()
163186
let index = sender.tag!

0 commit comments

Comments
 (0)