macOS 12.0 Monterey: Apache Setup: Multiple PHP Versions

by Little Bear @4 ต.ค. 64 14:48 ( IP : 171...109 ) | Tags : macOS , Server , Apache , PHP

เดี๋ยวค่อยมาเขียนรายละเอียด

Install Apache

Location of Apache config file is /opt/homebrew/etc/httpd/httpd.conf Change www home folder

mv /opt/homebrew/var/www /opt/homebrew/var/www.bak
ln -s /Users/httpdocs /opt/homebrew/var/www

brew tap shivammathur/php

เลือกมาสักเวอร์ชั่น

brew install shivammathur/php/php@5.6
brew install shivammathur/php/php@7.0
brew install shivammathur/php/php@7.1
brew install shivammathur/php/php@7.2
brew install shivammathur/php/php@7.3
brew install shivammathur/php/php@7.4
brew install shivammathur/php/php@8.0

Mac M1 : Config file อยู่ที่

/opt/homebrew/etc/php/7.0/php.ini
/opt/homebrew/etc/php/7.1/php.ini
/opt/homebrew/etc/php/7.2/php.ini
/opt/homebrew/etc/php/7.3/php.ini
/opt/homebrew/etc/php/7.4/php.ini
/opt/homebrew/etc/php/8.0/php.ini

Mac Intel : Config file อยู่ที่

/usr/local/etc/php/5.6/php.ini
/usr/local/etc/php/7.0/php.ini
/usr/local/etc/php/7.1/php.ini
/usr/local/etc/php/7.2/php.ini
/usr/local/etc/php/7.3/php.ini
/usr/local/etc/php/7.4/php.ini
/usr/local/etc/php/8.0/php.ini

ผลลัพท์ตอนติดตั้ง

[code]
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php7_module /usr/local/opt/php@7.4/lib/httpd/modules/libphp7.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/7.4/

php@7.4 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have php@7.4 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc

For compilers to find php@7.4 you may need to set:
  export LDFLAGS="-L/usr/local/opt/php@7.4/lib"
  export CPPFLAGS="-I/usr/local/opt/php@7.4/include"<br />
<br />
<br />
To start shivammathur/php/php@7.4:
  brew services start shivammathur/php/php@7.4
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/php@7.4/sbin/php-fpm --nodaemonize

เปลี่ยนลิงก์

brew unlink php && brew link --overwrite --force php@7.4

Apache

แก้ไขไฟล์ /etc/apache2/httpd.conf หรือ /usr/local/etc/httpd/httpd.conf file scroll to the bottom of the LoadModule entries.

 LoadModule php5_module /usr/local/opt/php@5.6/lib/httpd/modules/libphp5.so
 <a class="hashtag" href="/tags/LoadModule">#LoadModule</a> php7_module /usr/local/opt/php@7.0/lib/httpd/modules/libphp7.so
 <a class="hashtag" href="/tags/LoadModule">#LoadModule</a> php7_module /usr/local/opt/php@7.1/lib/httpd/modules/libphp7.so
 <a class="hashtag" href="/tags/LoadModule">#LoadModule</a> php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so
 <a class="hashtag" href="/tags/LoadModule">#LoadModule</a> php7_module /usr/local/opt/php@7.3/lib/httpd/modules/libphp7.so
 <a class="hashtag" href="/tags/LoadModule">#LoadModule</a> php7_module /usr/local/opt/php@7.4/lib/httpd/modules/libphp7.so
 <a class="hashtag" href="/tags/LoadModule">#LoadModule</a> php_module /usr/local/opt/php@8.0/lib/httpd/modules/libphp.so

Install mariadb

brew install mariadb

Restart MariaDB

Auto start

brew services start mariadb

Manual start

mysql.server restart

Location of database is /opt/homebrew/var/mysql, If you want to change use symbolic link to new location

brew services stop mariadb
cp -R /opt/homebrew/var/mysql /Users/mysql
mv /opt/homebrew/var/mysql /opt/homebrew/var/mysql.bak
mkdir /opt/homebrew/var/mysql
ln -s /Users/mysql /opt/homebrew/var/mysql
brew services start mariadb

ที่มา

Relate topics