Ubuntu下用apache+perl搭建最简单的聊天室

最近学习了下perl,尝试自己搭建一个聊天室,现已搭建成功,但设计方法很简陋,误见笑,收获在于对apache、html、perl都有了些许认识,后面打算学习LAMP(Linux+Apache+MySQL+PHP)搭建一个在线听歌网页。


操作系统: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文件代码:


<html><head><META HTTP-EQUIV = "REFRESH" CONTENT = "4"></head><body>
</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">
<html><meta charset="utf-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 "<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-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 "<html><head><META HTTP-EQUIV = \"REFRESH\" CONTENT = \"4\"></head><body>\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.html
chmod 777 /etc/www/message.htm
chmod 777 /etc/www/login.htm
chmod 777 /etc/www/chatroom.pl


六、配置apache,使其支持perl
1、进入/etc/apache2/sites-available/目录
2、打开其中的default文件
3、修改内容,最终内容如下:
<VirtualHost *:80>
ServerAdmin webmaster@localhost


DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
allow from all
satisfy all
</Directory>
<Directory /var/www/>
Options FollowSymLinks MultiViews
AllowOverride None
Order deny,allow
allow from all
</Directory>


ScriptAlias /cgi-bin/ /var/www/
<Directory "/var/www/">
AllowOverride all
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order deny,allow
Allow from all
AddHandler cgi-script .cgi .pl
</Directory>


ErrorLog ${APACHE_LOG_DIR}/error.log


# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn


