一、安装mysql
-
选择对应版本的mysql下载安装:https://dev.mysql.com/downloads/mysql/
-
安装输入密码后,配置软连接
sudo ln -sv /usr/local/mysql-8.0.30-macos12-x86_64/bin/mysql /usr/local/bin
sudo ln -sv /usr/local/mysql-8.0.30-macos12-x86_64/bin/mysqldump /usr/local/bin
- 打开设置,启动关闭mysql
- Mac MySql版本问题sql_mode=only_full_group_by 的解决方案
sudo vim /etc/etc/my.cnf
# 添加下面内容,重启MySql
[mysqld]
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
二、安装php
- 编译有点复杂,还是用brew
brew install php
- 没有下载icu4c库,单独安装
- 安装成功
- 使用apache服务
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.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 restart php after an upgrade:
brew services restart php
Or, if you don't want/need a background service you can just run:
/usr/local/opt/php/sbin/php-fpm --nodaemonize
- 启动,关闭,重启php
brew services start|stop|restart php
- 配置文件目录:/usr/local/etc/php/8.1
- 查看php-fpm是否启动成功
lsof -Pni4 | grep LISTEN | grep php
三、安装nginx
brew install nginx
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 restart nginx after an upgrade:
brew services restart nginx
Or, if you don't want/need a background service you can just run:
/usr/local/opt/nginx/bin/nginx -g daemon off;
==> Summary
🍺 /usr/local/Cellar/nginx/1.23.1: 26 files, 2.2MB
==> Running `brew cleanup nginx`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
- 启动,关闭,重启nginx
brew services start|stop|restart nginx
- 配置文件目录:/usr/local/etc/nginx
四、安装phpmyadmin
- https://www.phpmyadmin.net/访问不了,只能用brew安装
brew install phpmyadmin
- 目录:/usr/local/share/phpmyadmin
To enable phpMyAdmin in Apache, add the following to httpd.conf and
restart Apache:
Alias /phpmyadmin /usr/local/share/phpmyadmin
<Directory /usr/local/share/phpmyadmin/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
<IfModule mod_authz_core.c>
Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>
Then open http://localhost/phpmyadmin
The configuration file is /usr/local/etc/phpmyadmin.config.inc.php
==> Summary
🍺 /usr/local/Cellar/phpmyadmin/5.2.0: 3,553 files, 44.7MB
- 修改配置文件,vim /usr/local/share/phpmyadmin/config.inc.php
// $i++;
/* Authentication type */
// $cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
// $cfg['Servers'][$i]['host'] = 'localhost';
// $cfg['Servers'][$i]['compress'] = false;
// $cfg['Servers'][$i]['AllowNoPassword'] = false;
$i++;
$cfg['Servers'][$i]['host'] = '127.0.01';
$cfg['Servers'][$i]['port'] = '3306';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
五、配置nginx,打开phpmyadmin页面访问数据库
- 修改/etc/hosts
127.0.0.1 pma.monnys11.net
- cd /usr/local/etc/nginx/servers
echo '
server {
listen 80;
root /usr/local/share/phpmyadmin;
index index.html index.htm index.php;
# Make site accessible from http://localhost/
server_name pma.monnys11.net;
client_max_body_size 8M;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location ~ \.php$ {
try_files $uri =404;
# fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_max_temp_file_size 0;
fastcgi_buffer_size 4K;
fastcgi_buffers 64 4k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
' > pma
- 重启php,nginx
brew services restart php
brew services restart nginx
六、出现有问题
- 添加一行配置
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- 打开成功