健身类行业网站

上海健身网 – www.ejianshen.com
www.jianshen021.com
军友健身网 – www.plajs.com
中国健身网 – http://www.chinajianshen.com/

.net 生成excle

Protected Sub Button_excel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_excel.Click

        Dim sql_string As String = "select * from smt_time_List where 1=1 "

        If Me.TextBox_model.Text.Trim <> "" Then
            sql_string = sql_string + " and Model = ‘" + Me.TextBox_model.Text.Trim + "’ "
        End If

        If Me.DropDownList_project.SelectedIndex > 0 Then
            sql_string = sql_string + " and Project = ‘" + Me.DropDownList_project.SelectedValue.Trim + "’ "
        End If

        If Me.TextBox_updatedate.Text.Trim <> "" Then
            sql_string = sql_string + " and Update_Date = ‘" + Me.TextBox_updatedate.Text.Trim + "’ "
        End If

        If Me.DropDownList_line.SelectedIndex > 0 Then
            sql_string = sql_string + "and Line = ‘" + Me.DropDownList_line.SelectedValue.Trim + "’ "
        End If

        If Me.DropDownList_boardsider.SelectedIndex > 0 Then
            sql_string = sql_string + " and Board_Side= ‘" + Me.DropDownList_boardsider.SelectedValue.Trim + "’ "
        End If

        If Me.DropDownList_owner.SelectedIndex > 0 Then
            sql_string = sql_string + " and Owner = ‘" + Me.DropDownList_owner.SelectedValue.Trim + "’"
        End If

        Myconnection.Open()
        Dim myds As New DataSet
        Dim myad As New SqlDataAdapter(sql_string, Myconnection)
        myad.Fill(myds)

        ‘write excel******************************************

        ‘*************************************************************
        Dim sHtml As String
        sHtml = "<table cellSpacing=’0′ borderColorDark=’#ffffff’ cellPadding=’0′ width=’100%’ border=’1′>"
        sHtml = sHtml & "<tr bgColor=’#CCFFFF’><STRONG><td colspan=’1′ >Project</td><td colspan=’1′ >BU</td><td colspan=’1′ >Model</td><td colspan=’1′ >Description</td><td colspan=’1′ >Rev</td><td colspan=’1′ >Board_Side</td><td colspan=’1′ >Line</td><td colspan=’1′ >Quotation_Time</td><td colspan=’1′ >Standard_time</td><td colspan=’1′ >Update_Date</td><td colspan=’1′ >Owner</td></STRONG></tr>"
        For i As Integer = 0 To myds.Tables(0).Rows.Count – 1
            sHtml = sHtml & "<tr><STRONG><td >" & myds.Tables(0).Rows(i).Item("Project").ToString & "</td><td>" & myds.Tables(0).Rows(i).Item("BU").ToString & "</td><td>" & myds.Tables(0).Rows(i).Item("Model").ToString & "</td><td>" & myds.Tables(0).Rows(i).Item("Description").ToString & "</td><td>" & myds.Tables(0).Rows(i).Item("Rev").ToString & "</td><td>" & myds.Tables(0).Rows(i).Item("Board_Side").ToString & "</td><td >" & myds.Tables(0).Rows(i).Item("Line").ToString & "</td><td >" & myds.Tables(0).Rows(i).Item("Quotation_Time").ToString & "</td><td >" & myds.Tables(0).Rows(i).Item("Standard_time").ToString & "</td><td >" & myds.Tables(0).Rows(i).Item("Update_Date").ToString & "</td><td >" & myds.Tables(0).Rows(i).Item("Owner").ToString & "</td></STRONG></tr>"
        Next
        sHtml = sHtml & "</table>"
        Dim urlstr As String

        urlstr = MapPath(Request.ApplicationPath) + "xlssmt_std_report.xls"

 

        Dim fileWrite As StreamWriter = New StreamWriter(urlstr, False, Encoding.Default)     ‘Encoding.UTF8)
        fileWrite.Write(sHtml)
        fileWrite.Close()
        fileWrite.Dispose()
        Response.Write("<script>window.open(‘" + Request.ApplicationPath + "/xls/smt_std_report.xls" + "’);</script>")

    End Sub

聊天机器人

前一段时间,突发奇想,开发了一个聊天机器人,本来是想做helpdesk的一个平台。support部门的人先教它,然后有问题的人可以像它请教。

教的越多它越聪明。

但是公司一直没有机器来放,只好自己搞着玩一玩。

