Mac Apache PHP and CGI configuration

Source: Internet
Author: User
Tags apache php
This article introduces the contents of the Mac Apache PHP and CGI configuration, has a certain reference value, now share to everyone, the need for friends can refer to

Today read a lot about PHP and CGI on the Mac Apache configuration of the tutorial, follow the steps to operate or not, finally through the attempt to configure the success, the following I will summarize some of its configuration process, I hope to help everyone!!!!

# 1. PHP Configuration on Mac
# (1) View Apache version information enter apachectl-v on the terminal

Server version:apache/2.4.29 (Unix)

Server Built:jan 17 2018 18:20:31

# (2) Find Apache configuration file
#在目录/etc/apache2/, open the Finder, select "Go"-"Go to Folder", enter "/etc/apache2/",

#找到其中的 "httpd.conf" file, first copy out to the desktop

# (3) Open the Find #LoadModule as a text editor Php7_module libexec/apache2/libphp7.so to remove the ' # ' from the front

# find
“#
#ServerName www.example.com:80

Add a line below it ServerName localhost:80


# (4) Custom directory configuration
Found in "httpd.conf" file
DocumentRoot "/library/webserver/documents"
<directory "/library/webserver/documents" >
and change it to (/users/admin/sites) its own definition of the path can be modified according to their own needs
DocumentRoot "/users/admin/sites"
<directory "/users/admin/sites" >

Found it
#
Options FollowSymLinks MultiViews
Multiviewsmatch any
Switch
#
Options Indexes followsymlinks MultiViews

Multiviewsmatch any

Replace httpd.conf with httpd.conf file under/etc/apache2/path after the modification is complete


# (5) Create test file to verify that PHP is successfully configured
# Enter cp/library/webserver/documents/index.html.en/users/admin/sites/index.php on the terminal
# Open index.php in text-editing mode and add <?php phpinfo () in the back;?>
# launch Apache on terminal to input sudo apachectl-k restart

# Open Browser input localhost




# 2. Configure CGI
In the above operation, copy the httpd.conf file on the desktop to continue to modify
Find #loadmodule cgi_module libexec/apache2/mod_cgi.so Remove the front ' # '


Find <directory "/library/webserver/cgi-executables" >
Change to <directory "/users/admin/sites/cgi" > Note: the Custom path (/users/admin/sites/cgi) must be in the root directory modified earlier (documentroot "/users/ Admin/sites ")
<directory "/users/admin/sites/cgi" >
AllowOverride None
Options execcgi
Order Deny,allow
Allow from all
</Directory>


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"
Last save replace replace httpd.conf file under/etc/apache2/path
Restart Apache input sudo apachectl-k restart on the terminal


Put the hello.py file under the custom working directory (my is/users/admin/sites/cgi)
The file contents are as follows
#!/usr/bin/python
#-*-Coding:utf-8-*-


Print "content-type:text/html"
Print
print ' print ' print ' <meta charset= ' utf-8 > '
print ' <title>hello! </title> '
print ' print ' <body> '
print ' print ' </body> '
print '

Open Browser Input localhost/cgi-bin/hello.py

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.