Enable CGI on your Apache server(ubuntu+apache2)实践可行
来源:互联网 发布:淘宝众筹玩法 编辑:程序博客网 时间:2024/04/30 12:56
原文地址:http://www.techrepublic.com/blog/diy-it-guy/diy-enable-cgi-on-your-apache-server/#.
It's time to go a little old-school and lay out how to enable the Common Gateway Interface (CGI) for your Apache server. You might be wondering why we need CGI. It's simple: CGI allows the web server to interact with external programs. These programs can range in purpose and scope, but primarily they help to add dynamic content to a website. Most often these applications are Perl programs with the extension .pl, but CGI execution is not limited to Perl.
Get started with CGI
One of the stumbling blocks most people come up against with CGI is getting their Apache server to recognize the CGI directory and to allow for the execution of commands from within that directory. I will demonstrate this process on a Ubuntu 11.04 server running the latest LAMP stack. For the most part, this LAMP stack is default, so a fresh install of LAMP will do just fine.
Let's first talk about the directories. If you look in the /var/www (the document root of Apache), you will find a sub-directory called cgi-bin. This isnot where your Perl programs and other various files will be placed. Within the /usr/lib/ directory, you will find another cgi-bin directory; it is the repository for your executables. If that directory does not exist, create it with the command: sudo mkdir /usr/lib/cgi-bin.Now, make sure the permissions look like this:
drwxr-xr-x 3 root root 4096 2011-11-23 09:08 cgi-bin
Issue the command ls -l /usr/lib | less and scroll to check your directory's permissions. If it's not as you see above, issue the following commands:
sudo chmod 755 /usr/lib/cgi-bin
sudo chown root.root /usr/lib/cgi-bin
Now that your directory is ready, it's time to configure Apache. Remember, this is Ubuntu, so you will have to make a few simple modifications if you're using a different distribution with a different take on the Apache web server.
Configure Apache
A directive must be created so Apache knows about CGI -- where its directories are located and what it can do. In some Apache configurations, this is done within the httpd.conf file. Because this is Ubuntu, we are going to add the directive to the /etc/apache/sites-available. Open that file with your favorite text editor and, before you add anything, search for this section:
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
If the above section does not exist, add it in the <Virtualhost *:80> section just above the line:
ErrorLog ${APACHE_LOG_DIR}/error.log
Save that file and be ready to restart Apache. To restart the server, issue the command:
sudo service apache2 restart
Test it out
Now it's time to test this baby out. Let's create a file (call it test.pl), and the file's contents should be:
#!/usr/bin/perl -wprint "Content-type: text/html\r\n\r\n";
print "Hello there!<br />\nJust testing .<br />\n";
for ($i=0; $i<10; $i++)
{
print $i."<br />";
}
Save that file in /usr/lib/cgi-bin and give it 755 permissions. Now open that file in your web browser (point the browser tohttp://IP_OF_SERVER/cgi-bin/test.pl where IP_OF_SERVER is the address of the server), and you should see the following:
Hello there!
Just testing .
1
2
3
4
5
6
7
8
9
If you see that, CGI is working. You can dump your programs into the /usr/lib/cgi-bin/ directory and start using them It's simple and effective.
- Enable CGI on your Apache server(ubuntu+apache2)实践可行
- Enable Web Server on your MAC
- How to Add Perl CGI Script Support to Your Apache Server on Windows
- How to Add Perl CGI Script Support to Your Apache Web Server on Windows
- ubuntu apache cgi You don't have permission to access /cgi-bin/ on this server.
- Ubuntu 14 中给 APACHE2安装 SSL 模块 Enable SSL site on Ubuntu 14 LTS, Apache 2.4.7:
- Enable CGI by Apache
- 配置apache2支持CGI(UBUNTU)
- ubuntu server 11.04让apache2支持cgi的方法
- UBUNTU 11.04 配置 apache2 + cgi
- UBUNTU配置apache2支持CGI
- ubuntu 实现apache2+python+cgi
- Enable Python on Apache2 (Ubuntu9.10)
- Setup Apache2+Php5+Mysql+Cakephp on Ubuntu Server 10.04
- Enable Diagnostic Messages on your ADF Application
- Use Apache2 on Ubuntu
- ubuntu+apache+cgi配置
- ubuntu apache 执行 cgi
- Android中自定义View的MeasureSpec使用
- 书摘笔记
- 使用 Phrase 格式化 Android 字符串
- Hbase入门6 -白话MySQL(RDBMS)与HBase之间
- 孤鸿寡鹄费和风格和发
- Enable CGI on your Apache server(ubuntu+apache2)实践可行
- Levenshtein distance
- 欧拉函数与容斥
- 仿火车出票效果
- SQL SERVER数据类型与C#数据类型对照表
- 使用EditPlus搭建Lua开发环境
- ios页面跳转动画设置 animation
- i欧普聚会就很看好好机会
- 解决办法fatal error C1083: Cannot open precompiled header file: *.pcb