作为公司用,只有出现解决方案才有作用。也就是当你问它比较专业的问题时,它会告诉你如何解决,解决方案1,2,3并且要出现图解的内容。所以,最好查找到相应的内容,机器人给你一个网页地址,上面包含你要查找的内容。

好了,不多说了,把开发步骤介绍一下。

(一)分析流程,需求,建立数据库。

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sogo_link]’) AND type in (N’U’))
BEGIN
CREATE TABLE [dbo].[sogo_link](
 [id] [int] IDENTITY(1,1) NOT NULL,
 [sogo_link_url] [nvarchar](100) NULL,
 [sogo_link_font] [nvarchar](100) NULL,
 [sogo_link_login] [nvarchar](100) NULL,
 [sogo_link_alt] [nvarchar](100) NULL,
 [sogo_link_logo_or_txt] [int] NULL,
 [sogo_link_yes_no] [int] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[robot]’) AND type in (N’U’))
BEGIN
CREATE TABLE [dbo].[robot](
 [ID] [int] IDENTITY(1,1) NOT NULL,
 [title] [nvarchar](50) NULL,
 [robot_content] [nvarchar](4000) NULL,
 [BigClassName] [nvarchar](50) NULL,
 [SmallClassName] [nvarchar](50) NULL,
 [kin_demo] [nvarchar](4000) NULL,
 [picUrl] [nvarchar](255) NULL,
 [imagenum] [int] NULL,
 [firstImageName] [nvarchar](50) NULL,
 [robot_user] [nvarchar](50) NULL,
 [infotime] [datetime] NULL CONSTRAINT [DF_robot_infotime]  DEFAULT (getdate()),
 [hits] [int] NULL,
 [ok] [bit] NULL,
 [tuijian] [bit] NULL,
 [web_yes_no] [bit] NOT NULL,
 CONSTRAINT [PK_robot] PRIMARY KEY CLUSTERED
(
 [ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Admin]’) AND type in (N’U’))
BEGIN
CREATE TABLE [dbo].[Admin](
 [ID] [int] IDENTITY(1,1) NOT NULL,
 [admin] [nvarchar](50) NULL,
 [password] [nvarchar](50) NULL,
 [aleave] [nvarchar](50) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[bigClass]’) AND type in (N’U’))
BEGIN
CREATE TABLE [dbo].[bigClass](
 [BigClassID] [int] NOT NULL,
 [BigClassName] [nvarchar](50) NULL,
 [Admin] [nvarchar](100) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[shop_pinglun]’) AND type in (N’U’))
BEGIN
CREATE TABLE [dbo].[shop_pinglun](
 [pinglunid] [int] NOT NULL,
 [ID] [int] NULL,
 [pinglunname] [nvarchar](50) NULL,
 [pinglundate] [datetime] NULL,
 [pingluncontent] [nvarchar](max) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SmallClass]’) AND type in (N’U’))
BEGIN
CREATE TABLE [dbo].[SmallClass](
 [SmallClassID] [int] NOT NULL,
 [SmallClassName] [nvarchar](50) NULL,
 [BigClassName] [nvarchar](50) NULL,
 [Admin] [nvarchar](100) NULL
) ON [PRIMARY]
END

(二)建立解决方案网页。

(三)建立web版机器人

(四)申请小I机器人,下载原程序进行修改。

using System;
using System.IO;
using System.Drawing;
using System.Configuration;
using System.Runtime.Serialization;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
using System.Xml.Serialization;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;

using Incesoft.BotPlatform.SDK;
using Incesoft.BotPlatform.SDK.Interface;

namespace BotPlatformConsoleServer
{
 public class MyRobot
 {
  public string address;

  public int port;

  public string user;

  public string password;

  static void Main(string[] args)
  {
   MyRobot me = new MyRobot();
   me.address = "msnbot.incesoft.com";
   me.port = 6602;
   me.user = "SP092231";
   me.password = "******";
   
   IRobotServer server = RobotServerFactory.Instance.createRobotServer(me.address, me.port);
   server.addRobotHandler(new MyHandler(server));
   server.addConnectionListener(new MyListener());
   try
   {
    server.login(me.user, me.password, 300000);
    server.requestContactList(haigangdeng@126.com);
   }
   catch (RobotException e)  
   {
    Console.Out.WriteLine("Failed to connect :" + e.Message);
   }
  }
 }

 class MyHandler : IRobotHandler
 {
  public MyHandler(IRobotServer server)
  {
   this.server = server;
  }
  private IRobotServer server;
  private Random rdm = new Random();

