In this post, we'll be looking at how to install PHP 8 on macOS Big Sur using Homebrew. By right the steps will also work for the previous macOS versions like Catalina and Mojave.
Nội dung chính
- Step 1: Install Homebrew
- Step 2: Install PHP
- Step 3: The php.ini Config
- Step 4: Check if PHP is running
- Step 5: Checking PHP Version
- Alternative Tags
Step 1: Install Homebrew
The first step is to install Homebrew and this is a tool [package manager for macOS] that will allow us to install easily PHP and
basically any other package/tools.
/bin/bash -c "$[curl -fsSL //raw.githubusercontent.com/Homebrew/install/HEAD/install.sh]"
Step 2: Install PHP
To install PHP we can use the command below. The first command will automatically install the latest version of PHP which is at the current moment of writing this post version 8.
brew install php
If other versions may be preferred we can specify the PHP version and the code will look like the following.
brew install [email protected]
Step 3: The php.ini Config
The default PHP configuration should be sufficient to get started but if there are any other configurations, we can change them through the php.ini located on this path. Do note the PHP version number which in this case is version 8.
/usr/local/etc/php/8.0/php.ini
Step 4: Check if PHP is running
To check if PHP is already running we can make use of the brew services command. First, we can list the services that we have
installed.
brew services list
If PHP is not started we can then run the command below to start the service in the background.
brew services start [email protected]
Step 5: Checking PHP Version
Lastly to check the PHP version do run:
php -v
By now you will have PHP running on the background process and every time you logged in to the system it will start by default. Thanks for reading and have a good try.
- Upgrade to PHP 8 with Homebrew on Mac
- Setting up PHP 8 on macOS Big Sur using Homebrew
General-purpose scripting language
//www.php.net/
License: PHP-3.01
Formula JSON API: /api/formula/
Bottle JSON API: /api/bottle/
Formula code: on GitHub
Bottle [binary package] installation support provided for:
monterey | ✅ |
big sur | ✅ |
catalina | ✅ |
64-bit linux | ✅ |
monterey | ✅ |
big sur | ✅ |
Current versions:
Other versions:
7.4.30 | General-purpose scripting language | |
7.3.33 | General-purpose scripting language | |
7.2.34 | General-purpose scripting language |
Revision: 1
Keg-only
Depends on:
apr | 1.7.0 | Apache Portable Runtime library |
apr-util | 1.6.1 | Companion library to apr, the Apache Portable Runtime library |
argon2 | 20190702 | Password hashing library and CLI utility |
aspell | 0.60.8 | Spell checker with better logic than ispell |
autoconf | 2.71 | Automatic configure script builder |
curl | 7.85.0 | Get a file from an HTTP, HTTPS or FTP server |
freetds | 1.3.13 | Libraries to talk to Microsoft SQL Server and Sybase databases |
gd | 2.3.3 | Graphics library to dynamically manipulate images |
gettext | 0.21 | GNU internationalization [i18n] and localization [l10n] library |
gmp | 6.2.1 | GNU multiple precision arithmetic library |
icu4c | 71.1 | C/C++ and Java libraries for Unicode and globalization |
krb5 | 1.20 | Network authentication protocol |
libpq | 14.5 | Postgres C API library |
libsodium | 1.0.18 | NaCl networking and cryptography library |
libzip | 1.9.2 | C library for reading, creating, and modifying zip archives |
oniguruma | 6.9.8 | Regular expressions library |
openldap | 2.6.3 | Open source suite of directory software |
1.1.1q | Cryptography and SSL/TLS Toolkit | |
pcre2 | 10.40 | Perl compatible regular expressions library with a new API |
sqlite | 3.39.3 | Command-line interface for SQLite |
tidy-html5 | 5.8.0 | Granddaddy of HTML tools, with support for modern standards |
unixodbc | 2.3.11 | ODBC 3 connectivity for UNIX |
Depends on when building from source:
httpd | 2.4.54 | Apache HTTP server |
pkg-config | 0.29.2 | Manage compile and link flags for libraries |
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php_module $[brew --prefix]/opt//lib/httpd/modules/libphp.so
SetHandler application/x-httpd-php
Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
The
php.ini and php-fpm.ini file can be found in:
$[brew --prefix]/etc/php/8.0/
Analytics [macOS]:
| 18,082 |
| 17,833 |
| 6 |
| 49,161 |
| 48,456 |
| 162,273 |
| 156,468 |
Analytics [Linux]:
| 122 |
| 116 |
| 0 |
| 355 |
| 341 |
| 1,193 |
| 1,084 |