¿Cómo instalar la última versión de PHP en MacOS a través de Homebrew?
Publicado: 2022-01-31
¿Cómo instalar PHP en MacOS?
En este tutorial, repasaremos los pasos sobre cómo instalar PHP en MacOS. Usaremos Homebrew para instalar PHP en MacOS.
PHP
es un lenguaje de secuencias de comandos de propósito general ampliamente utilizado que es especialmente adecuado para el desarrollo web y se puede incrustar en HTML.
Empecemos:
- Agregue e instale PHP en macOS Monterey 12 con Homebrew.
- Actualización a las versiones de PHP 7.4 y 8 en macOS.
- Actualizar la versión de PHP en Mac
Paso 1
Instale Homebrew en MacOS con éxito. Por favor, siga este tutorial completamente.
Paso 2
Una vez que Homebrew se haya instalado correctamente, instale PHP usando el siguiente comando.
1 2 |
bash - 3.2 $ brew install php |
Aquí hay un resultado de consola detallado de "brew install php":
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
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 : / 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 : / 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 $ |
Aquí hay algunos resultados más de la consola MacOS:



Paso 3
Verifiquemos los detalles de la versión de PHP y dónde está instalado.
1 2 3 4 5 6 7 8 9 |
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 |
Y ya está todo listo. Avíseme si tiene algún problema al instalar PHP en su MacOS.
¿Dónde se encuentra el archivo apache.ini?
1 |
bash - 3.2 $ vi / usr / local / etc / php / 8.1 / php . ini |
Codificación feliz.