        public System.String commandList =  "Hi,你好,我是helpdesk小M。r" +
                                                            "如果你有************问题,可以问我。r" +
                                                            "也许我能帮你解答。";

  public System.String commandListEnt = "*****************************************r" +
                  "**  BOTPLATFORM SDK ENTERPRISE ONLY COMMAND LIST  **r" +
                  "**  Only use the following commands after upgraded your sp account  **r" +
                  "
*****************************************r" +
                  " file —— test file transfer.r" +
                  " bg ——– test background sharing.r" +
                  " ink ——- test send ink.r" +
                  " wink —— test send wink.r" +
                  " voice —– test send voiceclip.r" +
                  " webcam —- test send webcamr" +
                  " cs <account> ——– test create session.r" +
                  " pu <account> —— test push offline message.r" +
                  " iv <account> ——– test invite user.r" +
                  " ent ——— print this command list.";
 
  public virtual void  sessionOpened(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: sessionOpened");
   try
   {
    switch(session.OpenMode)
    {
     case SessionOpenMode.OPEN_MODE_CONV_OPEN:
      session.send(commandList);
      break;
     case SessionOpenMode.OPEN_MODE_ROBOT:
      session.send("You have an alert message: blablabla");
      break;
     default:
      break;
    }
   }
   catch (RobotException e)
   {
    util.consoleOut(e.ToString());
   }
  }
  
  
  public virtual void  sessionClosed(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: sessionClosed");
  }
  
  public virtual void  messageReceived(IRobotSession session, IRobotMessage message)
  {
   System.Console.Out.WriteLine("EVENT: messageReceived");
   
   try
   {
    System.String command = message.String;
    
    IRobotMessage msg = session.createMessage();

                if ("+".ToString().Equals(command[0].ToString()))
                {
                    if (command.IndexOf(‘|’) < 0)
                    {
                        session.send("问题和答案要用“|”分开吆");
                    }
                    else
                    {
                        string wenti = command.Substring(1, (command.IndexOf(‘|’) – 1));
                        string daan = command.Substring(command.IndexOf(‘|’) + 1);

                        string connectionstrings = "server=IP*****;UID=robot;PWD=******;DataBase=robot";
                        SqlConnection connection = new SqlConnection(connectionstrings);
                        string sqlxuexi = "insert into robot (title,robot_content,web_yes_no) values (" + "’" + wenti + "’," + "’" + daan + "’," + 0 + ")";
                        SqlCommand commxuexi = new SqlCommand(sqlxuexi,connection);
                        connection.Open();
                        commxuexi.ExecuteNonQuery();
                        connection.Close();

                        session.send("嗯,我记住了,谢谢你。");
                    }
                }

                else if ("help".ToUpper().Equals(command.ToUpper()) || "?".ToUpper().Equals(command.ToUpper()))
                {
                    session.send(commandList);
                }
                else if ("nudge".ToUpper().Equals(command.ToUpper()))
                {
                    session.sendNudge();
                }
    else if ("bye".ToUpper().Equals(command.ToUpper()))
    {
     session.cl
ose();
    }    
    else
                {
                    string connectionstrings = "server=IP******;UID=robot;PWD=******;DataBase=robot";
                    SqlConnection connection = new SqlConnection(connectionstrings);
                    string sqlcontent = "select * from robot where title like" + "’%" + command.ToString() + "%’";
                    SqlDataAdapter myad = new SqlDataAdapter(sqlcontent, connection);
                    connection.Open();

                    DataSet myds = new DataSet();
                    myad.Fill(myds,"robot");

                    if (myds.Tables["robot"].Rows.Count > 0)
                    {
                        int i = 0;
                        while (i < myds.Tables["robot"].Rows.Count)
                        {
                            int f = i + 1;
                            if (myds.Tables["robot"].Rows[i]["web_yes_no"].GetHashCode() == 0)
                            {
                                session.send(myds.Tables["robot"].Rows[i]["robot_content"].ToString());
                            }
                            else
                            {
                                session.send("解决方案(" + f +")n" + "http://www.xxxxx.com/robot/onews.asp?id=" + myds.Tables["robot"].Rows[i]["ID"].ToString());
                            }
                            i = i + 1;
                        }
                    }
                    else
                    {
                        session.send("对不起,我还不知道这个问题的答案,如果你知道你能告诉我吗?用“+问题|答案”的方式告诉我,我就能记住了。");
                    }
                    connection.Close();
                }
   }
   catch (RobotException e)
   {
    util.consoleOut(e.ToString());
   }   
  }
  
