首先安裝brew,安裝方法參考brew
MySQL
安裝mysql
$ brew install mysql
設置root賬號密碼
安裝完成後執行安全設置腳本,設置root賬號密碼
mysql_secure_installation
執行上面的命令後,會進入mysql的配置,配置完成後,就可以用mysql -u root -p
來登錄mysql了。
啓動
$ mysql.server start
PHP
安裝php
$ brew install php
修改環境變量
因爲mac默認是自帶php的,所以我們要把brew
安裝的php加到環境變量裏,而不是繼續使用mac自帶的php
$ vim ~/.bash_profile
在末尾加入一行:
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
保存退出後執行:
$ source ~/.bash_profile
此時,在命令行裏執行php -v
和php-fpm -v
看到的不再是系統自帶的php了,而是我們剛剛安裝的php。
修改配置文件
php.ini
$ vim /usr/local/etc/php/7.3/php.ini
去掉session.save_path = "/tmp"
前面的註釋;
php-fpm.conf
$ vim /usr/local/etc/php/7.3/php-fpm.conf
去掉pid = run/php-fpm.pid
、error_log = log/php-fpm.log
前面的註釋;
修改daemonize = yes
將其作爲守護進程後臺運行;
www.conf
$ vim /usr/local/etc/php/7.3/php-fpm.d/www.conf
把user = _www
group = _www
前加;
註釋掉,不指定用戶和組啓動php-fpm
將listen = 127.0.0.1:9000
改爲listen = /usr/local/var/run/php-cgi.sock
,使用unix socket方式啓動php-fpm
啓動
$ php-fpm
Nginx
安裝nginx
$ brew install nginx
修改配置文件
$ vim /usr/local/etc/nginx/nginx.conf
修改# user nobody
爲 user 用戶名 用戶組
此處填入當前用戶名和組;
保存退出,進行如下操作:
$ vim /usr/local/etc/nginx/fastcgi-php.conf
將下面內容填入:
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;
# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi.conf;
Next,
$ mkdir /usr/local/etc/nginx/servers
$ vim /usr/local/etc/nginx/servers/default.conf
將下面內容填入:
server {
listen 80 default_server;
server_name _;
root /xxx/webroot;
error_log /xxx/logs/nginx.error.log notice;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include fastcgi-php.conf;
fastcgi_pass unix:/usr/local/var/run/php-cgi.sock;
}
}
啓動
$ sudo nginx
至此,安裝啓動完成。