Hướng dẫn dùng 12.0.2 monterey trong PHP

Replies

PHP has been removed in macOS Monterey.

Nội dung chính

  • How do you check if I have PHP installed on Mac?
  • Is PHP installed on Mac by default?
  • How do I update PHP on my Mac?
  • How do I reinstall PHP on Mac?

This is a giant step backwards. One of the nice things about macOS is the built in apache including PHP. Please reconsider this.

MAMP (https://www.mamp.info/en/mac/) is also an option.

No one should use system PHP anyway on macOS, It is an old and insecure version. I would recommend installing PHP via brew  https://github.com/shivammathur/homebrew-php

Can I add my tuppence-worth as another request for PHP to return to macOS 12. My first thought was that it was a licensing issue, but PHP uses a BSD-style license, so I can't understand the rationale for removing it.

Via MacPorts ( https://www.macports.org/ ):

port install php

It seems that it would be easier for one person at apple to upgrade php, rather then millions of users having to do so. Laziness.

The situation is similar for Perl. You can install perl separately via homebrew or macports, or via plenv (https://github.com/tokuhirom/plenv) or perlbrew (perlbrew.pl). This is preferred anyway since in the last few OSX releases, Apple has edited some of the internal Perl toolchain modules (such as ExtUtils::MakeMaker) in a broken way without talking to the developer team (or even responding to repeated pleas to fix their broken changes).

100% the right move. Dockerize your app and move on.

docker pull php:alpine

O.k., they removed php... some call it a good thing, some call it a bad thing. But; why remove PHP, but keep apache?

Buna hiç gerek yoktu. İşi zora sokmak demek bu. Php eski ve kullanılmayan bir dil değil.. Web tabanlı en gelişmiş dillerden biri durumunda ve güncellenmeye devam ediliyor. Apple desteğini çekerek iyi yapmadı. Umarım konu hakkında gerekli iyileştirmeleri yaparlar ve php desteği geri gelir.

It would be good if Apple allows custom installation that makes php executable into /usr/bin. Right now, the situation is breaking some tools, such as phpcs in PHPStorm. I tried to solve it by installing PHP with Homebrew, and it doesn't solve the problem.

What upsets me about the move to big sur and then monterey is that the upgrade program should check that i have apache, php and mysql and if it finds that there it should stop and say: hey man, this upgrade is going to create problems for you ... do you want to think about it before you proceed?

So what I'm going top do now is upload the (daily) backedup MySQL database to a hosting service that will also support PHP. Then I'll find the time to work out how to migrate my admin systems to Monterey - and then buy a new Macbook Pro - after I know how to migrate to that environment.

PHP is not insecure if you use a supported version: https://www.php.net/supported-versions.php

Apple is not the only company to stop bundling it and give the responsibility to the end user. Claris also used to ship PHP with FileMaker Server and removed that. So Claris had to provide instructions to get your own php set up for custom web publishing in the Claris Engineering blog: https://support.claris.com/s/answerview?anum=000035470&language=en_US

These instructions were helpful, as were Tim Perfitt's instructions at Two Canoes for installing PHP on Monterey as he did for his MDS project: https://twocanoes.com/knowledge-base/installing-php-7-on-macos-12-monterey/

Of course, in Monterey you have to code-sign the PHP you install. But it is not so hard if you follow the method from Rich Trouton at "Der Flounder": https://derflounder.wordpress.com/2019/04/10/notarizing-automator-applications/

Using all this, I have had great success installing my own PHP on both my macOS FileMaker Server for custom PHP web publishing and my macOS Web Server (for a web site, munki server and munkireport server and various remote proxies. (both Macs on Monterey).

I presented on this topic along with my methodology including a "recipe" at the MacDevOps YVR conference 2022: https://www.youtube.com/watch?v=XzxxLHojXhk&t=1s

In short, PHP on the Mac still lives - but its up to the end user to maintain it.

On OSX/MacOS do the following in a Terminal window:

Run php --ini at the prompt by typing it and pressing enter

Reports something like: Configuration File (php.ini) Path: /etc Loaded Configuration File: (none) Scan for additional .ini files in: /Library/Server/Web/Config/php Additional .ini files parsed: (none)

...this is because in /etc there is a file called /etc/php.ini.default as an example and to show it is not in use. You need to copy that file to the name php expects so that you can edit it, like this:

Type:

$  sudo cp /etc/php.ini.default /etc/php.ini       (and enter your password)

...then you will see if you run php --ini again that it now sees your new file:

Typing this: php --ini at the prompt should report this:

Configuration File (php.ini) Path: /etc
Loaded Configuration File:         /etc/php.ini
Scan for additional .ini files in: /Library/Server/Web/Config/php
Additional .ini files parsed:      (none)

...now edit /etc/php.ini - you want to make sure the following lines (NOT the same line starting with a semi-colon ';') are exactly as follows: log_errors = On (this will turn the logging engine on)

Then, in this section:

; Log errors to specified file. PHP's default behavior is to leave this value
; empty.
; http://php.net/error-log
; Example:
;error_log = php_errors.log
; Log errors to syslog (Event Log on Windows).
;error_log = syslog

If you want to log to the syslog (or Windows Event Log on Windows) then ;error_log = syslog should become error_log = syslog

However, if as you say, you want to log to a file, you uncomment by removing the leading semi colon to make ;error_log = php_errors.log become error_log = php_errors.log or using a full path to place it where you want.

Good luck

How do you check if I have PHP installed on Mac?

2 Answers.

Go to File > Preferences > User Settings > Settings.json..

Change the value of php. validate. executablePath according to the installed directory of php7. "php.validate.executablePath": "/Applications/MAMP/bin/php/php7.0.14/bin/php".

Relaunch VM Code..

Is PHP installed on Mac by default?

Installation on macOS ¶ PHP is bundled with macOS since macOS X (10.0. 0) prior to macOS Monterey (12.0. 0). Compiling is similar to the Unix installation guide.

How do I update PHP on my Mac?

To update the PHP version, update the brew using the command brew update . Then, use the command brew upgrade php . It upgrades the current version to the latest version of PHP. Then, restart the webserver to see the changes.

How do I reinstall PHP on Mac?

Listed below are the commands required for the manual installation of PHP 8.1 on macOS. Check the package naming on your macOS terminal correctly. 2 - In the macOS terminal, execute brew update to update Brew. 3 - Use the command brew install shivammathur/php/[email protected] for installing PHP 8.1.