Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The solution that nginx does not support php in mac

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you the "mac nginx does not support php solutions", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "mac nginx does not support php solutions" this article.

Mac nginx does not support php because there is no configuration of PHP, the solution: 1, use homebrew to install nginx;2, set administrator rights to nginx; 3, execute the command "brew tap josegonzalez/homebrew-php" to install PHP.

This article operating environment: macOS10.15 system, PHP5.6 version, MacBook Air 2019 computer

What if mac nginx does not support php?

Mac install Nginx, configure PHP

Previously, Apache and PHP were used to work together.

Because PHP is self-taught, a lot of people don't understand (TP doesn't look at it, and it's useless)

Recently, I want to write something with nginx and php.

Because I have completed the installation on the computer, I have encountered some problems during this period. I can record it now while I still have a little impression. If you use nginx and php to develop in the future, you can refer to it.

1. Use yum to install software on Linux, and see a homebrew on Mac

2. Then we use homebrew to install nginx

One command installation is complete:

Brew install nginx

Then let's configure the permissions.

1 "set administrator permissions to nginx: Port 80 cannot listen if you do not set administrator permissions."

# the directory here is filled in according to the directory you actually installed. The default is this directory, and the difference is only the version number of nginx sudo chown root:wheel / usr/local/Cellar/nginx/1.10.1/bin/nginx sudo chmod UBSs / usr/local/Cellar/nginx/1.10.1/bin/nginx

2 "join launchctl startup control

Mkdir-p / Library/LaunchAgentscp / usr/local/opt/nginx/homebrew.mxcl.nginx.plist ~ / Library/LaunchAgents/launchctl load-w / Library/LaunchAgents/homebrew.mxcl.nginx.plist

3 "run nginx

Sudo nginx # Open nginxnginx-s reload | reopen | stop | quit # reload configuration | restart | stop | exit nginxnginx-t # to test whether the configuration has syntax errors

3. Install PHP

Since brew does not have a package for php by default, let's execute the following command first

Brew tap homebrew/dupesbrew tap josegonzalez/homebrew-php

There are many versions of php that we can view using brew search php.

What is on my computer is php5.6, but I installed it again using brew, which will not affect the one that comes with mac, because it will be installed under / usr/local/Cellar

Brew install php56

After the installation is complete, in order for the system to use the version I just installed, you need to configure

Sudo vim ~ / .bash_profile# adds the following statement at the end of the file: export PATH= "$(brew-- prefix php56) / bin:$PATH" # after saving the file, the file under source makes the environment variable you just added take effect source ~ / .bash_profile

When you're done, you can use php-v in the terminal to view the version, which is the version I just installed.

Join launchctl to start control

Mkdir-p / Library/LaunchAgentscp / usr/local/opt/php56/homebrew.mxcl.php56.plist ~ / Library/LaunchAgents/launchctl load-w / Library/LaunchAgents/homebrew.mxcl.php56.plist

The path to the php configuration file is as follows

/ usr/local/etc/php/5.6/php.ini/usr/local/etc/php/5.6/php-fpm.conf

After I finished doing this, I went directly to use the php test.

But the nginx service is normal, but php just doesn't show

The reason is that it is in such a hurry that nginx hasn't set up php yet.

The path to the nginx profile is as follows

/ usr/local/etc/nginx/nginx.conf

After opening it, find the following piece.

# pass the PHP scripts to FastCGI server listening on 127.0.0.1 location 9000 # # location ~\. Php$ {# root html; # fastcgi_pass 127.0.0.1 php$ 9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME / scripts$fastcgi_script_name; # include fastcgi_params; #}

Uncomment, and it still doesn't work after restarting nginx. I found out the reason, because the sentence [/ scripts$fastcgi_script_name;] should be [$document_root$fastcgi_script_name;].

Then restart nginx to access php.

I remember that I encountered some minor problems when I started php-fpm, and the contents of the problems were displayed in the terminal.

For example: [/ private/etc/php-fpm.conf] this file is not saved, but there is actually a file with the suffix [.default] in the same directory. Let's just copy this file and change it to php-fpm.conf.

If it is executed later, there may be an error in the error_log path. The default is to Log under [/ usr/var], but the path cannot be found. There are two solutions.

1 "prompt for folders that are not available, we will create

2 "change the php-fpm.conf file we copied just now and find something similar to the following

[global]; Pid file; Note: the default prefix is / usr/var; Default Value: nonepid = / usr/local/var/php-fpm/run/php-fpm.pid; Error log file; If it's set to "syslog", log is sent to syslogd instead of being written; in a local file.; Note: the default prefix is / usr/var; Default Value: log/php-fpm.logerror_log = / usr/local/var/php-fpm/log/php-fpm.log

Both pid and error_log used to be annotated, so we can change it to our own convenient location.

If there are no other special problems up to now, nginx and php can work normally.

We can configure our own access domain name by modifying nginx.conf and hosts files

The above is all the content of the article "nginx does not support php solution in mac". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report