  public virtual void  nudgeReceived(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: nudgeReceived");
  }
  
  
  public virtual void  activityAccepted(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: activityAccepted");
  }
  
  
  public virtual void  activityRejected(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: activityRejected");
  }

  public virtual void userAdd(String robot, String user)
  {
   System.Console.Out.WriteLine("EVENT: userAdd");
  }
  
  public virtual void userRemove(String robot, String user)
  {
   System.Console.Out.WriteLine("EVENT: userRemove");
  }
  
  public virtual void  exceptionCaught(IRobotSession session, System.Exception cause)
  {
   System.Console.Out.WriteLine("SERVER ERROR: " + cause.Message);
  }

  public virtual void  activityClosed(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: activityClosed");
  }
  public virtual void  fileAccepted(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: fileAccepted");
  }
  
  public virtual void  fileRejected(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: fileRejected");
  }
  
  public virtual void  fileTransferEnded(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: fileTransferEnded");
  }
  
  public virtu
al void  backgroundAccepted(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: backgroundAccepted");
  }
  
  public virtual void  backgroundRejected(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: backgroundRejected");
  }
  
  public virtual void  backgroundTransferEnded(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: backgroundTransferEnded");
  }
  
  public virtual void  webcamAccepted(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: webcamAccepted");
  }
  
  public virtual void  webcamRejected(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: webcamRejected");
  }
    
  public virtual void  activityLoaded(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: activityLoaded");
  }

  public virtual void  activityReceived(IRobotSession session, System.String data)
  {
   System.Console.Out.WriteLine("EVENT: activityReceived:" + data);
  }

  public virtual void  userJoined(IRobotSession session, IRobotUser user)
  {
   System.Console.Out.WriteLine("EVENT: userJoined : " + user);
  }

  public virtual void  userLeft(IRobotSession session, IRobotUser user)
  {
   System.Console.Out.WriteLine("EVENT: userLeft :" + user);
  }
  
  public virtual void  userUpdated(IRobotUser user)
  {
   System.Console.Out.WriteLine("EVENT: userUpdated (" + user.ID +","+user.Status+","+user.FriendlyName+ ")");
  }
  
  public virtual void  personalMessageUpdated(System.String robot, System.String user, System.String personalMessage)
  {
   System.Console.Out.WriteLine("EVENT: personalMessageUpdated (" + robot + ", " + user + ", " + personalMessage + ")");
  }   
  public virtual void contactListReceived(System.String robot, System.Collections.ArrayList contactList)
  {
   System.Console.Out.WriteLine("EVENT: contactListRecieved ");
   for (int i=0; i<contactList.Count; i++)
   {
    IRobotUser user = (IRobotUser)contactList[i];
    System.Console.Out.WriteLine("User "+i+": "+user.ID);
   }
  } 
  
 }
 class MyListener : IRobotConnectionListener
 {
  public void serverConnected(IRobotServer server)
  {
   Console.Out.WriteLine("Server connected.");
  }

  public void serverReconnected(IRobotServer server)
  {
   Console.Out.WriteLine("Server reconnected.");
  }

  public void serverDisconnected(IRobotServer server)
  {
   Console.Out.WriteLine("Server disconnected.");
  }

  public void serverLoggedIn(IRobotServer sever)
  {
   Console.Out.WriteLine("Server logged in.");
  }
 }
}

.net发送mail方法

字体变小 字体变大

Method 1
——————————————————————————————————
// using System.Net.Mail;
Mailmessageage message = new Mailmessageage();
message.From = new MailAddress("User@gmail.com", "Your DisplayName");
message.To.Add(new MailAddress("To@gmail.com")); // the email you want to send email to
message.Subject = "A test email"

message.IsBodyHtml = true;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Body = "this is just a simple test!<br> Jack"
message.Priority = MailPriority.High;

SmtpClient client = new SmtpClient("smtp.gmail.com", 587); // 587;//Gmail使用的端口
client.Credentials = new System.Net.NetworkCredential("User@gmail.com", "*****"); // Your user name & password
client.EnableSsl = true; //经过ssl加密
object userState = message;
try
{
client.Send(message);
Response.Write("邮件发送到" + message.To.ToString() + "<br>");
}
catch (Exception ee)
{
Response.Write(ee.messageage + "<br>" + ee.InnerException.messageage);
}

