ก๊วนซอฟท์แวร์ </softganz> SoftGang (Gang Software)

Web &amp; Software Developer Gang.

macOS 12 Monterey: Web Server Setup/Apache/MariaDB/PHP Multiple 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 services restart apache2

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
brew install shivammathur/php/php@8.1
brew install shivammathur/php/php@8.2

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
/opt/homebrew/etc/php/8.1/php.ini
/opt/homebrew/etc/php/8.2/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

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

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

&lt;FilesMatch .php$&gt;
    SetHandler application/x-httpd-php
&lt;/FilesMatch&gt;

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

แก้ไขไฟล์ /opt/homebrew/etc/httpd/httpd.conf /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
 <a class="hashtag" href="/tags/LoadModule">#LoadModule</a> php_module /usr/local/opt/php@8.1/lib/httpd/modules/libphp.so

ใช้ sphp เป็นตัวเปลี่ยน version จะสะดวกกว่า

curl -L https://gist.githubusercontent.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2/raw/adc8c149876bff14a33e3ac351588fdbe8172c07/sphp.sh > /opt/homebrew/bin/sphp
chmod +x /opt/homebrew/bin/sphp
sphp 8.1

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

MariaDB Configuration

แก้ไขไฟล์ /opt/homebrew/etc/my.cnf.d/my.cnf

[mysqld]
sqlmode="NOFIELDOPTIONS"
  # Avaliable Mode<br />
  # "NOFIELDOPTIONS,IGORESPACE,NOZEROINDATE,NOZERODATE,ERRORFORDIVISIONBYZERO,NOAUTOCREATEUSER,NOENGINESUBSTITUTION"
default-storage-engine = MYISAM
character-set-server = utf8
  <a class="hashtag" href="/tags/collation">#collation</a>-server = utf32unicodeci

หากไม่ต้องการให้ตรวจสอบการบันทึกข้อมูลของฟิลด์ เช่น ข้อมูลยาวเกินกว่าที่กำหนดในฟิลด์ ให้กำหนด mode เป็น NOFIELDOPTIONS

ที่มา