mac安装mysql,php,nginx,phpmyadmin,配置访问数据库

一、安装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;

在这里插入图片描述

  • 打开成功
    请添加图片描述
七、参考
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值