1、XCode 命令列工具
如果您尚未安裝XCode,則最好先安裝命令列工具,因為這些將由自制軟體使用:
xcode-select —install
2、安裝 brew 軟體管理工具
此過程嚴重依賴於名為Homebrew的macOS軟體包管理器。 使用brew命令,您可以輕鬆地向Mac新增強大的功能,但是首先我們必須安裝它。 這是一個簡單的過程,但是您需要啟動終端(/Applications/Utilities/Terminal)應用程式,然後輸入:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
只需按照終端提示輸入,然後在需要的地方輸入密碼即可。 這可能需要幾分鐘,但是完成後,一種快速的方法來確保您正確安裝了brew,只需鍵入:
brew --version
> Homebrew 3.4.7
Homebrew/homebrew-core (git revision 661ff0fc146; last commit 2022-04-13)
您應該可以執行以下命令,以確保所有配置正確:
brew doctor
它會指導您是否需要更正任何內容。
3、安裝 Nginx
brew install nginx
如果沒有選項,nginx將不需要從原始碼中構建,因此安裝速度非常快。完成後,您應該看到如下訊息:
==> Caveats
Docroot is: /usr/local/var/www
The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
nginx will load all files in /usr/local/etc/nginx/servers/.
To have launchd start nginx now and restart at login:
brew services start nginx
Or, if you don't want/need a background service you can just run:
nginx
==> Summary
? /usr/local/Cellar/nginx/1.21.6: 25 files, 2.1MB
==> Caveats
文件目錄是:/usr/local/var/www
預設埠已在/usr/local/etc/nginx/nginx.cinf中設定為8080,以便nginx可以在沒有sudo的情況下執行。
nginx將載入/usr/local.etc/nginx/servers/中所有的檔案。
要立即啟動nginx並且在登入時候重新啟動
brew services start nginx
複製如下檔案到~/Library/LaunchAgents/
cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/
或者,如果您不想/不需要後臺服務,您可以執行:
nginx
==> Summary
? /usr/local/Cellar/nginx/1.21.6: 25 files, 2.1MB
4、安裝 PHP
brew install php
==> 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/libphp8.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 have launchd start php now and restart at login:
brew services start php
Or, if you don't want/need a background service you can just run:
php-fpm
==> Summary
? /usr/local/Cellar/php/8.1.4: 517 files, 76MB
==> Caveats
要在Apache中啟用php,請講一下內容新增到httpd.conf並新重啟Apache:
LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp8.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
最後,檢查DirectoryIndex是否包含index.php
DirectoryIndex index.php index.html
php.ini和php-fpm.ini檔案可以在這裡找到:
/usr/local/etc/php/8.1/
現在啟動php並且在登入時候重新啟動
brew services start php
複製如下檔案到~/Library/LaunchAgents/
cp /usr/local/opt/httpd/homebrew.mxcl.php.plist ~/Library/LaunchAgents/
或者,如果您不想/不需要後臺服務,您可以執行:
php-fpm
==> Summary
? /usr/local/Cellar/php/8.1.4: 517 files, 76MB
5、安裝 MySQL
brew install mysql
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start
==> Summary
? /usr/local/Cellar/mysql/8.0.28: 286 files, 289.2MB
==> Caveats
我們已經安裝了沒有root密碼的MySQL資料庫。 為了確保它執行:
mysql_secure_installation
MySQL預設配置為僅允許來自localhost的連線
連線執行:
mysql -uroot
要啟動,請立即啟動mysql並在登入時重新啟動:
brew services start mysql
複製如下檔案到~/Library/LaunchAgents/
cp /usr/local/opt/mysql/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
或者,如果您不需要/需要後臺服務,則可以執行:
mysql.server start
==> Summary
? /usr/local/Cellar/mysql/8.0.28: 286 files, 289.2MB
6、安裝 Redis
brew install redis
==> Caveats
To have launchd start redis now and restart at login:
brew services start redis
Or, if you don't want/need a background service you can just run:
redis-server /usr/local/etc/redis.conf
==> Summary
? /usr/local/Cellar/redis/6.2.6: 13 files, 3.7MB
==> Caveats
要啟動,請立即啟動Redis,並在登入時重新啟動:
brew services start redis
複製如下檔案到~/Library/LaunchAgents/
cp /usr/local/opt/redis/homebrew.mxcl.redis.plist ~/Library/LaunchAgents/
或者,如果您不需要/需要後臺服務,則可以執行:
redis-server /usr/local/etc/redis.conf
==> Summary
? /usr/local/Cellar/redis/6.0.1: 13 files, 3.7MB
7、安裝 phpredis
7.1 克隆(下載) phpredis
git clone https://github.com/phpredis/phpredis
7.2 進入 phpredis
cd phpredis
7.3 切換版本
git checkout 5.3.7
7.4 生產 configure
/usr/local/Cellar/php/8.1.4/bin/phpize
7.4 原始碼安裝phpredis
./configure --with-php-config=/usr/local/Cellar/php/8.1.4/bin/php-config
make && make install
當編譯成功後,我們會得到一個提示,在 /usr/local/Cellar/php/8.1.4/pecl/20210902/ 目錄下有一個檔案 redis.so
7.5 修改php.ini檔案
修改php.ini檔案,讓其載入redis.so檔案,這樣我們就可以操作redis,php.ini檔案在 /usr/local/etc/php/8.1/php.ini
vim /usr/local/etc/php/8.1/php.ini
extension=/usr/local/Cellar/php/8.1.4/pecl/20210902/redis.so
7.6 重啟Nginx和PHP
重啟nginx 和 php 後 訪問index.php, 檢視redis模組是否載入
8、安裝 Memcached
brew install memcached
==> Caveats
To have launchd start memcached now and restart at login:
brew services start memcached
Or, if you don't want/need a background service you can just run:
/usr/local/opt/memcached/bin/memcached
==> Summary
? /usr/local/Cellar/memcached/1.6.5: 11 files, 267.5KB
==> Caveats
要啟動,請立即啟動memcached並在登入時重新啟動:
brew services start memcached
複製如下檔案到~/Library/LaunchAgents/
cp /usr/local/opt/memcached/homebrew.mxcl.memcached.plist ~/Library/LaunchAgents/
或者,如果您不需要/需要後臺服務,則可以執行:
/usr/local/opt/memcached/bin/memcached
==> Summary
? /usr/local/Cellar/memcached/1.6.5: 11 files, 267.5KB
9、安裝 Node
brew install node
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
? /usr/local/Cellar/node/14.1.0: 4,659 files, 60.8MB
==> Caveats
Bash完成已安裝到:
/usr/local/etc/bash_completion.d
==> Summary
? /usr/local/Cellar/node/14.1.0: 4,659 files, 60.8MB
node -v
v17.9.0
npm -v
8.5.5
10、安裝 Yarn
brew install yarn
? /usr/local/Cellar/yarn/1.22.18: 14 files, 5MB, built in 73 minutes 8 seconds
yarn -v
1.22.18
11、安裝 Composer
brew install composer
? /usr/local/Cellar/composer/2.3.4: 3 files, 1.9MB, built in 2 minutes 7 seconds
composer -V
Composer version 2.3.4 2022-04-07 21:16:35
本作品採用《CC 協議》,轉載必須註明作者和本文連結