mac os LNMP 配置(親測)

在歷時兩天的折騰後,我想有必要總結一下經驗,一方面自我梳理,方便之後用。另外一方面也給其餘碰到相同問題的人提供方法。

  1. 安裝brew:(mac 下的包管理工具),在最新的 mac os 下是自帶的php

  2. 在最新的 mac os 下,php 是自帶的html

  3. 安裝nginx :brew install nginxmysql

  4. 啓動 nginx:sudo nginx ,訪問 http://localhost:8080看是否正常訪問nginx

  5. 前面都不要更改服務器配置可是接下來就厲害了,重點!!!
    廢話很少說直接上配置文件nginx.confsql

#user  *root*;
worker_processes  1;

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

       # access_log  logs/host.access.log  main;

        location / {
            root   /Users/qsong/Desktop/MILANJUJIA/public;
            index  index.php index.html index.htm;
        }

        #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   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          /Users/qsong/Desktop/MILANJUJIA/public;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$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;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    include servers/*;
}

想要配置多個項目的能夠在server下添加項目配置(注意保持最後一行配置 include server/*打開),在 server 下每一個項目對應一個配置文件,下面是個人一個配置文件安全

server {
        listen  8995;
        server_name  localhost;
        access_log  access_default.log  ;
        location / {
            root   /Users/qsong/Desktop/MILANJUJIA/public;
            index  index.php index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ .php$ {
            root          /Users/qsong/Desktop/MILANJUJIA/public;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
        location ~ /.ht {
            deny  all;
        }
}

完成這些後按道理就能夠從不一樣端口訪問項目了,但這以前還需開啓 php-fpm。
開啓的時候可能會出現缺乏配置文件、缺乏日誌目錄的狀況,參考如下命令啓動。服務器

php-fpm --fpm-config /usr/local/etc/php/7.0/php-fpm.conf  --prefix /usr/local/var

到這裏應該就完成了 nginx 和 php的部署session

mysql
安裝的教程不少,這裏很少說。這裏說一下若是碰到不能登入 mysql (未設置密碼)的狀況進入mysql的安全模式app

sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables

如今就能夠直接執行 mysql 進入 mysql命令行
修改密碼tcp

UPDATE mysql.user SET authentication_string=PASSWORD('123456') where User='root'; //將root用戶密碼改爲 123456
flush privileges; //更新配置

重啓 mysql就能夠登入

mysql -u root -p 123456

至此,php、php-fpm、nginx、mysql 配置完畢

相關文章
相關標籤/搜索