《PHP應(yīng)用:在Mac OS上搭建Nginx+PHP+MySQL開(kāi)發(fā)環(huán)境的教程》要點(diǎn):
本文介紹了PHP應(yīng)用:在Mac OS上搭建Nginx+PHP+MySQL開(kāi)發(fā)環(huán)境的教程,希望對(duì)您有用。如果有疑問(wèn),可以聯(lián)系我們。
PHP實(shí)例安裝homebrew
PHP實(shí)例homebrew是mac下非常好用的擔(dān)保理器,會(huì)自動(dòng)安裝相關(guān)的依賴包,將你從繁瑣的軟件依賴安裝中解放出來(lái).
安裝homebrew也非常簡(jiǎn)單,只要在終端中輸入:
PHP實(shí)例
<!-- lang: shell -->
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
PHP實(shí)例homebrew的常用命令:
PHP實(shí)例
<!-- lang: shell -->
brew update #更新可安裝包的最新信息,建議每次安裝前都運(yùn)行下
brew search pkg_name #搜索相關(guān)的包信息
brew install pkg_name #安裝包
PHP實(shí)例想了解更多地信息,請(qǐng)參看homebrew
PHP實(shí)例安裝nginx
PHP實(shí)例安裝
PHP實(shí)例
<!-- lang: shell -->
brew search nginx
brew install nginx
PHP實(shí)例當(dāng)前的最新版本是1.4.4.
PHP實(shí)例配置
PHP實(shí)例
<!-- lang: shell -->
cd /usr/local/etc/nginx/
mkdir conf.d
vim nginx.conf
vim ./conf.d/default.conf
PHP實(shí)例nginx.conf內(nèi)容,
PHP實(shí)例
<!-- lang: shell -->
worker_processes 1;
error_log /usr/local/var/log/nginx/error.log warn;
pid /usr/local/var/run/nginx.pid;
events {
worker_connections 256;
}
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/var/log/nginx/access.log main;
port_in_redirect off;
sendfile on;
keepalive_timeout 65;
include /usr/local/etc/nginx/conf.d/*.conf;
}
PHP實(shí)例default.conf文件內(nèi)容,
PHP實(shí)例
<!-- lang: shell -->
server {
listen 8080;
server_name localhost;
root /Users/user_name/nginx_sites/; # 該項(xiàng)要修改為你準(zhǔn)備寄存相關(guān)網(wǎng)頁(yè)的路徑
location / {
index index.php;
autoindex on;
}
#proxy the php scripts to php-fpm
location ~ \.php$ {
include /usr/local/etc/nginx/fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
}
}
PHP實(shí)例安裝php-fpm
PHP實(shí)例Mac OSX 10.9以后的系統(tǒng)自帶了PHP、php-fpm,省去了安裝php-fpm的麻煩.
這里必要簡(jiǎn)單地修改下php-fpm的配置,否則運(yùn)行php-fpm會(huì)報(bào)錯(cuò).
PHP實(shí)例
<!-- lang: shell -->
sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf
vim /private/etc/php-fpm.conf
PHP實(shí)例修改php-fpm.conf文件中的error_log項(xiàng),默認(rèn)該項(xiàng)被注釋掉,這里必要去注釋并且修改為error_log = /usr/local/var/log/php-fpm.log.如果不修改該值,運(yùn)行php-fpm的時(shí)候會(huì)提示log文件輸出路徑不存在的錯(cuò)誤.
PHP實(shí)例安裝mysql
PHP實(shí)例安裝
PHP實(shí)例
<!-- lang: shell -->
brew install mysql
PHP實(shí)例常用命令
PHP實(shí)例
<!-- lang: shell -->
mysql.server start #啟動(dòng)mysql服務(wù)
mysql.server stop #關(guān)閉mysql服務(wù)
PHP實(shí)例配置
在終端運(yùn)行mysql_secure_installation腳本,該腳本會(huì)一步步提示你設(shè)置一系列平安性相關(guān)的參數(shù),包括:設(shè)置root密碼,關(guān)閉匿名訪問(wèn),不允許root用戶遠(yuǎn)程訪問(wèn),移除test數(shù)據(jù)庫(kù).當(dāng)然運(yùn)行該腳本前記得先啟動(dòng)mysql服務(wù).
PHP實(shí)例測(cè)試nginx服務(wù)
PHP實(shí)例在之前nginx配置文件default.conf中設(shè)置的root項(xiàng)對(duì)應(yīng)的文件夾下創(chuàng)立測(cè)試文件index.php:
PHP實(shí)例
<!-- ~/nginx_sites/index.php -->
<?php phpinfo(); ?>
PHP實(shí)例啟動(dòng)nginx服務(wù),
PHP實(shí)例
sudo nginx;
PHP實(shí)例改動(dòng)配置文件,重啟nginx服務(wù),
PHP實(shí)例
sudo nginx -s reload
PHP實(shí)例啟動(dòng)php服務(wù),
PHP實(shí)例
sudo php-fpm;
PHP實(shí)例在閱讀器地址欄中輸入localhost:8080,如果配置正確地話,應(yīng)該能看到PHP相關(guān)信息的頁(yè)面.
《PHP應(yīng)用:在Mac OS上搭建Nginx+PHP+MySQL開(kāi)發(fā)環(huán)境的教程》是否對(duì)您有啟發(fā),歡迎查看更多與《PHP應(yīng)用:在Mac OS上搭建Nginx+PHP+MySQL開(kāi)發(fā)環(huán)境的教程》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.snjht.com/jiaocheng/8190.html