CustomLog ${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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/423951.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

闲聊型对话系统之NLG总结报告

文章目录1 项目介绍1.1 背景知识介绍1.2 NLG的实现方式1.2.1 基于模板1.2.2 检索式1.2.3 生成式1.3 数据集介绍2 技术方案梳理2.1 模型介绍2.2 评价指标2.3 模型实现2.3.1 数据处理2.3.2 构建dataset2.3.3 模型定义2.3.4 训练相关参数2.3.5 训练结果1 项目介绍 1.1 背景知识介…

spring mvc学习(50):java.lang.ClassNotFoundException: org.springframework.web.servlet. DispatcherSe

今天朋友发了个maven项目给我看&#xff0c;问我为什么启动不了。说实话&#xff0c;一直用Jfinal都快不会用spring了… 还是决定看看。 接收了文件&#xff0c;是maven构建的&#xff0c;打开eclipse&#xff0c;导入maven项目&#xff0c;然后部署到tomcat&#xff0c;启动t…

Luogu2439 [SDOI2005]阶梯教室设备利用 (动态规划)

同上一题&#xff0c;区间改左闭右开就双倍经验了。貌似可以跑最长路。 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define R(a,b,c) for(register int a (b); a < (c); a) #defi…

Python是如何进行内存管理的

从三个方面来说,一对象的引用计数机制,二垃圾回收机制,三内存池机制 一、对象的引用计数机制 Python内部使用引用计数&#xff0c;来保持追踪内存中的对象&#xff0c;所有对象都有引用计数。 引用计数增加的情况&#xff1a; 1&#xff0c;一个对象分配一个新名称 2&#xf…

spring mvc学习(51):jsonp

引入jar包 pom.xml <project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">…

抓狂

每次要给财务提交timecard报表&#xff0c; 就会遇到那些乱七八糟的事情&#xff0c; 浪费时间而无意义&#xff0c; 几个小时之后&#xff0c;我真的都想杀人&#xff0c; 在杀人与不杀之间徘徊良久&#xff0c;终于忍住&#xff0c; 那些PM根本就不负起自己的责任&#xff0c…

什么是word2vector

原文地址&#xff1a;https://www.julyedu.com/questions/interview-detail?quesId2761&cateNLP&kp_id30 什么是 Word2vec? 在聊 Word2vec 之前&#xff0c;先聊聊 NLP (自然语言处理)。NLP 里面&#xff0c;最细粒度的是 词语&#xff0c;词语组成句子&#xff0c…

spring mvc学习(52):json数据类型提交

引入jar包 pom.xml <project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">…

关注:Eclipse,转贴eclipse CDT的开发文章

致谢&#xff1a;Tinyfool的鼎立相助&#xff01; cdt是在eclipse中编写C程序的插件&#xff0c;虽然还不是很完美&#xff0c;但是是在windows中编写linux下C程序&#xff08;GNU C&#xff09;的一个好途径。按照eclipse的官方网站的要求&#xff0c;要下载如下的东东…

[译作]Class in Jscript Part I

【原文地址】 Classes in Jscript - Part I 【原文发表日期】 Monday, September 24, 2007 9:23 AM by don.raman 我是Ritesh Parikh&#xff0c;最近刚转入Jscript Team作一名SDET&#xff08;译注&#xff1a;我也不知道SDET是什么样的岗位:(&#xff09;。我刚接触Jscript…

第三课 SVM(2)

1 线性可分的数据集 1.1 超平面 SVM的思想是找到最大间隔的分隔超平面。 在两个分类中&#xff0c;找到能够一条线&#xff0c;以最好地区分这两个分类。这样如果有了新的点&#xff0c;这条线也能很好地做出分类。 这样的线在高维样本中的时候就叫做超平面。 1.2 几何间隔与…

musql-mmm

http://mysql-mmm.org/转载于:https://www.cnblogs.com/fanweixiao/archive/2010/11/05/1870267.html

《C Traps and Pitfalls》 笔记

这本书短短的100多页&#xff0c;很象是一篇文章。但是指出的很多问题的确容易出现在笔试的改错题中--------------------------------------------------------------------第1章 词法陷阱1.1 和 1.3 词法分析的"贪心法则"编译器从左到右读入字符&#xff0c;每个符…

spring mvc学习(53):回顾和springmvc返回值类型总结

媒体类型 MIME媒体类型&#xff08;简称MIME类型&#xff09;是描述报文实体主体内容的一些标准化名称&#xff08;比如&#xff0c;text/html、image/jpeg&#xff09;。 因特网有数千种不同的数据类型&#xff0c;HTTP仔细地给每种要通过web传输的对象都打上了名为MIME类型的…

2019hdu多校1

1009 考虑贪心&#xff0c;暴力枚举一位。 $o(676n)$ #include<bits/stdc.h> using namespace std; const int N1e5333; int n,m,zl; int pos[26],cnt[N],t[26],az[N]; char s[N],st[N]; int l[N],r[N],nx[N],zzq[26]; int main(){ios::sync_with_stdio(0);//freopen(&qu…

关于梅花雪的js树

最近一段时间&#xff0c;为了学习java&#xff0c;天天在看别人的框架&#xff0c;为了实现一颗树&#xff0c;找到了一个改写梅花雪的js&#xff0c;下面是一个基本的结构<% page language"java" import"java.util.*" pageEncoding"GBK"%&g…

总和最大区间问题

题目和解题思路来源于吴军著作《计算之魂》。本题目是例题1.3。 文章目录1 问题描述2 解题思路2.1 三重循环2.2 两重循环2.3 分治法2.4 正反两遍扫描的方法2.5 再进一步&#xff0c;假设失效3 应用动态规划1 问题描述 总和最大区间问题&#xff1a;给定一个实数序列&#xff0…

spring mvc学习(54):简单异常处理

引入jar包 pom.xml <project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">…

【原】docker部署单节点consul

docker下部署单节点的consul&#xff0c;最重要的是在run consul时&#xff0c;配置-bootstrap-expect1 docker run --name consul1 -d -p 5902:8500 -p 8300:8300 -p 8301:8301 -p 8302:8302 -p 8600:8600 10.109.30.246:5901/daily_docker/consul:1.4.5 agent -server -boots…

learning to rank评价指标

文章目录1 准确率Mean average precision1.1 定义1.2 计算2 NDCG(Normalized Discounted Cumulative Gain)2.1定义2.2 例子1 准确率Mean average precision 1.1 定义 Precision at position k (Pk)是一个衡量排名前k位的方法&#xff0c;使用两个级别(相关的和不相关)的相关性…