Ticker

6/recent/ticker-posts

Ad Code

Responsive Advertisement

How to install PHP latest version on MacOS?

How to install PHP latest version on MacOS?

How to install PHP on MacOS?

In this tutorial we will go over steps on how to install PHP on MacOS. We will use Homebrew to install PHP on MacOS.

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

Let’s get started:

Step-1

Install Homebrew on MacOS successfully. Please follow this tutorial completely.

Step-2

Once Homebrew is successfully installed, install PHP using below command.

bash-3.2$ brew install php

Here is a detailed console result of “brew install php”:

bash-3.2$ 
bash-3.2$ 

bash-3.2$ brew install php

==> Downloading https://ghcr.io/v2/homebrew/core/apr/manifests/1.7.0_2
Already downloaded: //cdn.crunchify.com/Users/app/Library/Caches/Homebrew/downloads/bea860ee12694d9b28c54323f66a2ed14e5b7b44c7fd2568ddd179b86f27829e--apr-1.7.0_2.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/apr/blobs/sha256:706df15280f05bc3ab057bd5dd856746f02c4fcc7356cccd5babd92a6362f132
Already downloaded: /Users/app/Library/Caches/Homebrew/downloads/3beab76299c09a6d05b8ddb53711803844ff70c996e04daf8188953e2d8e9dc3--apr--1.7.0_2.monterey.bottle.tar.gz


==> Downloading https://ghcr.io/v2/homebrew/core/php/manifests/8.1.2
Already downloaded: //cdn.crunchify.com/Users/app/Library/Caches/Homebrew/downloads/bb615e3f8d0140a0e40ab9ada2f73189ec03af655631c39f30d78a02b2887ac4--php-8.1.2.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/php/blobs/sha256:08fc122518eca5e578ff4cd791c2ced0e4a10f707ec48f1938791473e38fceb5
Already downloaded: /Users/app/Library/Caches/Homebrew/downloads/f7d51e966f2f708d28d0888ffd9e830c1cb4212293ef8408e610be33024e4521--php--8.1.2.monterey.bottle.tar.gz

==> Downloading https://ghcr.io/v2/homebrew/core/php/blobs/sha256:08fc122518eca5e578ff4cd791c2ced0e4a10f707ec48f1938791473e38fceb5
Already downloaded: /Users/app/Library/Caches/Homebrew/downloads/f7d51e966f2f708d28d0888ffd9e830c1cb4212293ef8408e610be33024e4521--php--8.1.2.monterey.bottle.tar.gz
==> Installing dependencies for php: apr, ca-certificates, openssl@1.1, argon2, aspell, m4, autoconf, brotli, libunistring, libidn2, libnghttp2, libssh2, openldap, rtmpdump, zstd, curl, libtool, unixodbc, freetds, libpng, freetype, fontconfig, jpeg, libtiff, giflib, webp, gd, gmp, icu4c, krb5, libpq, libsodium, libzip, oniguruma, pcre2, readline, sqlite and tidy-html5
==> Installing php dependency: apr
==> Pouring apr--1.7.0_2.monterey.bottle.tar.gz
🍺  /usr/local/Cellar/apr/1.7.0_2: 59 files, 1.4MB
==> Installing php dependency: ca-certificates
==> Pouring ca-certificates--2021-10-26.all.bottle.tar.gz
==> Regenerating CA certificate bundle from keychain, this may take a while...
🍺  /usr/local/Cellar/ca-certificates/2021-10-26: 3 files, 208.5KB
==> Installing php dependency: openssl@1.1
==> Pouring openssl@1.1--1.1.1m.monterey.bottle.tar.gz
🍺  /usr/local/Cellar/openssl@1.1/1.1.1m: 8,081 files, 18.5MB
==> Installing php dependency: argon2

==> Pouring php--8.1.2.monterey.bottle.tar.gz
==> /usr/local/Cellar/php/8.1.2/bin/pear config-set php_ini /usr/local/etc/php/8.1/php.ini system
==> /usr/local/Cellar/php/8.1.2/bin/pear config-set php_dir /usr/local/share/pear system
==> /usr/local/Cellar/php/8.1.2/bin/pear config-set doc_dir /usr/local/share/pear/doc system
==> /usr/local/Cellar/php/8.1.2/bin/pear config-set ext_dir /usr/local/lib/php/pecl/20210902 system
==> /usr/local/Cellar/php/8.1.2/bin/pear config-set bin_dir /usr/local/opt/php/bin system
==> /usr/local/Cellar/php/8.1.2/bin/pear config-set data_dir /usr/local/share/pear/data system
==> /usr/local/Cellar/php/8.1.2/bin/pear config-set cfg_dir /usr/local/share/pear/cfg system
==> /usr/local/Cellar/php/8.1.2/bin/pear config-set www_dir /usr/local/share/pear/htdocs system
==> /usr/local/Cellar/php/8.1.2/bin/pear config-set man_dir /usr/local/share/man system
==> /usr/local/Cellar/php/8.1.2/bin/pear config-set test_dir /usr/local/share/pear/test system
==> /usr/local/Cellar/php/8.1.2/bin/pear config-set php_bin /usr/local/opt/php/bin/php system
==> /usr/local/Cellar/php/8.1.2/bin/pear update-channels
==> Caveats

To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so

    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>

Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
    /usr/local/etc/php/8.1/

To restart php after an upgrade:
  brew services restart php
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/php/sbin/php-fpm --nodaemonize
==> Summary
🍺  /usr/local/Cellar/php/8.1.2: 513 files, 80.0MB
==> Running `brew cleanup php`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

bash-3.2$ 
bash-3.2$

Here are some more MacOS console result:

PHP Install log on MacOS
PHP Install log on MacOS - Crunchify Tips

Step-3

Let’s verify PHP version details and where it’s installed.

bash-3.2$ which php
/usr/local/bin/php

bash-3.2$ php -version
PHP 8.1.2 (cli) (built: Jan 21 2022 04:47:46) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies

And you are all set. Let me know if you face any issue installing PHP on your MacOS.

Happy coding.

The post How to install PHP latest version on MacOS? appeared first on Crunchify.

Enregistrer un commentaire

0 Commentaires