Set up PHP 7.2 on macOS Mojave (with homebrew)

NottDev
2 min readJan 27, 2020

--

สำหรับใครที่ต้องการติดตั้ง PHP เวอร์ชั่น 7.2 ในเครื่อง macOS บทความนี้ตอบโจทย์คุณแน่นอน ^^

เริ่ม…

คำสั่งสำหรับเช็คเวอร์ชั่น PHP ปัจจุบัน

$ php -v

หรือคำสั่งสำหรับลิสเวอร์ชั่นทั้งหมดที่เคยติดตั้งไว้แล้ว

$ brew list | grep php

อัพเดท homebrew ให้ปัจจุบันด้วยคำสั่ง

$ brew update
$ brew upgrade

ติดตั้ง PHP

ติดตั้ง PHP เวอร์ชั่น 7.2 ด้วยคำสั่ง

$ brew install php@7.2

ตั้งค่าให้เวอร์ชั่น 7.2 เป็นเวอร์ชั่นปัจจุบัน ด้วยคำสั่ง

echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

source is a shell built-in command which is used to read and execute the content of a file(generally set of commands), passed as an argument in the current shell script.

จากนั้นทดสอบ รันคำสั่งเช็คเวอร์ชั่นปัจจุบันของ PHP

$ php --version

ผลลัพธ์ที่ได้หน้าตาจะประมาณนี้

Path ไฟล์ php.ini

ไฟล์ php.ini อยู่ที่ /usr/local/etc/php/7.2/php.ini

หรือรันคำสั่งเช็ค path ของไฟล์ php.ini ใช้คำสั่ง

php --ini

ติดตั้ง Extensions

สำหรับการติดตั้ง extension นั้นสามารถติดตั้งผ่านคำสั่ง pecl

$ pecl install xdebug

PECL is a repository for PHP Extensions, providing a directory of all known extensions and hosting facilities for downloading and development of PHP extensions.

***คำสั่งที่ควรรู้

  • PECL คือ เป็น Repository ที่รวบรวม Open Source Library สำหรับ PHP
  • SOURCE คือ คำสั่งสำหรับอ่านและ execute เนื้อหาในไฟล์ และส่งค่า argument ไปทำงานที่ shell script ปัจจุบัน

--

--

NottDev
NottDev

Written by NottDev

Your only limit is your mind.

No responses yet