Method 2
——————————————————————————————————

// using System.Net.Mail;
MailMessage message = new MailMessage();
message.From = new MailAddress("User@gmail.com");

message.To.Add(new MailAddress("to@gmail.com"));

message.Subject = "This is my subject"
message.Body = "This is the content"
SmtpClient client = new SmtpClient();
client.EnableSsl = true;

try
{
client.Send(message);
Response.Write("邮件发送到" + message.To.ToString() + "<br>");
}
catch (Exception ee)
{
Response.Write(ee.Message );
}

//In web.config

<system.net>
<mailSettings>
<smtp from="from@gmail.com">
<network host="smtp.gmail.com" port="587" userName="User@gmail.com" password="your pwd" />
<!– if has ‘defaultCredentials="true"’ , using Gmail can not send success –>
</smtp>
</mailSettings>
</system.net>

全程指导Linux 下PHP环境配置 LAMP

1 PHP 4.4.4
安装环境:Red Hat Linux
注意事项:安装LINUX的时候,不要安装系统自带的apache(在Linux下名为httpd),也不要安装mysql;
所需软件

  • php-4.4.4.tar.gz
  • mysql-standard-5.0.27-linux-i686-glibc23.tar.gz
  • phpMyAdmin-2.8.2.4.tar.gz
  • gd-2.0.33.tar.gz
  • httpd-2.0.59.tar.gz  即(Apache2)
  • ZendOptimizer-3.0.0-linux-glibc21-i386.tar.gz

安装路径:/usr/local;
安装步骤:
1.1 安装mysql
(1)首先得看下载下来的mysql是二进制的还是源代码的。由于  mysql-standard-5.0.27-glibc23.tar.gz是二进制的,所以不用进行.configure的配置,直接解压文件,把解压出来的文件名改名为mysql,放置到想安装的路径位置去。我的位置是 /usr/local/mysql;
(2)建立一个mysql组和一个mysql用户来访问mysql;
[root@Linux root]# cd /usr/local/mysql       #进入mysql文件夹
[root@Linux mysql]# groupadd mysql        #建立组
[root@Linux mysql]# useradd mysql -g mysql  #建立用户
(3)建立用户之后就初始化表
[root@Linux mysql]# ./scripts/mysql_install_db–-user=mysql
(4)设置权限
[root@Linux mysql]# chown -R root .  #设定root能访问/usr/local/mysql,注意后面有个点
[root@Linux mysql]# chown -R mysql data   #设定mysql用户能访问/usr/local/mysql/data, 里面存放的是数据库文件
[root@Linux mysql]# chgrp -R mysql .  #设定mysql用户组能访问/usr/local/mysql,注意后面有一个点
(5)配置完成之后,运行 mysql
[root@Linux mysql]#/usr/local/mysql/bin/safe_mysqld–user=mysql &
如果没有问题的话,应该会出现类似的提示:
[1] 一个数字
#Starting mysqld daemon with databases from /usr/local/mysql/data
恭喜,这就证明你的mysql已经安装成功了。
(6)修改root密码.默认安装密码为空.为了安全必须马上修改。
[root@Linux mysql]# /usr/local/mysql/bin/mysqladmin -uroot password 123456
现在修改的密码为:123456
(7)设置开机自动启动
[root@Linux mysql]# cp support-files/mysql.server /etc/init.d/
OK,MySql已经安装成功。
(8)进入mysql
[root@Linux mysql]# /usr/local/mysql/bin/mysql -u root -p
Enter password:输入你的密码。
可以见到以下提示:
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 1 to server version: 5.0.27-standard-log
Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.
mysql>
(9)退出mysql
mysql> quit;
1.2 安装apache2 (即httpd)
(1)解开压缩文件httpd-2.0.59.tar.gz
(2)进入解开的文件httpd-2.0.59中:
[root@Linux root]# cd /你的存放该文件的路径/httpd-2.0.59
(3)在/usr/local 新建一个文件夹apache2 ,到时候就是安装在这里.
(4)开始配置Apache
[root@Linux httpd-2.0.59]# ./configure(空格)
–prefix=/usr/local/apache2 (空格)
–enable-module=so(空格)
–enable-rewrite=shared(空格)
–enable-speling=shared(回车)
  (注:–prefix=/usr/local/apache2 为安装的路径)
(5)配置完成,开始编译:
[root@Linux httpd-2.0.59]# make
    编译会需要一定的时间.
