• 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
    
    • 1
    • 2
    • 打开设置,启动关闭mysql

      在这里插入图片描述
    二、安装php
    • 编译有点复杂,还是用brew
    brew install php
    
    • 1

    请添加图片描述

    • 没有下载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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 启动,关闭,重启php
    brew services start|stop|restart php
    
    • 1

    在这里插入图片描述

    • 配置文件目录:/usr/local/etc/php/8.1

    请添加图片描述

    • 查看php-fpm是否启动成功
    lsof -Pni4 | grep LISTEN | grep php
    
    • 1

    请添加图片描述

    三、安装nginx
    brew install nginx
    
    • 1
    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`).
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 启动,关闭,重启nginx
    brew services start|stop|restart nginx
    
    • 1

    在这里插入图片描述

    • 配置文件目录:/usr/local/etc/nginx
    四、安装phpmyadmin
    • https://www.phpmyadmin.net/访问不了,只能用brew安装
    brew install phpmyadmin
    
    • 1
    • 目录:/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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 修改配置文件,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;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    五、配置nginx,打开phpmyadmin页面访问数据库
    • 修改/etc/hosts
    127.0.0.1 pma.monnys11.net
    
    • 1
    • 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 重启php,nginx
    brew services restart php
    brew services restart nginx
    
    • 1
    • 2
    六、出现有问题

    请添加图片描述请添加图片描述

    • 添加一行配置
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    
    • 1

    在这里插入图片描述

    • 打开成功
      请添加图片描述
    七、参考
  • 相关阅读:
    [Java基础] 设计模式之观察者模式
    C++ 多态性
    Linux系统下如何使用NiMotionUSBCAN转换器?
    Android Room使用模板
    vue常见的指令
    手机号码认证什么价格?手机号码认证怎样申请?
    在线云原生边缘计算KubeEdge安装配置(二)
    如果你有一次自驾游的机会,你会如何准备?
    前端页面左右布局,点击左div增加动画过渡效果
    Excel快捷键
  • 原文地址:https://blog.csdn.net/tianjiewang/article/details/126790256