Mac os Nginx mysql php

系统运维 2017-11-06

先安装Mac ports ,先要安装XCODE
http://www.macports.org/install.php
https://distfiles.macports.org/MacPorts/
选跟自己系统版本相同的.bkg 安装

  1. 先把软件一路安装完
  2. port install nginx php5 +fastcgi +pear mysql5 mysql5-server spawn-fcgi php5-mysql php5-memcache php5-mcrypt php5-pear php5-curl php5-iconv php5-gd php5-posix memcached

需要比较长的时间,可以先去泡个咖啡,龟速网络的孩子们可以先去把个妹看场电影再回来。上面的php组件可按需安装。

  1. 设置Mysql
  2. -u _mysql mysql_install_db5

sudo /opt/local/lib/mysql5/bin/mysqld_safe &
sudo /opt/local/lib/mysql5/bin/mysql_secure_installation

按照引导完成Mysql的root用户,test用户等设置安装
默认mysqld不会设置my.ini文件,如果需要自定义,可建立一个,并做需要的修改:
sudo cp /opt/local/share/mysql5/mysql/my-medium.cnf/opt/local/etc/mysql5/my.cnf
sudo vi /opt/local/etc/mysql5/my.cnf

  1. 设置PHP
  2. /opt/local/etc/php5

sudo mv php.ini-development php.ini
sudo /opt/local/bin/spawn-fcgi -C 5 -p 9000 /opt/local/bin/php-cgi #启动fcgi,开发环境,起5个进程足矣,多了浪费。
sudo ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.sock #建立mysql soket连接,否则php无法连接mysql

  1. 设置Nginx
  2. /opt/local/etc/nginx #

sudo mv nginx.conf.example nginx.conf #建立nginx的配置文件
sudo vi nginx.conf #修改vitualhost的配置,大约的参考为:(更详细的配置,可以参考我之前所写的 Ubuntu下使用Nginx+PHP教程

test.conf
server {

listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
    #root share/nginx/html;
    root /data/php_workspaces;
    index index.html index.htm index.php;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# 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 /data/php_workspaces$fastcgi_script_name;
    include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}

}

sudo nginx -t #测试nginx
nginx: the configuration file /opt/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /opt/local/etc/nginx/nginx.conf test is successful
sudo nginx #如果测试成功,则启动

检测配置文件是否有效 sudo nginx -t

重启

sudo nginx -s reload
sudo echo "< ?php phpinfo();" --> /data/php_workspaces/index.php

浏览器打开 127.0.0.0.1 应该可以看到phpinfo的信息页面了。
接下来,如果都OK的话,将这几个服务都设置为开机启动
sudo launchctl load -w /Library/LaunchDaemons/org.macports.nginx.plist#设置NGINX
sudo launchctl load -w/Library/LaunchDaemons/org.macports.mysql5.plist
cd /Library/LaunchDaemons/ #建立一个fastcgi的启动脚本
sudo vi com.luochunhui.php-fastcgi.plist


本文由 伯仁 创作,采用 知识共享署名 3.0,可自由转载、引用,但需署名作者且注明文章出处。

还不快抢沙发

添加新评论