软件选择:
-
- php 7.2;
- mysql 8.0.19;
- nginx 1.17.8;
所有操作都是基于brew进行的,没有brew的请先读
安装nginx
- 打开终端,输入命令
brew install nginx
- 最终输出信息,这是安装成功了
==> nginx Docroot is: /usr/local/var/www //nginx主目录存放 The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that nginx can run without sudo. //默认端口8080,没有sudo权限也可以用 nginx will load all files in /usr/local/etc/nginx/servers/. //nginx服务存放 To have launchd start nginx now and restart at login: brew services start nginx Or, if you don't want/need a background service you can just run: nginx yumangdembp:~ yumang-root$
- 根据提示,打开localhost:8080,查看默认页,welcome to nginx
- nginx的配置文件存放于/usr/local/etc/nginx
- 扩展(nginx命令):
- 启动nginx
sudo nginx
- 停止nginx
sudo nginx - s stop
- 重启nginx
sudo nginx -s reload
- 启动nginx
安装php
- 非常简单(接下来会有各种报错,不过都很容易解决)
brew install php72
- php-fpm第一次报错
Last login: Sun Feb 23 06:15:50 on ttys000 yumangdembp:~ yumang-root$ php-fpm [23-Feb-2020 06:19:28] ERROR: failed to open configuration file '/private/etc/php-fpm.conf': No such file or directory (2) [23-Feb-2020 06:19:28] ERROR: failed to load configuration file '/private/etc/php-fpm.conf' [23-Feb-2020 06:19:28] ERROR: FPM initialization failed yumangdembp:~ yumang-root$
翻译报错信息:打开配置文件/private/etc/php-fpm.conf失败,原因是:No such file or directory(没有这个路径或文件)
- 那到底是没有路径还是没有文件呢
cd /private/etc
用cd命令到/private/etc里面看一下,没有php-fpm.conf文件,却有一个php-fpm.conf.default文件
这不难办,直接同目录复制一个就好sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf
再复制一个做备份
sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf.bak
- 再次运行php-fpm,第二次报错
[23-Feb-2020 06:27:44] ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory (2) [23-Feb-2020 06:27:44] ERROR: failed to post process the configuration [23-Feb-2020 06:27:44] ERROR: FPM initialization failed yumangdembp:~ yumang-root$
这次问题和刚才的一样,都是没有路径或文件,这次是日志文件。打开/usr/var/log查看php-fpm.log是否存在的时候,你会发现usr下连var目录都没有,别说再下级的log中的php-fpm.log了。
- php-fpm.log,/usr/local/var/log里有这个文件,不需要再默认的路径建文件夹拷过去。就用atom修改php-fpm.conf:line:24(搜索error_log)
将; error_log = log/php-fpm.log
改为
error_log = /usr/local/var/log/php-fpm.log
- 再次运行php-fpm,第三次报错
[23-Feb-2020 06:41:44] WARNING: Nothing matches the include pattern '/private/etc/php-fpm.d/*.conf' from /private/etc/php-fpm.conf at line 125. [23-Feb-2020 06:41:44] ERROR: No pool defined. at least one pool section must be specified in config file [23-Feb-2020 06:41:44] ERROR: failed to post process the configuration [23-Feb-2020 06:41:44] ERROR: FPM initialization failed
line:125是
include=/private/etc/php-fpm.d/*.conf
- 打开/private/etc/php-fpm.d/ 发现没有conf结尾的文件,复制这个重命名把.default删掉
- 再次运行php-fpm,第四次报错
[23-Feb-2020 06:52:12] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root [23-Feb-2020 06:52:12] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root Starting php-fpm [23-Feb-2020 06:52:12] ERROR: unable to bind listening socket for address '127.0.0.1:9000': Address already in use (48) Starting php-fpm [23-Feb-2020 06:52:12] ERROR: FPM initialization failed
前两行是权限不足,直接忽略即可,问题是9000端口的异常占用。
- 修改/private/etc/php-fpm.d/www.conf:36
listen = 127.0.0.1:9000
改为
listen = 127.0.0.1:9999
修改/usr/local/etc/nginx/nginx.conf:67
# fastcgi_pass 127.0.0.1:9000;
改为
# fastcgi_pass 127.0.0.1:9999;
- 把nginx和php的监听端口都改成9999之后运行php-fpm会有两行notice还是提示权限的问题,不要管他。
yumangdembp:etc yumang-root$ /usr/local/Cellar/php@7.2/7.2.28/sbin/php-fpm -t [23-Feb-2020 07:03:31] NOTICE: configuration file /usr/local/etc/php/7.2/php-fpm.conf test is successful yumangdembp:etc yumang-root$
安装mysql
- brew install mysql
brew install mysql //安装,一般一分钟内即可下载完成 mysql.server start //启动mysql服务
-
mysql_secure_installation //初始化配置
New password: //输入密码 Re-enter new password: //确认 Estimated strength of the password: 100 //密码强度(大写,小写,数字,符号,大于八位,我用的Wrdy0408.就满分密码了) Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y //确定用这个密码吗?(Y) By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y //删除匿名用户(Y) Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n //开启远程登录(N) ... skipping. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y //删除自带的test库(Y) - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y //重载privilege tables(Y) Success. All done!
-
yumangdembp:~ yumang-root$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 18 Server version: 8.0.19 Homebrew Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
结束
版权声明:本文著作权归原作者所有,欢迎分享本文,谢谢支持!