1

I have used this blog as a basis for creating a local environment to run PHP sites on MacOS Sierra. I have installed NGINX, PHP 7, PHP-FPM, MySQl, and PhpMyAdmin. All the parts appear to be working:

Using the default nginx.conf and running: curl -IL http://127.0.0.1:8080, I get:

HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Tue, 22 Aug 2017 08:10:03 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 11 Jul 2017 13:24:27 GMT
Connection: keep-alive
ETag: "5964d18b-264"
Accept-Ranges: bytes

Wiht regard to PHP-FPM, on running: lsof -Pni4 | grep LISTEN | grep php, I get:

php-fpm   13178 phil    6u  IPv4 0x2b2cdb4c34e4e2c3      0t0  TCP 127.0.0.1:9000 (LISTEN)
php-fpm   13181 phil    0u  IPv4 0x2b2cdb4c34e4e2c3      0t0  TCP 127.0.0.1:9000 (LISTEN)
php-fpm   13182 phil    0u  IPv4 0x2b2cdb4c34e4e2c3      0t0  TCP 127.0.0.1:9000 (LISTEN)

I can also start MySQL, I get:

mysql>

Using the default nginx.conf, i can visit http://localhost:8080/ and I see the 'Welcome to nginx!' test screen.

The problem comes when I edit my nginx.conf. Here is how I have edited it:

user  phil staff;
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       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /Users/phil/sites/drupal/;
            index  index.php;
        }

    location ~ \.php {
            fastcgi_split_path_info ^(.+?\.php)(/.*)$;
            if (!-f $document_root$fastcgi_script_name) {
                return 404;
            }
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            include fastcgi_params;
        }

        #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           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$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/*;
}

Now, if I run brew services restart nginx and then sudo nginx -t, I get:

nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful

...but, if I visit http://localhost/, I get Local host refused to connect.

My hunch is it is permissions and using port 80, but I'm not sure what to do to get this working.

If I do curl -IL http://127.0.0.1:80, I get:

curl: (7) Failed to connect to 127.0.0.1 port 80: Connection refused

Thanks.

1 Answer 1

1

The solution was to restart the NGINX service with sudo.

sudo brew services restart nginx

You must log in to answer this question.