(6)安装
[root@Linux httpd-2.0.59]# make install
(7)让apache2随系统启动
找到 /etc/rc.local 文件,打开,在最下面输入以下一行:
/bin/sh -c ‘/usr/local/apache2/bin/apachectl start’
保存并退出。
(8)打开/usr/local/apache2/conf/下的httpd.conf,进行配置。找到#ServerName 127.0.0.1:80 去掉前面的#号,保存并退出。
(9)启动apache
[root@Linux root]# /usr/local/apache2/bin/apachectl start
(10)现在应该可以通过127.0.0.1来访问了,如果见到了apache 的有关说明,恭喜,apache已经安装成功了。      
1.3 安装GD库
解开压缩之后,进行配置:./configure –prefix=/usr/local/gd2
然后进行make ,再make install就可以安装成功了。
1.4 安装php
(1)在/usr/local/新建一个目录php
(2)解开压缩文件,然后进入解开的目录
[root@Linux root]# cd /你存放的路径/php-4.4.4
(3)进行配置
[root@Linux php-4.4.4]# ./configure(空格)
–prefix=/usr/local/php(空格)
–enable-mbstring=LANG(空格)
–with-mysql=/usr/local/mysql(空格)
–with-gd=/usr/local/gd2(空格)
–with-apxs2=/usr/local/apache2/bin/apxs(回车)
如果上面的配置没有错的话.那么最后应该会显示感谢使用PHP等字样,证明配置成功。如果上面的配置选项不支持,会提示错误。
(4)进行编译
[root@Linux php-4.4.4]# make
  编译成功之后会出现”Build complete”字样,就可以进行安装了。
(5)进行安装
[root@Linux php-4.4.4]# make install
(6)安装完成后,把php.ini-dist 复制到/usr/local/php/lib/,并重命名为php.ini
(7)打开/usr/local/apache2/conf/下的httpd.conf,进行配置。
找到ServerName 127.0.0.1:80
在下面加入一句:AddType application/x-httpd-php .php .php4
找到DirectoryIndex index.html index.html.var
改为DirectoryIndex index.php index.html index.html.var
保存退出。
(8)重新启动apache
   如果apache 正在运行,则
[root@Linux root]# /usr/local/apache2/bin/apachectl stop
[root@Linux root]# /usr/local/apache2/bin/apachectl start
   如果apache没有运行,则
[root@Linux root]# /usr/local/apache2/bin/apachectl start
(9)现在apache可以运行php文件了。进行测试,在/usr/local/apache2/htdocs目录下 ,建立一个phpinfo.php文件,代码如下:
<? phpinfo(); ?>
保存文件,在浏览器输入http://127.0.0.1/phpinfo.php,如果可以见到php的系统信息,恭喜,php安装成功。
1.5 安装phpMyAdmin
(1)解开压缩文件
把解开的文件重命名为phpMyAdmin,并放到/usr/local/apache2/htdocs 下。
(2)打开phpMyAdmin,找到 libraries,打开,对config.default.php 进行编辑。
[root@Linux root]#vi/usr/local/apache2/htdocs/phpMyAdmin/libraries/config.default.php
找到:$cfg[‘Servers’][$i][‘auth_type’]    = ‘config’;  
     $cfg[‘Servers’][$i][‘user’]          = ‘root’;     
     $cfg[‘Servers’][$i][‘password’]      = ”;           
改为:$cfg[‘Servers’][$i][‘auth_type’]    = ‘http’;   
     $cfg[‘Servers’][$i][‘user’]          = ‘root’;    
     $cfg[‘Servers’][$i][‘password’]      = ‘Mysql密码’;
保存退出。
(3)通过 http://127.0.0.1/phpMyAdmin/进行访问。
由于有设置密码,而且是用 http方式,会出现登录框.输入用户名root, 密码为mysql设置的密码。成功进入phpMyAdmin 。恭喜,phpMyadmin 安装成功。
1.6 安装ZendOptimizer
(1)解开压缩包
(2)进入解开后的目录
(3)#./install.sh
(4)问Confirm the location of your php.ini file的时候输入/usr/local/php/lib 也就是你的php.ini的路径,问Are you using Apache web server 的时候选YES。
(5)其他均为默认
(6)安装完毕之后会提示重启Apache,重启之后,在浏览页输入我们测试 php的那个页面phpinfo.php,应该可以在下面看到Zend的版本说明,OK,安装成功。
另:

