如安在Mac OS下树立LnMP开发环境?
一、概述
咱们应该都知道LNMP代表的就是:Linux体系下Nginx+MySQL+PHP这种网站服务器架构。Linux是一类Unix计算机操作体系的总称,是现在最盛行的免费操作体系。代表版别有:debian、centos、ubuntu、fedora、gentoo等。Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。Mysql是一个小型联络型数据库办理体系。PHP是一种在服务器端履行的嵌入HTML文档的脚本语言。这四种软件均为免费开源软件,组合到一同,成为一个免费、高效、扩展性强的网站服务体系。下面来看看本文的具体内容吧。
二、装置Homebrew
运用Mac的程序员必不可少的一步就是装置Homebrew,他就像是centOS的yum
指令和ubuntu的apt-get
指令相同,经过brew
指令,咱们能够快速的装置一些软件包。
运用指令行装置Homebrew的指令如下:
vwin娱乐场ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
运用brew doctor
查看是否存在抵触,然后运用brew update && brew upgrade
对brew进行晋级。
三、装置nginx
nginx在Mac OS中能够直接运用brew指令进行装置:
brew install nginx
假如需求运用80端口的话,需求将nginx参加root组傍边:
sudo cp -v /usr/local/opt/nginx/*.plist /Library/LaunchDaemons/ sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
然后运用指令发动nginx服务:
sudo nginx
测验nginx是否装置成功,由于默许装备文件监听的是8080端口,所以先对8080端口建议恳求:
curl -IL http://127.0.0.1:8080
成果应该相似于下:
HTTP/1.1 200 OK Server: nginx/1.9.1 Date: Fri, 29 May 2015 14:50:47 GMT Content-Type: text/html Content-Length: 612 Last-Modified: Fri, 29 May 2015 14:40:47 GMT Connection: keep-alive ETag: "5444dea7-264" Accept-Ranges: bytes
nginx的相关操作如下:
sudo nginx //发动nginx sudo nginx -s reload|reopen|quit //从头加载|重启|退出
四、装置php-fpm
由于brew并没有php-fpm的源,所以首要要增加源:
brew tap homebrew/dupes brew tap homebrew/php
然后装置php-fpm,输入指令:
brew install php56 --whitout-apache --with-imap --with-tidy --with-debug --with-pgsql --with-mysql --with-fpm
程序会主动装置,等候几分钟后完结装置。
装置完结后,还需求将php参加$PATH
傍边:
# 假如运用bash的话 vim ~/.bash_profile export PATH="/usr/local/sbin:$PATH" source ~/.bash_profile # 假如运用ZSH的话 vim ~/.zshrc export PATH="/usr/local/sbin:$PATH" source ~/.zshrc
然后能够设置php-fpm的开机自发动:
mkdir -p ~/Library/LaunchAgents ln -sfv /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist
运用以下指令监测php-fpm是否发动成功:
lsof -Pni4 | grep LISTEN | grep php
假如发动成功应当有以下相似输出:
php-fpm 27578 wenzhiquan 9u IPv4 0xf29f8b26c08fc27 0t0 TCP 127.0.0.1:9000 (LISTEN) php-fpm 27628 wenzhiquan 0u IPv4 0xf29f8b26c08fc27 0t0 TCP 127.0.0.1:9000 (LISTEN) php-fpm 27629 wenzhiquan 0u IPv4 0xf29f8b26c08fc27 0t0 TCP 127.0.0.1:9000 (LISTEN) php-fpm 27630 wenzhiquan 0u IPv4 0xf29f8b26c08fc27 0t0 TCP 127.0.0.1:9000 (LISTEN)
五、装置MySQL
MySQL也能够运用brew指令直接进行装置:
brew install mysql
相同,能够设置MySQL的开机自发动:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
然后进行MySQL的安全装置,运用以下指令,能够更改root暗码、删去匿名用户、封闭长途衔接等:
mysql_secure_installation
然后会输出以下内容:
> Enter current password for root (enter for none): //默许没有暗码,直接回车即可 > Change the root password? [Y/n] //是否更改root暗码,挑选是,然后输入并承认暗码 > Remove anonymous users? [Y/n] //是否删去匿名用户,挑选是 > Disallow root login remotely? [Y/n] //是否制止长途登录,挑选是 > Remove test database and access to it? [Y/n] //是否删去test数据库,挑选是 > Reload privilege tables now? [Y/n] //是否重载表格数据,挑选是
测验数据库是否装置成功:
mysql -u root -p
然后输入方才设置的root暗码,将会输出以下内容:
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> exit //输入exit退出数据库
六、装备nginx
首要,为咱们的装备文件创立一些文件夹,这些是模仿ubuntu的nginx结构进行树立的目录:
mkdir -p /usr/local/etc/nginx/logs mkdir -p /usr/local/etc/nginx/sites-available mkdir -p /usr/local/etc/nginx/sites-enabled mkdir -p /usr/local/etc/nginx/conf.d mkdir -p /usr/local/etc/nginx/ssl sudo mkdir -p /var/www sudo chown :staff /var/www sudo chmod 775 /var/www
然后修正nginx装备文件:
vim /usr/local/etc/nginx/nginx.conf
将内容替换为:
worker_processes 1; error_log /usr/local/etc/nginx/logs/error.log debug; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /usr/local/etc/nginx/logs/access.log main; sendfile on; keepalive_timeout 65; index index.html index.php; include /usr/local/etc/nginx/sites-enabled/*; }
然后创立php-fpm装备文件:
vim /usr/local/ect/nginx/conf.d/php-fpm
输入以下内容:
location ~ \.php$ { try_files $uri = 404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param script_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
然后参加站点装备文件:
vim /usr/local/ect/nginx/sites-enabled/default
输入以下内容:
server { listen 80; server_name localhost; root /var/www/; access_log /usr/local/etc/nginx/logs/default.access.log main; location / { include /usr/local/etc/nginx/conf.d/php-fpm; } location = /info { allow 127.0.0.1; deny all; rewrite (.*) /.info.php; } error_page 404 /404.html; error_page 403 /403.html; }
重启nginx,至此,装备完结,在www下写一个测验文件,进行测验即可
总结
以上就是在Mac OS上树立LNMP开发环境的悉数过程了,纵情的享用在Mac OS开发PHP的快感吧!期望本文的内容对咱们的学习或许作业能带来必定的协助,假如有疑问咱们能够留言沟通,谢谢咱们对vwin的支撑。
本文地址:http://www.anyuan2002.com/bcdm/89225.html