简单架设一个LAMP架构的基础网站


web服务器的实现,在LAMP架构下,分为三层:

    1、web服务器响应客户端请求的接入层(http)

    2、使用应用业务的应用层(PHP)

    3、后端提供数据服务的数据层(MySQL)

这三层已经能够满足基本需要了。

 

 

这三层分别使用http2.2、hph5.3和mysql5.1来实现。

 

# yum -y install httpd

# vim /etc/httpd/conf/httpd.conf

ServerName 192.168.1.33:80

# service httpd configtest

Syntax OK

# vim /var/www/html/index.html 编写后即可成为默认访问页面

<h1>/var/www/html/index.html</h1>

# chkconfig httpd on

# /etc/init.d/httpd start
Starting httpd:                                            [  OK  ]

 

实现httpd启动完成

在客户端使用IP:192.168.1.33访问,出现主页面上的内容就可以使用web网站了。

 

安装并启动hph

# yum install php

# vim /etc/httpd/conf/httpd.conf

DirectoryIndex index.php index.html index.html.var

# service httpd configtest

Syntax OK

# vim /var/www/html/index.php 

写入下面的内容

<?php

phpinfo();

?>

# /etc/init.d/httpd restart

如果在网页中使用IP地址可以访问到php返回内容,就说明可以使用php了。

 

 

安装并启动mysql

# yum install mysql mysql-server php-mysql

# /etc/init.d/mysqld start

# mysql 可以直接使用默认用户root连接进入mysql

在主页中编写如下脚本,来测试与mysql的连接性

[root@www mysql]# vim /var/www/html/index.php

<?php

  $link=mysql_connect(localhost,root,'');

  if ($link)

        echo "Sueccess...";

  else

        echo "Failure...";

?>

# /etc/init.d/httpd restart

 

客户端访问,出现Sueccess...就说明已经完成php与mysql的连接。

 

这样一个LAMP架构就简单地在一个服务器中实现了。

 

 

安装wordpress

[root@www ~]# unzip wordpress-3.1-RC1.zip 


[root@www html]# mv /root/wordpress-3.1-RC1/wordpree/* /var/www/html/

提供主配置文件

[root@www html]# cp wp-config-sample.php wp-config.php 


[root@www html]# vim wp-config.php 

// ** MySQL settings - You can get this info from your web host ** //

/** The name of the database for WordPress */

define('DB_NAME', 'wpdb'); 数据库为wpdb


/** MySQL database username */

define('DB_USER', 'root'); 用户为root


/** MySQL database password */

define('DB_PASSWORD', ''); 密码为空

 

# setenforce 0


在浏览器上就可以查看到wordpress页面

在初始化页面提供用户名密码,邮件,就可以登录了。

LAMP架构的简单实现_网站