จะติดตั้ง PHP เวอร์ชันล่าสุดบน MacOS ผ่าน Homebrew ได้อย่างไร?
เผยแพร่แล้ว: 2022-01-31
จะติดตั้ง PHP บน MacOS ได้อย่างไร?
ในบทช่วยสอนนี้ เราจะพูดถึงขั้นตอนในการติดตั้ง PHP บน MacOS เราจะใช้ Homebrew เพื่อติดตั้ง PHP บน MacOS
PHP
เป็นภาษาสคริปต์ทั่วไปที่ใช้กันอย่างแพร่หลายซึ่งเหมาะอย่างยิ่งสำหรับการพัฒนาเว็บและสามารถฝังลงใน HTML ได้
มาเริ่มกันเลย:
- เพิ่มและติดตั้ง PHP ไปยัง macOS Monterey 12 ด้วย Homebrew
- กำลังอัปเดตเป็น PHP เวอร์ชัน 7.4 และ 8 บน macOS
- อัปเดตเวอร์ชัน PHP ใน Mac
ขั้นตอนที่ 1
ติดตั้ง Homebrew บน MacOS สำเร็จ โปรดปฏิบัติตามบทช่วยสอนนี้อย่างสมบูรณ์
ขั้นตอนที่ 2
เมื่อติดตั้ง Homebrew สำเร็จแล้ว ให้ติดตั้ง PHP โดยใช้คำสั่งด้านล่าง
1 2 |
bash - 3.2 $ brew install php |
นี่คือผลลัพธ์คอนโซลโดยละเอียดของ "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 $ |
นี่คือผลลัพธ์คอนโซล MacOS เพิ่มเติมบางส่วน:



ขั้นตอนที่ 3
มาตรวจสอบรายละเอียดเวอร์ชัน PHP และติดตั้งที่ไหน
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 |
และคุณพร้อมแล้ว แจ้งให้เราทราบหากคุณประสบปัญหาในการติดตั้ง PHP บน MacOS ของคุณ
ไฟล์ apache.ini อยู่ที่ไหน
1 |
bash - 3.2 $ vi / usr / local / etc / php / 8.1 / php . ini |
มีความสุขในการเข้ารหัส