DEV Community

How to setup Nginx and PHP7.1 with FPM on Mac OS X without crying

Valentine on October 29, 2017

I had problems with my nginx for months. I read a ton of articles online but couldn't find a solution. Most of what I saw was for php7.0, and the...
Collapse
 
thanhoangxuannghiep profile image
thanhoangxuannghiep

Hi, I am following this article. But when I run "brew tap homebrew/dupes". I got this error: "Error: homebrew/dupes was deprecated. This tap is now empty as all its formulae were migrated". How can I fix this? I tried to search but I do not found any solution. I am using Homebrew 1.6.4. MacOS high sierra version 10.13.4 (17E202). Thanks.

Collapse
 
chiefoleka profile image
Valentine

Did you find a solution? You only needed to find the replacement for homebrew/dupes

Collapse
 
enggsher profile image
Sher Bahadur

When, I have created info.php file as you suggested and when I am hitting the URL (localhost:8080/info.php) the file is getting downloaded instead of displaying details.

Can you please help me out.
I want to setup a Laravel project and run through Nginx.

Thanks in advance.

Collapse
 
chiefoleka profile image
Valentine

Hi Sher,

I apologise for getting to this late. This usually happens when PHP is not properly configured. Nginx isn't passing the PHP script to FPM or FPM is not processing it at all (probably not set up properly), so it is sending the file because it does not know what to do.

Also, be sure your PHP installation is not using the .sock file but is processing via port 9000. Look at /etc/php/{PHP_VERSION}/fpm/pool.d/www.conf and be sure what it is listening to sock file: prnt.sc/s2dr4p or port 9000: prnt.sc/s2dvdv. It may also be in /etc/php/{PHP_VERSION}/php-fpm.d/www.conf depending on your installation. Just find it.

Let me know if you have found a solution for it.

Collapse
 
madaarya profile image
Mada Aryakusumah • Edited

about fastcgi_param , not sure about the default is not work. But this config will work

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name
Enter fullscreen mode Exit fullscreen mode
Collapse
 
e4neilook profile image
e4ne

This was pretty much useless, it still didn't work for many reasons.
Thanks for trying

Now I have to cry

Collapse
 
chiefoleka profile image
Valentine

What result did you get at the end of the day?

I mean, I wrote this about 1 year ago, so a lot might have changed since then.

Nonetheless, share what didn't work let me see if I can help.

Collapse
 
e4neilook profile image
e4ne

Hi Valentine!

Thanks for replying.

I might found a solutions that now works. It took me three days to reach there. Now the only thing I have left is to make a websocket proxy works properly with SSL.

You're right things seems to happens very rapidly. There are many non up to date articles out there that sometimes confusing a bit.

Your solution might work indeed if I had the pleasure to be use a new fresh sierra. But that was unfortunate not the case. I have been sort of messing up a few configurations, packages, not update, miss to set permissions, right user etc.

But now that is in right place/order.

The only thing I have left is to setup a properly websocket proxy to sort of prevent expose ports for the end-user. Here is what it looks like:

Thanks for helping , very kind of you!

....

http {

   ....

    server {
        listen          443 ssl;
        server_name     mydomain.com;
        client_max_body_size 20M;

        root            /Users/myusers/Documents/www/;

        access_log      /Users/myusers/Documents/logfiles/default-ssl.access.log  main;

        ssl_certificate      /Users/myusers/Documents/cert/mydomain.com/public_cert.crt;
        ssl_certificate_key  /Users/myusers/Documents/cert/mydomain.com/private_cert.key;

        ssl_session_timeout  5m;

        ssl_protocols  SSLv2 SSLv3 TLSv1;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers   on;


        location / {
            index  index.php index.html index.htm;
        }

        ....

        # For the websocket
        location /websocket/ {
            proxy_pass https://mydomain.com:8443;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_read_timeout 86400;
        }
    }

}

(note: everything working and SSL cert and php, permissions, etc.
But now I also have a node-js-server that is up and running correctly. the DNS mydomain.com is a changed host DNS, so its not live or real!
It points to localhost/127.0.0.1 in the hostfile on my machine, but that should work too).

Collapse
 
milosb793 profile image
milosb793

I'm crying nevertheless :'(

Collapse
 
http91 profile image
T

Dude...

Thanks.

Collapse
 
rango3526 profile image
Ranger

This was a huge help even in 2023, thank you!!