当前位置: 首页 > 后端技术 > PHP

Mac下Nginx、PHP、MySQL和PHP-fpm的安装配置

时间:2023-03-30 06:16:03 PHP

之前换了电脑安装了Mnmp。遇到了一些小坑。写到这里,希望对一些第一次搭建Mnmp的phper有所帮助。...安装Mac的包管理器——homebrewHomebrew是一款MacOS平台的包管理工具,具有安装、卸载、更新、查看、搜索等诸多实用功能。在安装Homebrew之前,您需要确定是否mac已经安装了xcode,然后安装xcode命令行工具。#安装xcode命令行工具xcode-select--install如果不想使用该方法或者各种原因,可以:登录[https://developer.apple.com/download/more/][1]并下载dmg安装注意:一定要选择与mac系统版本和xcode版本一致的命令行工具。好的,现在让我们安装Homebrew。/usr/bin/ruby-e"$(curl-fsSLhttps://raw.githubusercontent.com/Homebrew/install/master/install)"安装好Homebrew后,可以使用brew命令安装相应的包。执行Nginxbrewinstallnginx后,安装Nginx。下面是nginx的几个常用命令。#启动nginx服务sudonginx#重新加载配置|restart|stop|exitnginxnginx-sreload|reopen|stop|quit#测试配置语法错误nginx-t#启动nginxsudongixn-c/usr/local/etc/nginx/nginx.conf#测试配置语法错误nginx-t-c/usr/local/etc/nginx/nginx.conf#nginx配置phplocation~\.php${root/usr/share/nginx/;#herehtml到目录fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;includefastcgi_params;}nginx启动后,在浏览器中输入http://localhost:8080/回车,看到运行结果时,/usr/local/Cellar/nginx/1.10.0/html的内容/index.html文件显示。设置开机自启动nginx服务设置:mkdir-p~/Library/LaunchAgentscp/usr/local/Cellar/nginx/1.10.0/homebrew.mxcl.nginx.plist~/Library/LaunchAgents/launchctlload-w~/Library/LaunchAgents/homebrew.mxcl.nginx.plistMySQLbrewinstallmysql//执行mysql_secure_installation//如果报如下错误://ERROR2002(HY000):Can'tconnecttolocalMySQLserverthroughsocket'/tmp/mysql.sock'(2)//执行sudochmod777/var/run/mysql//再次执行mysql_secure_installation//开始MySQL的安全设置保护MySQL服务器部署。使用空白密码连接到MySQL。验证密码组件可用于测试密码并提高安全性。它检查密码的强度并允许用户只设置那些足够安全的密码。WouldyouliketosetupVALIDATEPASSWORDcomponent?//是否设置验证密码组件:yPressy|YforYes,anyotherkeyforNo:y密码验证策略分为三级:LOWLength>=8MEDIUMLength>=8、数字、混合大小写和特殊字符STRONG长度>=8,numeric,mixedcase,specialcharactersanddictionaryfile//密码验证策略有三个等级:0=low,1=medium,2=strong:0Pleaseenter0=LOW,1=MEDIUMand2=STRONG:0Please在这里设置root密码。//输入密码:admin123新密码://重复密码:admin123重新输入新密码:估计密码强度:50//密码强度为50,是否使用此密码:yDoyouwish要使用提供的密码继续吗?(按y|Y表示是,任何其他键表示否):y默认情况下,MySQL安装有一个匿名用户,允许任何人登录MySQL而无需为他们创建用户帐户。这仅用于测试,并使安装更顺利。您应该在进入生产环境之前删除它们。//删除匿名用户(测试用户):yRemoveanonymoususers?(按y|Y表示“是”,任何其他键表示“否”):ySuccess。通常,只应允许root从“localhost”连接。这样可以保证别人无法从网络上猜出root密码。//不允许远程登录root目录记录:n(根据个人选择,建议输入y)Disallowrootloginremotely?(按y|Y表示是,任何其他键表示否):n...跳过。默认情况下,MySQL带有一个名为“test”的数据库,任何人都可以访问。这也仅用于测试,应该在进入生产环境之前删除。//删除测试数据库:yRemovetestdatabaseandaccesstoit?(按y|Y表示是,任何其他键表示否):y-删除测试数据库...成功。-Removingprivilegesontestdatabase...Success.Reloadingtheprivilegetableswillensurethatallchangesmadesofarwillmadeimmediately.//是否刷新权限:yReloadprivilegetablesnow?(按y|Y表示是,任何其他键表示否):ySuccess.//Complete全部完成!//nginx启动和停止server.mysqlstartstoprestart#loginmysqlmysql-uroot-psetbootstartmkdir-p~/Library/LaunchAgents/cp/usr/local/Cellar/mysql/5.7.12/homebrew.mxcl。mysql.plist~/Library/LaunchAgents/launchctlload-w~/Library/LaunchAgents/homebrew.mxcl.mysql.plistPHPbrewinstallphp@7.1sudovim~/.bash_profileexportPATH="$(brew--prefixphp@7.1)/bin:$PATH"sudophp-fpmERROR:无法打开配置文件'/private/etc/php-fpm.conf':Nosuchfileordirectory(2)#解决cp/private/etc/php-fpm.conf.default/private/etc/php-fpm.confERROR:failedtoopenerror_log(/usr/var/log/php-fpm.log):Nosuchfileordirectory(2)#Solution修改php-fpm.conferror_log配置为/usr/local/var/log/php-fpm.logphp-fpmstartuperrorNopooldefinedfailedtopostprocesstheconfigurationFPMinitializationfailed#解决方案:cd/private/etc/php-fpm.d/sudocpwww.conf.defaultwww.conf#Restartphp-fpmtoERROR:unabletobindlisteningsocketforaddress'127.0.0.1:9000':Addressalreadyinuse(48)#Solution编辑php-fpm.conf//private/etc/php-fpm.d/www.conf,修改listen127.0.0.1:9999phpsetbootmkdir-p~/Library/LaunchAgentscp/usr/local/opt/php56/homebrew.mxcl.php56.plist~/Library/LaunchAgents/launchctlload-w~/Library/LaunchAgents/homebrew.mxcl.php56.plist打开:brew服务esstartphp@7.2Restart:brewservicesrestartphp@7.2Stop:brewservicesstopphp@7.2配置Nginxvim/usr/local/etc/nginx/nginx.conf#隐藏入口文件配置位置/{indexindex.phpindex.html索引.htm;if(!-e$request_filename){重写^/(.*)$/index.php?$1最后;#ci框架写入#rewrite^/(.*)$/index.php?s=/$1last;#tp帧写入中断;}}修改hostvim/etc/hosts#127.0.0.1www.test.com#