linux操作系统基础(3)lamp架构的搭建和使用

(1)构建LAMP(LINUX + APACHE + MYSQL + PHP)网站

A安装必要的软件

1.Install SSH Client and Server (for my remote access)

sudo apt-get install ssh

2. Install Database Server(传言现在只能装5.0的版本,别的我没实践过)

sudo apt-get install mysql-server-5.0

3. Install Apache HTTP Server

sudo apt-get install apache2

4.Install PHP5 and Apache PHP5 module

sudo apt-get install php5 libapache2-mod-php5

5.Install php5-mysql

sudo apt-get install php5-mysql

6. Restart Apache

sudo /etc/init.d/apache2 restart

7. Optionally, install phpMyAdmin
sudo apt-get install phpmyadmin

使用apachectl -v可以查看安装的apache版本。

也可以使用一键安装包

sudo apt-get update; sudo apt-get install tasksel

sudo tasksel

安装后

sudo apache2 restart

可以用浏览器访问127.0.0.1验证apache安装成功。

在var/www/html中,建立test.php用于验证php安装成功,输入以下页面


    
                     phpinfo()
        ?>
    

如果没有变化,请尝试清除浏览器缓存。

参考另一篇教程中对mysql进行管理。新建php页面如下


	
		

THE PLANK HODER DURATION IN 7829

"; $str.= ""; $str.= ""; $str.= ""; $str.= ""; $str.= ""; $str.= ""; $str.= ""; echo $str; //echo "1"; } mysql_free_result($query);//free mysql memory mysql_close($dbMysql);//disconnect mysql ?>
idnamesexagebirthdaytime(s)
".$row[id]."".$row[name]."".$row[sex]."".$row[age]."".$row[birthday]."".$row[time]."
如果能正确显示,说明安装成功。


(2)实例1 处理用户登录命令

本节主要参考自http://blog.csdn.net/sysprogram/article/details/21107041

新建登录页面login.html


	login
	
		


新建登录处理页面

      login';  
        exit;  
        }  
        //登录  
        if(!isset($_POST['submit'])){  
        exit('not authorized!');  
        }  
        //$username = htmlspecialchars($_POST['username']);  
        //$password = MD5($_POST['password']);  
        $password = ($_POST['password']);  
        $username = ($_POST['username']);  
        
          
        //包含数据库连接文件  
        include('conn.php');          
        //检测用户名及密码是否正确  
        $check_query = mysql_query("select userid from userlist where username='$username' and password='$password' limit 1");  
        if($result = mysql_fetch_array($check_query)){  
        //登录成功  
        session_start();  
        $_SESSION['username'] = $username;  
        $_SESSION['userid'] = $result['userid'];  
        echo $username,' welcome! enter user center
';           echo 'click here logout login
';           exit;           } else {           exit('login failed,click here return try again');           }             ?> 

其中,conn.php文件如下:

      

my.php文件如下:

      

    //包含数据库连接文件  
    include('conn.php');  
    $userid = $_SESSION['userid'];  
    $username = $_SESSION['username'];  
    $user_query = mysql_query("select * from user_list where userid = '$userid' limit 1");  
    $row = mysql_fetch_array($user_query);  
    echo 'User Infomation:
'; echo 'User ID:',$userid,'
'; echo 'User Name:',$username,'
'; echo 'logout
'; ?>



你可能感兴趣的:(操作系统和编译器)