摘要:第一步关闭及开机启动要使用,最好停用中自带的。解压后将目录下的所有文件放到网站根目录下如。设置本地域名打开文件,另起一行输入,保存文件。
对于不懂后端的我,做这件事真是受尽折磨。 在不懈努力下,终于成功。 下面写下笔记,与大家分享。
第一步:关闭Apache及开机启动要使用nginx,最好停用mac中自带的Apache。停用很简单:
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
第二步:安装homebrewhomebrew是mac下的包管理器,类似于linux下的yum,apt。使用homebrew安装nginx,php,mysql要比手动安装方便很多。官网地址:http://brew.sh/index_zh-cn.html
安装:
sudo ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
第三步:安装nginx安装:brew install nginx
启动:sudo nginx
停止:sudo nginx -s quit
配置nginx:
在/usr/local/var/log/nginx/下,新建文件:access.log、error.log
配置/usr/local/etc/nginx/nginx.conf
#user nobody; worker_processes 1; error_log /usr/local/var/log/nginx/error.log; pid /usr/local/var/run/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; access_log /usr/local/var/log/nginx/access.log; sendfile on; keepalive_timeout 65; # include conf.d/*.conf; }
在/usr/local/etc/nginx/下,新建文件夹conf.d。在conf.d/下,新建文件default.conf,配置default.conf:
server { listen 80 default_server; server_name localhost; #域名,自定义 root 网站根目录; #自定义,如/var/www index index.html index.htm }
测试:在你设定的根目录下(例如/var/www/),新建一个静态页index.html,启动nginx,在浏览器中输入localhost,成功看到静态页内容。
第四步:安装php首先,在brew中添加php的源:
brew tap josegonzalez/php
brew tap homebrew/dupes
查看已添加的源:brew tap
搜索可安装的php:brew search php
一看结果,我靠,怎么这么多!不懂php的我,完全不懂这些是什么东西。 不过不用管他们。只要知道该安装哪些就好。
看到别人安装最多的是php55,安装前首先查看一下安装相关参数的说明:
brew search php55
结果:
--disable-opcache Build without Opcache extension --homebrew-apxs Build against apxs in Homebrew prefix --with-apache Enable building of shared Apache 2.0 Handler module, overriding any options which disable apache --with-cgi Enable building of the CGI executable (implies --without-apache) --with-debug Compile with debugging symbols --with-enchant Build with enchant support --with-fpm Enable building of the fpm SAPI executable (implies --without-apache) --with-gmp Build with gmp support --with-homebrew-curl Include Curl support via Homebrew --with-homebrew-libxslt Include LibXSLT support via Homebrew --with-homebrew-openssl Include OpenSSL support via Homebrew --with-imap Include IMAP extension --with-libmysql Include (old-style) libmysql support instead of mysqlnd --with-mssql Include MSSQL-DB support --with-pdo-oci Include Oracle databases (requries ORACLE_HOME be set) --with-phpdbg Enable building of the phpdbg SAPI executable (PHP 5.4 and above) --with-postgresql Build with postgresql support --with-thread-safety Build with thread safety --with-tidy Include Tidy support --without-bz2 Build without bz2 support --without-mysql Remove MySQL/MariaDB support --without-pcntl Build without Process Control support --without-pear Build without PEAR --without-snmp Build without SNMP support --HEAD Install HEAD version
没搞明白这些是什么意思,先这么装吧:
brew install php55 --with-fpm, --with-enchant, --with-debug
成功安装后,启动php-fpm:(php-fpm相当于一个接口,nginx和php之间通信通过php-fpm这个东西)
launchctl load -w /usr/local/opt/php55/homebrew.mxcl.php55.plist
停止php-fpm:
launchctl unload -w /usr/local/opt/php55/homebrew.mxcl.php55.plist
设置快捷指令:打开~/.bash_profile,添加
alias php55.start=launchctl load -w /usr/local/opt/php55/homebrew.mxcl.php55.plist alias php55.stop=launchctl unload -w /usr/local/opt/php55/homebrew.mxcl.php55.plist
快捷指令设置之后,重启shell,就可以用php55.start和php55.stop来启动和停止php-fpm了。
重新配置nginx:配置文件/usr/local/etc/nginx/conf.d/default.conf
server { listen 80 default_server; server_name localhost; #域名,自定义 root 网站根目录; #自定义,如/var/www index index.html index.htm # pass the PHP scripts to FastCGI slinerver listening on 127.0.0.1:9000 # location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME 网站根目录$fastcgi_script_name; #如/var/www$fastcgi_script_name include fastcgi_params; fastcgi_intercept_errors on; } }
测试:重启nginx,启动php-fpm后,在网站根目录下新建文件index.php,设置index.php的内容:。然后浏览器中输入:localhost/index.php,看到php信息,成功。
第五步:安装mysql安装:brew install mysql
启动:launchctl load -w /usr/local/opt/mysql/homebrew.mxcl.mysql.plist
停止:launchctl unload -w /usr/local/opt/php55/homebrew.mxcl.php55.plist
设置快捷指令:同php-fpm快捷指令一样,打开~/.bash_profile,添加
alias mysql.start=launchctl load -w /usr/local/opt/mysql/homebrew.mxcl.mysql.plist alias mysql.stop=launchctl unload -w /usr/local/opt/mysql/homebrew.mxcl.mysql.plist
初始化mysql:运行/usr/local/opt/mysql/bin/mysql_secure_installation 将有一个向导知道你一步一步设定安全和配置信息。
安装phpmyadmin: 在http://www.phpmyadmin.net/home_page/downloads.php下载最新版的phpmyadmin,解压后将目录下的所有文件放到网站根目录/phpmyadmin下(如/var/www/phpmyadmin),然后浏览器中输入localhost/phpmyadmin出现首页,输入数据库账号(root)和密码,登陆成功。
第六步:安装wordpress下载:从https://wordpress.org/download/上下载最新版的wordpress。
解压后将目录下的所有文件放到网站根目录/wordpress下(如/var/www/wordpress)。
设置本地域名:打开文件/etc/hosts,另起一行输入127.0.0.1 mywordpress,保存文件。
我遇到一件很头疼的事:明明nginx,php,mysql都没有问题,可是每当初始化wordpress总会遇到nginx报错:
google一查,原来wordpress官方专门有个配置nginx的教程:http://codex.wordpress.org/Nginx
重新配置nginx:
配置/usr/local/etc/nginx.conf
#user nobody; worker_processes 1; error_log /usr/local/var/log/nginx/error.log; pid /usr/local/var/run/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; access_log /usr/local/var/log/nginx/access.log; sendfile on; keepalive_timeout 65; #php max upload limit cannot be larger than this client_max_body_size 13m; index index.php index.html index.htm; # Upstream to abstract backend connection(s) for PHP. upstream php { #this should match value of "listen" directive in php-fpm pool #server unix:/tmp/php-fpm.sock; server 127.0.0.1:9000; } # # include conf.d/*.conf; }
在/usr/local/etc/nginx/下新建目录global,在/usr/local/etc/nginx/global/下新建文件添加文件restrictions.conf 和 wordpress.conf,分别添加如下内容:
restrictions.conf:
# Global restrictions configuration file. # Designed to be included in any server {} block. location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) location ~ /. { deny all; } # Deny access to any files with a .php extension in the uploads directory # Works in sub-directory installs and also in multisite network # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) location ~* /(?:uploads|files)/.*.php$ { deny all; }
wordpress.conf:
# WordPress single blog rules. # Designed to be included in any server {} block. # This order might seem weird - this is attempted to match last if rules below fail. # http://wiki.nginx.org/HttpCoreModule location / { try_files $uri $uri/ /index.php?$args; } # Add trailing slash to */wp-admin requests. rewrite /wp-admin$ $scheme://$host$uri/ permanent; # Directives to send expires headers and turn off 404 error logging. location ~* ^.+.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { access_log off; log_not_found off; expires max; } # Uncomment one of the lines below for the appropriate caching plugin (if used). #include global/wordpress-wp-super-cache.conf; #include global/wordpress-w3-total-cache.conf; # Pass all .php files onto a php-fpm/php-fcgi server. location ~ [^/].php(/|$) { fastcgi_split_path_info ^(.+?.php)(/.*)$; if (!-f $document_root$fastcgi_script_name) { return 404; } # This is a robust solution for path info security issue and works with "cgi.fix_pathinfo = 1" in /etc/php.ini (default) include fastcgi.conf; fastcgi_index index.php; # fastcgi_intercept_errors on; fastcgi_pass php; }
在/usr/local/etc/nginx/conf.d/下新建文件 mywordpress.conf,配置文件内容
server { server_name mywordpress; root 网站根目录/mywordpress; #自定义,如/var/www/mywordpress index index.php; include global/restrictions.conf; include global/wordpress.conf; }
最后一步:重启nginx,启动php-fpm和mysql,在浏览其中输入mywordpress,出现初始化向导,按照向导设置数据库信息,然后成功。
如有问题欢迎留言与我联系! 或者邮箱:linchen.1987@foxmail.com
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/39119.html
摘要:第一步关闭及开机启动要使用,最好停用中自带的。解压后将目录下的所有文件放到网站根目录下如。设置本地域名打开文件,另起一行输入,保存文件。 对于不懂后端的我,做这件事真是受尽折磨。 在不懈努力下,终于成功。 下面写下笔记,与大家分享。 第一步:关闭Apache及开机启动 要使用nginx,最好停用mac中自带的Apache。停用很简单: sudo launchctl unload ...
摘要:是一个像或的服务器。得益于的特性,只是一个小小的二进制文件,没有依赖,很好部署。我们来试试在当前目录创建这样一个叫的文件这次,我们改变了端口,并且启用了自动压缩数据。据说全世界四分之一的站点都是搭建的,而公认是世界上最好的语言。 caddy 是一个像 Apache, nginx, 或 lighttpd 的web服务器。你要问nginx已经很好了,为什么要用caddy呢? 我觉得cadd...
摘要:先来一段吐槽好朋友校招进百度前端团队了我还在找工作好心塞但是蛮为他高兴的是我的问题技术面铺的太开了,没有深入的一项比较深入的也就是渗透,了吧但是渗透团队要求好高网易跪在了面绿盟进行中工资略低啊技能点大概是星满分星星渗透星星网络安全星,学习能 PS: 先来一段吐槽...好朋友校招进百度前端团队了..我还在找工作ing..好心塞.但是蛮为他高兴的. 是我的问题.技术面铺的太开了,没有深...
摘要:一步一步教你基于搭建自己的个人博客,作为成熟的框架,美观,方便,插件多,更新频繁,非常适合个人博客与网站的搭建,适合新手,无需太多的代码基础。原文链接手把手教你搭建自己的网站购买购买云服务器为了搭建个人网站,首先肯定需要一个云服务器。 一步一步教你基于WordPress搭建自己的个人博客,WordPress作为成熟的CMS框架,美观,方便,插件多,更新频繁,非常适合个人博客与网站的搭建...
摘要:以下为文章的原文项目简介通过使用腾讯云多种产品证书并配合使用知名系统,从无到有打造一个自己在互联网空间中的自留地。战前准备拥有一个已经在腾讯云备案成功的域名。 推荐理由: 今天我在腾讯云技术社区—腾云阁看到一篇文章,我感觉对我们这些小白进军互联网很有帮助,让我重新认识了云端的部署和构架,以及对云服务器、云数据库、CDN、云安全、万象图片和云点播等产品的一个了解,在此我也想给大家分享一下...
阅读 968·2021-11-22 13:52
阅读 1411·2021-11-19 09:40
阅读 3020·2021-11-16 11:44
阅读 1206·2021-11-15 11:39
阅读 3798·2021-10-08 10:04
阅读 5216·2021-09-22 14:57
阅读 3073·2021-09-10 10:50
阅读 3134·2021-08-17 10:13