自己做免费手机网站,有限公司网站建设 互成网络地址 四川,seo推广软件哪个好,荥阳市网站建设最近学习了下perl#xff0c;尝试自己搭建一个聊天室#xff0c;现已搭建成功#xff0c;但设计方法很简陋#xff0c;误见笑#xff0c;收获在于对apache、html、perl都有了些许认识#xff0c;后面打算学习LAMP#xff08;LinuxApacheMySQLPHP#xff09;搭建一个在线… 最近学习了下perl尝试自己搭建一个聊天室现已搭建成功但设计方法很简陋误见笑收获在于对apache、html、perl都有了些许认识后面打算学习LAMPLinuxApacheMySQLPHP搭建一个在线听歌网页。 操作系统Ubuntu 12.04.2 LTS linux内核Linux ubuntu 3.5.0-23-generic #35~precise1-Ubuntu SMP Fri Jan 25 17:13:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux apache版本Apache/2.2.22 (Ubuntu) 编程语言HTML perl 一、安装apache sudo apt-get install apache2 二、编写HTML聊天WEB界面 1、chatroom.html文件代码 ?xml version 1.0 encoding utf-8? !DOCTYPE html PUBLIC -//w3c//DTD XHTML 1.1//EN http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd html xmlns http://www.w3.org/1999/xhtml FRAMESET ROWS *,65 FRAME SRC message.htm FRAME SRC login.htm /FRAMESET 2、message.htm文件代码 htmlheadMETA HTTP-EQUIV REFRESH CONTENT 4/headbody /body/html 3、login.htm文件代码 ?xml version 1.0 encoding UTF-8? !DOCTYPE html PUBLIC -//w3c//DTD XHTML 1.1//EN http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd htmlmeta charsetutf-8 /body form action ./chatroom.pl method post输入你的名字 input type text name username input type submit value 开始聊天 input type hidden name message value connected /form/body/html 三、用perl编写cgi程序 chatroom.pl文件代码 #!/usr/bin/perl -w $buffer ; print Content-type:text/html\n\n; get_form_data; open(MESSAGE,/var/www/message.htm); lines MESSAGE; close(MESSAGE); $now_string localtime; thetime split(/ /,$now_string); print htmlmeta http-equiv\Content-Type\ content\text/html; charsetUTF-8\body\n; print form action \./chatroom.pl\ method \post\\n; print input name username type hidden value $data[1]\n; print input type text name message size 40\n; print input type submit value \发言\/form\n; if($data[3]ne) {$newmessage br$data[1]:$data[3](发送时间:$thetime[3])\n;open(NEW,/var/www/message.htm);print NEW htmlheadMETA HTTP-EQUIV \REFRESH\ CONTENT \4\/headbody\n;#print NEW encode(utf-8,decode(utf-8,$newmessage));print NEW $newmessage;$limit_lines 10;if($#lines 10){$limit_lines $#lines;}for($i 1;$i $limit_lines;$i){#print NEW encode(utf-8,decode(utf-8,$lines[$i]));print NEW $lines[$i];}print NEW /body/html;close(NEW); } print /body/html\n; exit 0; sub get_form_data {read(STDIN,$buffer,$ENV{CONTENT_LENGTH});pairs split(//,$buffer);data();foreach $pair(pairs){a split(//,$pair);$name $a[0];$value $a[1];$value ~s/%([0-9a-fA-F][0-9a-fA-F])/pack(C,hex($1))/eg;push (data,$name);push (data,$value);} } 四、移动文件 将编写好的文件chatroom.html、message.htm、login.htm和chatroom.pl统一移动到/var/www/目录下。此处可以通过配置apache自由设置目录 五、修改文件权限 还没具体尝试到最安全可靠的权限级别目前统一将html文件、perl文件、/var/www/文件夹全部修改权限为777。 指令chmod 777 /etc/www/chmod 777 /etc/www/chatroom.htmlchmod 777 /etc/www/message.htmchmod 777 /etc/www/login.htmchmod 777 /etc/www/chatroom.pl 六、配置apache使其支持perl 1、进入/etc/apache2/sites-available/目录 2、打开其中的default文件 3、修改内容最终内容如下 VirtualHost *:80ServerAdmin webmasterlocalhostDocumentRoot /var/www/Directory /Options FollowSymLinksAllowOverride NoneOrder deny,allowallow from allsatisfy all/DirectoryDirectory /var/www/Options FollowSymLinks MultiViewsAllowOverride NoneOrder deny,allowallow from all/DirectoryScriptAlias /cgi-bin/ /var/www/Directory /var/www/AllowOverride allOptions ExecCGI -MultiViews SymLinksIfOwnerMatchOrder deny,allowAllow from allAddHandler cgi-script .cgi .pl/DirectoryErrorLog ${APACHE_LOG_DIR}/error.log# Possible values include: debug, info, notice, warn, error, crit,# alert, emerg.LogLevel warnCustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ /usr/share/doc/ Directory /usr/share/doc/ Options Indexes MultiViews FollowSymLinks AllowOverride none Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 /Directory /VirtualHost 七、重新开启apache服务 指令service apache2 restart 八、在浏览器输入地址测试是否成功 http://你服务的IP地址/chatroom.html转载于:https://www.cnblogs.com/fengty90/archive/2013/05/03/3768872.html