4321 发表于 2016-9-27 09:07:09

LAMP的部署

所谓LAMP就是linux、apache、mysql、php的组合,也就是把apache、mysql以及php安装在linux系统上,组成一个环境来运行php的脚本语言。

下面介绍一下他们各自有什么作用:

apache:是当今流行的web服务器,快速、可靠、可通过简单的API扩展。它主要有两个作用。


[*]解析网页语言,如php、html等。

[*]接收web用户的请求并给予用户一定的响应。


mysql:是一种开源的关系型数据库,其作用是存储网站数据,使用户在客户端实
现读写数据的操作。

php:负责处理网站中的php程序,处理完后php再把结果给到apache,由
apache响应客户端的访问。

搭建LAMP环境的步骤:


1.安装mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
cd /usr/local/src/

http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-x86_64-icc-glibc23.tar.gz    (64位源码包)

tar zxvf /usr/local/src/mysql-5.1.40-linux-x86_64-icc-glibc23.tar.gz

mv mysql-5.1.40-linux-x86_64-icc-glibc23 /usr/local/mysql

useradd -s /sbin/nologin mysql

cd /usr/local/mysql

mkdir -p /data/mysql

chown -R mysql:mysql /data/mysql

./scripts/mysql_install_db --user=mysql --datadir=/data/mysql   #数据库初始化

cp support-files/my-large.cnf   /etc/my.cnf   #拷贝配置文件

cp support-files/mysql.server   /etc/init.d/mysqld    #拷贝启动脚本

chmod 755 /etc/init.d/mysqld

vim /etc/init.d/mysqld   #修改datadir=/data/mysql

chkconfig --add mysqld

chkconfig mysqld on

service mysqld start





2. 安装apache


1
2
3
4
5
6
7
8
9
wgethttp://archive.apache.org/dist/httpd/httpd-2.2.27.tar.bz2

tar jvxf httpd-2.2.27.tar.bz2

cd httpd-2.2.27

./configure --prefix=/usr/local/apache2--enable-mods-shared=most--enable-so

make && make install





3. 安装在最后的php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
wget http://cn2.php.net/distributions/php-5.3.28.tar.gz

tar zxf php-5.3.28.tar.gz

cd php-5.3.28

./configure   --prefix=/usr/local/php   --with-apxs2=/usr/local/apache2/bin/apxs   
--with-config-file-path=/usr/local/php/etc   --with-mysql=/usr/local/mysql   
--with-libxml-dir   --with-gd   --with-jpeg-dir   --with-png-dir   --with-freetype-dir
--with-iconv-dir   --with-zlib-dir   --with-bz2   --with-openssl   --with-mcrypt   
--enable-soap   --enable-gd-native-ttf   --enable-mbstring   --enable-sockets   
--enable-exif   --disable-ipv6

make && make install




把php放在最后来编译安装的原因:在编译安装php时,有指定mysql以及apache的
路径,如果不先安装好mysql和apache就没有办法安装php。

4. 配置apache结合php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# vim /usr/local/apache2/conf/httpd.conf

找到:

   Options FollowSymLinks
   AllowOverride None
   Order deny,allow
   Deny from all

改为:

   Options FollowSymLinks
   AllowOverride None
   Order deny,allow
   Allow from all


找到:

AddType application/x-gzip .gz .tgz

在该行下面添加:

AddType application/x-httpd-php .php

找到:

   DirectoryIndex index.html

将该行改为:

   DirectoryIndex index.html index.htm index.php

找到:

#ServerName www.example.com:80

修改为:

ServerName localhost:80





5. 测试解析php



1
2
3
4
5
6
7
8
9
10
11
12
13
# vim /usr/local/apache2/htdocs/1.php

写入:

<?php

   echo "php解析正常";

?>

保存后,继续测试:

curl localhost/1.php




测试结果为:php解析正常

页: [1]
查看完整版本: LAMP的部署