当前位置: 首页 > Linux

macosLNMP配置(亲测)

时间:2023-04-07 00:18:44 Linux

折腾了两天,觉得有必要总结一下经验,一方面自己整理,以备日后使用。另一方面,也为遇到同样问题的其他人提供了解决方案。安装brew:(mac下的包管理工具),最新的macos自带。在最新的macos下,php是自带的。安装nginx:brewinstallnginx启动nginx:sudonginx,访问http://localhost:8080看是否访问正常。之前不要改服务器配置,但是下一步就厉害了,重点!!!废话不多说,直接上配置文件nginx.conf#user*root*;worker_processes1;error_loglogs/error.log;#error_loglogs/error.lognotice;#error_loglogs/error.loginfo;#pidlogs/nginx.pid;events{worker_connections1024;}http{includemime.types;default_type应用程序/八位字节流;#log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'#'$status$body_bytes_sent"$http_referer"'#'"$http_user_agent""$http_x_forwarded_for"';#access_log日志/access.logmain;发送文件;#tcp_nopush上;#keepalive_timeout0;keepalive_timeout65;#gzip上;服务器{听8080;服务器名称本地主机;#字符集koi8-r;#access_log日志/host.access.logma在;location/{root/Users/qsong/Desktop/MILANJUJIA/public;indexindex.phpindex.htmlindex.htm;}#error_page404/404.html;#将服务器错误页面重定向到静态页面/50x.html#error_page500502503504/50x.html;location=/50x.html{根html;}#将PHP脚本代理到侦听127.0.0.1:80的Apache##location~\.php${#proxy_passhttp://127.0.0.1;#}#将PHP脚本传递给监听127.0.0.1:9000的FastCGI服务器#*location~\.php${root/Users/qsong/Desktop/MILANJUJIA/public;fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;包括fastcgi_params;}*#拒绝访问.htaccess文件,如果Apache的文档根#与nginx的一致##location~/\.ht{#denyall;#}}#另一个混合使用基于IP、名称和端口的配置的虚拟主机##server{#listen8000;#听某个名字:8080;#server_namesomename别名another.alias;#位置/{#根html;#索引index.htmlindex.htm;#}#}#HTTPS服务器##server{#listen443ssl;#server_name本地主机;#ssl_certificatecert.pem;#ssl_certificate_keycert.key;#ssl_session_cache共享:SSL:1m;#ssl_session_timeout5m;#ssl_ciphersHIGH:!aNULL:!MD5;#ssl_prefer_server_ciphers开启;#位置/{#根html;#索引index.htmlindex.htm;#}#}includeservers/*;}如果要配置多个项目,可以在server下添加项目配置(保留最后一行配置includeserver/*open),server下的每个项目对应一个配置文件,下面是我的其中一个配置文件server{listen8995;服务器名称本地主机;access_logaccess_default.log;location/{root/Users/qsong/Desktop/MILANJUJIA/public;indexindex.phpindex.htmlindex.htm;}error_page500502503504/50x.html;location=/50x.html{root/usr/share/nginx/html;}#将PHP脚本传递给侦听127.0.0.1:9000位置的FastCGI服务器~.php${root/Users/qsong/Desktop/MILANJUJIA/public;fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;includecfastcation;giht{全部拒绝;}}完成这些之后,就可以合理的从不同的端口访问项目了,但是在此之前,你需要打开php-fpm。当你打开它时,可能缺少配置文件和日志目录。参考以下命令启动。php-fpm--fpm-config/usr/local/etc/php/7.0/php-fpm.conf--prefix/usr/local/var至此,nginx和php的部署应该就完成了。mysql的安装教程很多。这里不多说。在这里告诉大家,如果不能登陆mysql(没有设置密码),进入mysql安全模式sudo/usr/local/mysql/bin/mysqld_safe--skip-grant-tables现在可以直接执行mysql和进入mysql命令行修改密码UPDATEmysql.userSETauthentication_string=PASSWORD('123456')whereUser='root';//修改root用户密码为123456flush权限;//更新配置重启mysql登录mysql-uroot-p123456至此,php、php-fpm、nginx、mysql都配置好了