1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 03:50:08 +02:00

Add option to restart nginx, open valet config

This commit is contained in:
2020-02-20 17:24:21 +01:00
parent e683b6bc9a
commit 67e80aac8d
4 changed files with 85 additions and 19 deletions

View File

@ -1,6 +1,6 @@
# PHP Monitor
PHP Monitor (or phpmon) is a macOS utility that runs on your Mac and displays the active PHP version in your status bar.
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).
<img src="./docs/screenshot.png" width="278px" alt="phpmon screenshot"/>
@ -8,19 +8,13 @@ For me, it comes in handy when running multiple versions of PHP with Homebrew an
## System requirements
**Minimal system requirements**
* macOS 10.14 or higher
* PHP 7.4 installed via Homebrew
* Laravel Valet 2.3 or higher installed
**Recommended system**
* macOS 10.15 Catalina
* PHP 7.4 installed with Homebrew 2.2
* PHP 7.4 installed with Homebrew 2.x
- other versions of PHP are optional
- includes support for PHP 5.6 and PHP 7.0 [as well](https://github.com/eXolnet/homebrew-deprecated)
* Laravel Valet 2.5.x installed
* Laravel Valet 2.8
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.
## Why I built this
@ -48,8 +42,9 @@ The utility runs the following commands:
- Unlink all detected PHP versions
- Switch to PHP 7.4 (this is done in order to ensure that Valet works, even when attempting to use PHP 5.6)
- Tell Valet to switch to a specific PHP version
- Stop all php-fpm service instances
- Link the desired version of PHP
- Start the correct php-fpm service for the desired PHP version
### Want to know more?
@ -59,6 +54,8 @@ This app isn't very complicated after all. In the end, this just (conveniently)
## Troubleshooting
---
### Reasons for alerts at startup
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
Follow instructions as specified in the alert in order to resolve any issues.
### Still seeing another PHP version (from before switching versions)?
---
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:
### Laravel Valet is using a different version of PHP than what is active in PHP Monitor and in my terminal!
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:
sudo brew services list | grep php
This will present to you a list of services, like so (depending on the installed versions of PHP):
```
php started root /Library/LaunchDaemons/homebrew.mxcl.php.plist
php@5.6 stopped
php@7.0 stopped
php@7.1 stopped
php@7.2 stopped
php@7.3 stopped
```
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:
sudo brew services stop {service_name}
So in order to disable PHP 7.3, you'd need to run:
sudo brew services stop php@7.3
If you notice that PHP FPM is running as your own user account, you can turn off the service by running:
brew services stop php@7.3
The easiest way to make sure that PHP Monitor works again is to run the following commands:
sudo brew services stop php
sudo brew services stop php@7.3
sudo brew services stop php@7.2
sudo brew services stop php@7.1
sudo brew services stop php@7.0
sudo brew services stop php@5.6
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.
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}`).
You should only have to do this **once**, and then PHP Monitor should work as usual.
---
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.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 314 KiB

After

Width:  |  Height:  |  Size: 615 KiB

View File

@ -35,6 +35,11 @@ class Actions {
}
}
public static func restartNginx()
{
Shell.user.run("sudo brew services restart nginx")
}
public static func switchToPhpVersion(version: String, availableVersions: [String]) {
availableVersions.forEach { (version) in
// Unlink the current version
@ -65,6 +70,11 @@ class Actions {
NSWorkspace.shared.activateFileViewerSelecting(files as [URL])
}
public static func openValetConfigFolder() {
let files = [NSURL(fileURLWithPath: NSString(string: "~/.config/valet").expandingTildeInPath)];
NSWorkspace.shared.activateFileViewerSelecting(files as [URL])
}
public static func XdebugFound(_ version: String) -> Bool {
let command = """
grep -q 'zend_extension="xdebug.so"' /usr/local/etc/php/\(version)/php.ini; [ $? -eq 0 ] && echo "YES" || echo "NO"

View File

@ -57,7 +57,9 @@ class MainMenu: NSObject, NSWindowDelegate {
menu.addItem(menuItem)
}
menu.addItem(NSMenuItem.separator())
menu.addItem(NSMenuItem(title: "Restart php-fpm service", action: #selector(self.restartService), keyEquivalent: "r"))
menu.addItem(NSMenuItem(title: "Active Services", action: nil, keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "Restart php-fpm service", action: #selector(self.restartPhpFpm), keyEquivalent: "f"))
menu.addItem(NSMenuItem(title: "Restart nginx service", action: #selector(self.restartNginx), keyEquivalent: "n"))
menu.addItem(NSMenuItem.separator())
}
if (App.shared.busy) {
@ -65,7 +67,11 @@ class MainMenu: NSObject, NSWindowDelegate {
menu.addItem(NSMenuItem.separator())
}
if (App.shared.currentVersion != nil) {
menu.addItem(NSMenuItem(title: "Configuration", action: nil, keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "Valet configuration (.config/valet)", action: #selector(self.openValetConfigFolder), keyEquivalent: "v"))
menu.addItem(NSMenuItem(title: "PHP configuration file (php.ini)", action: #selector(self.openActiveConfigFolder), keyEquivalent: "c"))
menu.addItem(NSMenuItem.separator())
menu.addItem(NSMenuItem(title: "Enabled Extensions", action: nil, keyEquivalent: ""))
let xdebugFound = App.shared.currentVersion!.xdebugFound
if (xdebugFound) {
let xdebugOn = App.shared.currentVersion!.xdebugEnabled
@ -135,12 +141,13 @@ class MainMenu: NSObject, NSWindowDelegate {
}
}
@objc public func restartService() {
private func waitAndExecute(_ execute: @escaping () -> Void)
{
App.shared.busy = true
self.setBusyImage()
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
self.update()
Actions.restartPhpFpm()
execute()
App.shared.busy = false
DispatchQueue.main.async {
self.updatePhpVersionInStatusBar()
@ -149,6 +156,18 @@ class MainMenu: NSObject, NSWindowDelegate {
}
}
@objc public func restartPhpFpm() {
self.waitAndExecute({
Actions.restartPhpFpm()
})
}
@objc public func restartNginx() {
self.waitAndExecute({
Actions.restartNginx()
})
}
@objc public func openAbout() {
NSApplication.shared.activate(ignoringOtherApps: true)
NSApplication.shared.orderFrontStandardAboutPanel()
@ -158,6 +177,10 @@ class MainMenu: NSObject, NSWindowDelegate {
Actions.openPhpConfigFolder(version: App.shared.currentVersion!.short)
}
@objc public func openValetConfigFolder() {
Actions.openValetConfigFolder()
}
@objc public func switchToPhpVersion(sender: AnyObject) {
self.setBusyImage()
let index = sender.tag!