Home > Backend Development > PHP Tutorial > Mac apache php and CGI configuration

Mac apache php and CGI configuration

不言
Release: 2023-03-24 12:22:01
Original
2007 people have browsed it

The content of this article is about the configuration of Mac apache php and CGI. It has a certain reference value. Now I share it with you. Friends in need can refer to it.

I read a lot about PHP and CGI today. CGI tutorial on apache configuration on Mac. I followed the steps but it still didn’t work. Finally, I tried to configure it successfully. Below I will summarize some of the configuration process for you. I hope it can help you! ! ! !

# 1. Php configuration on Mac
# (1) To view the version information of Apache, enter apachectl -v

Server version: Apache/2.4.29 (Unix) on the terminal

Server built: Jan 17 2018 18:20:31

#(2) Find the apache configuration file
#In the directory /etc/apache2/, open Finder, Select "Go" - "Go to folder", enter "/etc/apache2/",

#Find the "httpd.conf" file, copy it to the desktop first

# (3) Open the search in the form of text editing #LoadModule php7_module libexec/apache2/libphp7.so and remove the '#' in front of it

# Find
"
# # ServerName www.example.com:80

Add a line below it ServerName localhost:80


#( 4) Custom directory configuration
Find in the "httpd.conf" file
DocumentRoot "/Library/WebServer/Documents"

and It is changed to (/Users/admin/Sites). The self-defined path can be modified according to your own needs.
DocumentRoot "/Users/admin/Sites"


Find

#Options FollowSymLinks Multiviews
MultiviewsMatch Any
Change to

#Options Indexes FollowSymLinks Multiviews

MultiviewsMatch Any

After modification, replace httpd.conf with the httpd.conf file under the /etc/apache2/ path


# (5) Create a test file to verify the configuration php Is it successful?
# Enter cp /Library/WebServer/Documents/index.html.en /Users/admin/Sites/index.php on the terminal
# Open index.php in text editing mode, and then add
# Start apache. Enter sudo apachectl -k restart

# on the terminal. Open the browser and enter localhost




# 2. Configure CGI
Copy the above operation to the httpd.conf file on the desktop and continue to modify it
Find #LoadModule cgi_module libexec/apache2/mod_cgi.so and remove the '#'


Find
Change to Note: The customized path (/Users/admin/Sites/Cgi) must be in the root directory modified previously (DocumentRoot "/Users/admin/Sites")

AllowOverride None
Options ExecCGI
Order deny,allow
Allow from all



Find AddHandler cgi-script .cgi
Change it to
AddHandler cgi-script .cgi .py .pl .sh


Find ScriptAliasMatch ^/ cgi-bin/((?!(?i:webobjects)).*$) "/Library/WebServer/CGI-Executables/$1"
Change it to
ScriptAliasMatch ^/cgi-bin/(( ?!(?i:webobjects)).*$) "/Users/admin/Sites/Cgi/$1"
Finally save and replace the httpd.conf file under the /etc/apache2/ path
Restart apache Enter sudo apachectl -k restart


on the terminal and put the hello.py file in the custom working directory (mine is /Users/admin/Sites/Cgi)
File content As follows
#!/usr/bin/python
# -*- coding: UTF-8 -*-


print "Content-type:text/html"
print
print ''
print ''
print ''
print 'Hello! '
print ''
print ''
print '

Hello test Word!

'
print ''
print ''


Open the browser and enter localhost/cgi-bin/hello.py

The above is the detailed content of Mac apache php and CGI configuration. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template