Mysql忘记管理员密码的解决方法
如果Mysql忘记了管理员的密码.那么,我们首先应该停止mysql的所有进程,然后,进入mysql目录.找到data文件夹,进入,找到mysql文件夹,把其删除.。然后再:
重新初始化表。
[root@Linux mysql]# ./scripts/mysql_install_db–user=mysql
设置权限
[root@Linux mysql]# chown -R root .  
[root@Linux mysql]# chown -R mysql data
[root@Linux mysql]# chgrp -R mysql .
运行 mysql
[root@Linux mysql]#/usr/local/mysql/bin/safe_mysqld–user=mysql &
这样就OK了.
强制卸载rpm安装
rpm –e -–nodeps 安装包名
2 PHP 5.1.2
安装环境:Red Hat Linux
所需软件:

  • php-5.1.2.tar.gz
  • mysql-standard-5.0.27-linux-i686-glibc23.tar.gz
  • PhpMyAdmin-2.8.2.4.tar.gz
  • Gd-2.0.33.tar.gz
  • httpd-2.0.59.tar.gz  即(Apache2)
  • libxml2-2.6.23.tar.bz2

说明:安装步骤与上面的基本一致,由于软件版本不同,在某些操作上会有不同的地方。
安装路径依然是/usr/local/
2.1 安装MySql
(1)首先得看下载下来的mysql是二进制的还是源代码的。由于  mysql-standard-5.0.27-glibc23.tar.gz是二进制的,所以不用进行.configure的配置,直接解压文件,把解压出来的文件名改名为mysql,放置到想安装的路径位置去。我的位置是 /usr/local/mysql;
(2)建立一个mysql组和一个mysql用户来访问mysql;
[root@Linux root]# cd /usr/local/mysql       #进入mysql文件夹
[root@Linux mysql]# groupadd mysql        #建立组
[root@Linux mysql]# useradd mysql -g mysql  #建立用户
(3)建立用户之后就初始化表
[root@Linux mysql]# ./scripts/mysql_install_db–-user=mysql
(4)设置权限
[root@Linux mysql]# chown -R root .  #设定root能访问/usr/local/mysql,注意后面有个点
[root@Linux mysql]# chown -R mysql data   #设定mysql用户能访问/usr/local/mysql/data, 里面存放的是数据库文件
[root@Linux mysql]# chgrp -R mysql .     #设定mysql用户组能访问/usr/local/mysql,注意后面有个点
(5)配置完成之后,运行mysql
[root@Linux mysql]#/usr/local/mysql/bin/safe_mysqld–user=mysql &
如果没有问题的话,应该会出现类似下面的提示:
[1] 一个数字
#Starting mysqld daemon with databases from /usr/local/mysql/data
   恭喜,这就证明你的mysql已经安装成功了。
(6)修改root密码.默认安装密码为空,为了安全必须马上修改。
[root@Linux mysql]# /usr/local/mysql/bin/mysqladmin -uroot password 123456
现在修改的密码为:123456
(7)设置开机自动启动
[root@Linux mysql]# cp support-files/mysql.server /etc/init.d/
    OK,MySql已经安装成功。
(8)进入mysql
[root@Linux mysql]# /usr/local/mysql/bin/mysql -u root -p
Enter password:输入你的密码。
可以见到以下提示:
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 1 to server version: 5.0.27-standard-log
Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.
mysql>
(9)退出mysql
mysql> quit;
注意:按照上面的安装方法,每次系统启动之后,mysql都没法随系统启动,得手工启动。不过没关系,修改/ect/rc.local,在后面加上一句:
/usr/local/mysql/bin/safe_mysqld &
保存退出就OK了。
2.2 安装Apache2
(1)解开压缩文件httpd-2.0.59.tar.gz
(2)进入解开的文件httpd-2.0.59中:
  [root@Linux root]# cd /你的存放该文件的路径/httpd-2.0.59
(3)在/usr/local 新建一个文件夹apache2 ,到时候就是安装在这里.
(4)开始配置Apache
[root@Linux httpd-2.0.59]# ./configure(空格)
–prefix=/usr/local/apache2 (空格)
–enable-module=so(空格)
–enable-rewrite=shared(空格)
–enable-speling=shared(回车)
(注:–prefix=/usr/local/apache2 为安装的路径)
(5)配置完成,开始编译:
[root@Linux httpd-2.0.59]# make
    编译会需要一定的时间.
