apache 同时支持php,python cgi配置方法

apache 同时支持php,python cgi配置方法

1. 我用的是mac系统默认安装了apache,这里就为给大家介绍apache的安装过程,百度一堆堆的
2. 首先配置虚拟域名:
#vim /etc/apache2/httpd.conf

找到下面这行
#Include /private/etc/apache2/extra/httpd-vhosts.conf
将前面的#号去掉
再打开/etc/apache2/extra/httpd-vhosts.conf 将内容改成以下的样子

		DocumentRoot "/Users/user/Project/php"
		ServerName test.php.com
		ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
		CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
		
			Options Indexes FollowSymLinks MultiViews
			AllowOverride None
			Order deny,allow
			Allow from all
		


将文件添加可读权限
chomd -R 755 /Users/user/Project/php
添加hosts
sudo vi /etc/hosts 以管理员身份打开hosts文件,追加一行
127.0.0.1       test.php.com



保存重启APACHE 
#sudo apachectl restart

3. 配置apache 支持python cgi 加入CGI支持
#vim /etc/apache2/httpd.conf 
LoadModule cgi_module /usr/lib/apache2/modules/mod_cgi.so //默认有则不需要加
AddHandler cgi-script .cgi .pl .py .sh // 我们加入这一句,使CGI支持 perl和python 和shell脚本,这行一般都存在去掉前面的注释即可

#sudo vim /etc/apache2/extra/httpd-vhosts.conf 将以下行加入文件底部

	DocumentRoot "/Users/user/Project/python/cgi-bin"
	ServerName cgi.python.com
	ScriptAlias /cgi-bin/ "/Users/user/Project/python/cgi-bin"
	ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
	CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
	
		Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
		AllowOverride None
		Order deny,allow
		Allow from all
	


添加hosts
sudo vi /etc/hosts 以管理员身份打开hosts文件,追加一行
127.0.0.1       test.php.com

#cd /Users/user/Project/python/
#chmod -R 755 cgi-bin/
重启apache 
#sudo apachectl restart

4. 测试php、cgi、py
#vim test.py
#!/usr/bin/python
print 'Content-Type: text/html\n\nhello world'


保存

#vim test.cgi
#!/usr/bin/python
print 'Content-Type: text/html\n\nhello world'


保存

能打印hello world 一切正常






你可能感兴趣的:(php,python,apache)