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

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,php,nginx,phpmyadmin,配置访问数据库

    在这里插入图片描述

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

在这里插入图片描述

  • 打开成功
    请添加图片描述

七、参考

  • mac安装php7步骤详解
  • php官方编译安装参考
  • Mac 安装PHP Redis 扩展
  • nginx+php部署FastCGI sent in stderr: “Primary script unknown” while reading response header from upstream错误
                       

点击阅读全文

上一篇 2023年 5月 27日 am10:45
下一篇 2023年 5月 27日 am10:46