(6)安装
[root@Linux httpd-2.0.59]# make install
(7)让apache2随系统启动
找到 /etc/rc.local 文件,打开.在最下面输入以下一行:
/bin/sh -c ‘/usr/local/apache2/bin/apachectl start’
保存并退出.
(8)打开/usr/local/apache2/conf/下的httpd.conf进行配置
找到#ServerName 127.0.0.1:80 去掉前面的#号,保存并退出。
(9)启动apache
[root
@Linux root]# /usr/local/apache2/bin/apachectl start
(10)安装之后,运行http://127.0.0.1,页面提示相当简单,只是:It works!
2.3 安装libxml2
(1)由于php.5.1.2需要libxml2-2.6以上版本,所以必须把系统自带的1.X版本卸载掉。
[root@Linux root]#rpm –e -–nodeps xml2
(2)安装libxml2-2.6.23 安装在/usr/local/libxml2
(3)把libxml2/bin里的xml2.config 复制到/usr/bin里去。如提示已有存在,则覆盖掉!
2.4 安装GD
解开压缩之后,进行配置:./configure –prefix=/usr/local/gd2
然后进行make ,再make install就可以安装成功了。
2.5 安装Php
(1)在/usr/local/新建一个目录php
(2)解开压缩文件,然后进入解开的目录
   [root@Linux root]# cd /你存放的路径/php-4.4.4
(3)进行安装配置
[root@Linux php-4.4.4]# ./configure(空格)
–prefix=/usr/local/php(空格)
–enable-mbstring=LANG(空格)
–with-mysql=/usr/local/mysql(空格)
–with-gd=/usr/local/gd2(空格)
–with-apxs2=/usr/local/apache2/bin/apxs(回车)
如果上面的配置没有错的话,那么最后应该会显示感谢使用PHP等字样,证明配置成功。如果上面的配置选项不支持,会提示错误。
(4)进行编译
[root@Linux php-4.4.4]# make
编译成功之后会出现”Build complete”字样,就可以进行安装了。
(5)进行安装
[root@Linux php-4.4.4]# make install
(6)安装完成后,把php.ini-dist 复制到/usr/local/php/lib/,并重命名为php.ini
(7)打开/usr/local/apache2/conf/下的httpd.conf,进行配置。
找到AddType application/x-gzip .gz .tgz
在下面加入2行:
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
查找LoadModule,可以找到有一句:
LoadModule php5_module modules/libphp5.so
如果没有,在LoadModule那里自己补上。
找到DirectoryIndex index.html改为DirectoryIndex index.php index.html
保存退出。
(8)重新启动apache
   如果apache 正在运行,则
[root@Linux root]# /usr/local/apache2/bin/apachectl stop
[root@Linux root]# /usr/local/apache2/bin/apachectl start
   如果apache没有运行,则
[root@Linux root]# /usr/local/apache2/bin/apachectl start
(9)现在apache可以运行php文件了。进行测试,在/usr/local/apache2/htdocs目录下,建立一个phpinfo.php文件,代码如下:
<? phpinfo(); ?>
保存文件,在浏览器输入http://127.0.0.1/phpinfo.php,如果可以见到php的系统信息,恭喜,php安装成功。
2.6 安装PhpMyAdmin
(1)解开压缩文件
把解开的文件重命名为phpMyAdmin,并放到/usr/local/apache2/htdocs 下。
(2)打开phpMyAdmin,找到 libraries,打开,对config.default.php 进行编辑。
[root@Linux root]#vi/usr/local/apache2/htdocs/phpMyAdmin/libraries/config.default.php
找到:$cfg[‘Servers’][$i][‘auth_type’]    = ‘config’;  
     $cfg[‘Servers’][$i][‘user’]          = ‘root’;     
     $cfg[‘Servers’][$i][‘password’]      = ”;           
改为:$cfg[‘Servers’][$i][‘auth_type’]    = ‘http’;   
     $cfg[‘Servers’][$i][‘user’]          = ‘root’;    
     $cfg[‘Servers’][$i][‘password’]      = ‘Mysql密码’;
保存退出。
(3)通过 http://127.0.0.1/phpMyAdmin/进行访问。
由于有设置密码,而且是用 http方式,会出现登录框.输入用户名root, 密码为mysql设置的密码。成功进入phpMyAdmin 。恭喜,phpMyadmin 安装成功。
另:

时差修改

如果出现的时间和实际时间相差8小时,则必须修改php.ini:
[Date]; Defines the default timezone used by the date functions date.timezone = PRC
(PRC义为:中华人民共和国)