在 Mac 上搭建 Nginx PHP Mysql 開發環境,nginxmysql

來源:互聯網
上載者:User

在 Mac 上搭建 Nginx PHP Mysql 開發環境,nginxmysql

  • 其實這個過程跟Linux下安裝都差不多,只是部分命令有差別,大同小異。

    網上看到很多教程都是用 brew 之類的包管理器安裝,但是 Mac 內建了 php , 難道還要再裝一個第三方的?強迫症果斷不能忍,於是就想利用內建的 php-fpm 來搭建,沒想到一搭建就是兩個小時,在這裡把過程整理一下備用,同時也方便需要的人。

    因為是調試環境,所以沒有注重安全方面,有些東西直接 chmod 777 了 要用於ws的話還是改改吧。

    下載 nginx 原始碼 並開始編譯

    tar zxvf nginx.tar.gzcd nginx−1.7.4./configure

    執行報錯:

    ./configure: error: the HTTP rewrite module requires the PCRE library.You can either disable the module by using −−without−http_rewrite_moduleoption, or install the PCRE library into the system, or build the PCRE librarystatically from the source with nginx by using −−with−pcre=<path> option.

    Rewrite 需要 PCRE 庫的支援 , 下載pcre庫後進行編譯安裝

    tar xvzf pcre.tar.gzcd pcre-8.35./configuremakesudo make install

    重新編譯nginx

    cd .../configuremakesudo make install

    建立一個符號連結讓開關容易一些

    sudo ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx

    有了 web 服務,接著嘗試啟動系統內建的php-fpm

    php-fpm

    執行報錯

    ERROR: failed to open configuration file '/private/etc/php-fpm.conf': No such file or directory (2)

    找不到設定檔,為了省事就直接把.default複製,然後賦予許可權

    sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.confsudo chmod 777 /private/etc/php-fpm.confsudo php-fpm

    嘗試啟動報錯:

    ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory (2)

    找不到檔案夾就建立

    sudo mkdir /usr/varsudo mkdir /usr/var/logsudo php-fpm

    此時PHP正常啟動,不過還是需要完善一下 ,放置一下設定檔,修改一下許可權,如果開公網訪問的話“中獎”就杯具了,這種東西還是不要用 su 執行好一點。

    cp /etc/php.ini.default  /etc/php.inisudo chmod 777 /etc/php.inisudo killall php-fpmphp-fpm

    此時PHP正常啟動 有兩個notice 可以不管他

    NOTICE: [pool www] 'user' directive is ignored when FPM is not running as rootNOTICE: [pool www] 'group' directive is ignored when FPM is not running as root

    修改 nginx 設定檔 使其可以處理php

    location ~ \.php$ {      root   /path/to/wwwroot;      fastcgi_pass   127.0.0.1:9000;      fastcgi_index  index.php;      include        fastcgi_params;      fastcgi_param  SCRIPT_FILENAME  /path/to/wwwroot$fastcgi_script_name;}

    啟動 nginx

    sudo nginx

    接下來就是 mysql 了

    從官方下載 ( 下載DMG的話安裝更簡單的,可是我手賤下載了tar )http://dev.mysql.com/downloads/mysql/

    tar zxvf mysql.tar.gzcd mysql-*mkdir /User/typcn/mysqlmv * /User/typcn/mysql/cd /User/typcn/mysqlsudo chown -R _mysql .#賦予許可權sudo chgrp -R _mysql . sudo scripts/mysql_install_db --user=_mysql --datadir=/User/typcn/mysql/data#執行安裝sudo chown -R root . sudo chown -R _mysql data subl my.cnf 

    編輯Mysql 設定檔

    basedir = /path/to/mysqldatadir = /path/to/mysql/dataport = 3306 server_id = 1 socket = /tmp/mysql.sockuser = _mysql 

    用指令碼管理Mysql

    sudo ln -s /User/typcn/mysql/support-files/mysql.server /usr/local/bin/mysqlsubl support-files/mysql.server

    修改設定檔

    basedir=/path/to/mysqldatadir=/path/to/datamysqld_pid_file_path=/path/to/mysql.pid

    好吧。我承認pid什麼的放tmp是個壞習慣。

    sudo mysql start

    現在訪問 localhost 試試吧

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.