MAC通過MacPorts配置 PHP54+PHP FPM+NGINX+MYSQL5.5

來源:互聯網
上載者:User

使用MacPorts配置PHP開發環境(PHP54+PHP FPM+NGINX+MYSQL55),首先需要安裝port,訪問:http://www.macports.org/install.php,直接下載原始碼: https://distfiles.macports.org/MacPorts/MacPorts-2.1.3.tar.gz。

安裝port:

1. tar xzvf MacPorts-2.1.3.tar.gz  解壓

2. cd MacPorts-2.1.3

3. ./configure && make && sudo make install

這樣就安裝好port了。

4. vi ~/.bash_profile

按i鍵進入編輯方式,粘下以下文字:

export PATH=/opt/local/bin:$PATH

按ESC鍵退出編輯方式,按:鍵再輸入wq儲存退出。

現在我們就可以很方便地使用port了。

安裝php:

1. port info php 列出所支援的php資訊,可以根據需要來選對應的版本安裝,我選php54這個版本。

2. sudo port install php54 php54-fpm php54-mysql php54-mbstring php54-mcrypt php54-sockets php54-curl 可以根據需要增加或者減少

3. cd /opt/local/etc/php54/

4. sudo cp ./php-fpm.conf.default ./php-fpm.conf

5. sudo cp ./php.ini-development ./php.ini 可以根據需要換成php.ini-production的

6. vi ~/.bash_profile 加上以下內容:

#php-fpm
alias fpm_start='sudo launchctl load -w /Library/LaunchDaemons/org.macports.php54-fpm.plist'
alias fpm_stop='sudo launchctl unload -w /Library/LaunchDaemons/org.macports.php54-fpm.plist'
alias fpm_restart='fpm_stop; fpm_start'

7. 開啟個新的命令視窗,輸入:fpm_start,php-fpm就開始運行了,可以用top命令查看或者用ps -e | grep php-fpm查看。

這樣子php就已經搞定了。

nginx:

1. sudo port install nginx

2. vi ~/.bash_profile 加上以下內容:

# nginx
alias nginx_start='sudo launchctl load -w /Library/LaunchDaemons/org.macports.nginx.plist'
alias nginx_stop='sudo launchctl unload -w /Library/LaunchDaemons/org.macports.nginx.plist'
alias nginx_restart='nginx_stop; nginx_start;'

3. cd /opt/local/etc/nginx/

4. sudo cp fastcgi.conf.example fastcgi.conf 如此類推,把那些以.example為尾碼的拷出一份沒有.example為尾碼的檔案來。

5. sudo vi nginx.conf 找到

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 這段,內容改成這樣子:

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /opt/local/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}

其實就是去掉前面的#號和改了一下fastcgi_param SCRIPT_FILENAME /opt/local/share/nginx/html$fastcgi_script_name;

6. nginx_start就可以啟動了

7. cd /opt/local/share/nginx/html/

8. vi phpinfo.php 加入以下內容:

<?php phpinfo(); ?>

9. 通過瀏覽器訪問:http://localhost/phpinfo.php 完成。

MYSQL:

1. sudo port install mysql55 再根據安裝完成後的內容設定資料庫

2. vi ~/.bash_profile 加上以下內容:

#mysql
alias mysql_start='sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql55-server.plist'
alias mysql_stop='sudo launchctl unload -w /Library/LaunchDaemons/org.macports.mysql55-server.plist'
alias mysql_restart='mysql_stop; mysql_start'

3. mysql_start

4. sudo vi /opt/local/ect/mysql55/my.cnf 注掉# !include /opt/local/etc/mysql55/macports-default.cnf 這一行,再加上: [mysqld_safe] socket = /tmp/mysql.sock, 否則mysql命令可以串連,工具連不上。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.