sdfwe 发表于 2015-11-5 08:53:03

LAMP环境的搭建

介绍

LAMP(Linux-Apache-MySQL-PHP)网站架构是目前国际流行的Web框架,该框架包括:Linux操作系统,Apache网络服务器,MySQL数据库,Perl、PHP或者Python编程语言,所有组成产品均是开源软件,是国际上成熟的架构框架,很多流行的商业应用都是采取这个架构,和Java/J2EE架构相比,LAMP具有Web资源丰富、轻量、快速开发等特点,微软的.NET架构相比,LAMP具有通用、跨平台、高性能、低价格的优势,因此LAMP无论是性能、质量还是价格都是企业搭建网站的首选平台。本文以实验情况搭下的源码搭建LAMP.

Apache: Web 服务器网页网站服务器提供静态页面

PHP :处理动态程序的, 让看页面的人可以和网站服务器进行互动

Mysql:存储大量的信息已提供给 动态程序(PHP) 才能经过判断返回给用户



实验环境: EnterpriseLinux Server release 6.5

实验机器:localhost1.cnIP:192.168.10.63

实验步骤:编译APPache----编译mysql--------编译php



    编译APPache

下载apache源码包---安装软件包---编译-------修改配置文件---测试

安装开发环境

yum installgcc-c++ openssl –ypcre-devel

上传源码包httpd-2.4.16.tar.gz,编译安装appache,需要事先源码编译安装APR等几个软件包,不然编译appache的时候会报缺少apr

源码编译安装apr-1.5.2apr-util-1.5.4pcre-8.10







源码编译apr-1.5.2

解压软件

tar -zxvfapr-1.5.2.tar.gz ;cd /root/lamp/apr-1.5.2

编译

./configure--prefix=/usr/local/apr

[root@localhost1apr-1.5.2]# make -j 4 && make install

检查是否编译完成:echo $?0 表示安装成功

spacer.gif

同样的方法编译安装apr-util-1.5.4 和 pcre-8.10

[root@localhost1apr-util-1.5.4]#./configure--prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config ; make-j 4 ; make install

[root@localhost1pcre-8.10]# ./configure --prefix=/usr/local/pcre ; make -j 4 ; make install

编译appache

[root@localhost1httpd-2.4.16]# tar zxvf httpd-2.4.16.tar.gz ; cd /root/lamp/httpd-2.4.16

./configure--prefix=/usr/local/apache2 --enable-so --enable-rewrite --enable-ssl--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

make -j 4 ; makeinstall

参数说明

--prefix=/usr/local/apache2   #指定安装路径

--enable-so# 支持动态加载模块

--enable-rewrite#支持网站地址重写

--enable-ssl# 支持ssl加密

查看编译是否成功

spacer.gif







创建软连接

# ln -s /usr/local/apache2/ /etc/apache2

#appache配置文件

# ln -s /usr/local/apache2/htdocs/ /var/www/apache2

#appache 页面路径

启动服务

cp/usr/local/apache2/bin/apachectl /etc/init.d/

# /etc/init.d/apachectl start

# netstat -anutp | grep 80

tcp      0   0 :::80                     :::*                        LISTEN      36633/httpd

加入标准服务

# chkconfig --addapachectl

apachectl 服务不支持 chkconfig   报错

编辑vim /etc/init.d/apachectl 增加以下内容

# chkconfig:2345 64 36

# 2345 系统级别下启动这个服务 ,64 启动顺序 , 36 关闭顺序

# description:Activates/Deactivates all network interfaces configured to

spacer.gif

查看服务

spacer.gif

# netstat -anutp | grep 80

tcp      0   0 :::80                      :::*                        LISTEN      36633/httpd







编译MySQL

创建运行mysql 服务的用户-安装软件包---编译-------修改配置文件---测试   

创建用户

# useradd -u 8000 -s /sbin/nologin mysql

# id mysql

uid=8000(mysql)gid=8000(mysql) 组=8000(mysql)

创建安装目录

mkdir /server



安装软件包

Mysql 5.30以上的需要cmake 编译

yum install cmake –y

tar -zxvfmysql-5.5.45.tar.gz; cd /root/lamp/mysql-5.5.45

cmake -DCMAKE_INSTALL_PREFIX=/server/mysql-5.5 \

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_EXTRA_CHARSETS=all \

-DWITH_MYISAM_STORAGE_ENGINE=1\

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DMYSQL_DATADIR=/server/mysql/data \

-DMYSQL_USER=mysql

spacer.gif





Make -j 4; makeinstall

# echo $?

0

# ls /server/

mysql-5.5

chown -Rmysql:mysql /server/mysql-5.5 配置权限

cp -vf/server/mysql-5.5/support-files/my-large.cnf   /etc/my.cnf   配置 主配置文件

cp -vf/server/mysql-5.5/support-files/mysql.server   /etc/init.d/mysqld5.5 添加启动

chmod +x/etc/init.d/mysqld5.5 可执行权限

修改配置文件

# vim /etc/init.d/mysqld5.5

增加以下内容

spacer.gif

basedir=/server/mysql-5.5运行目录

datadir=/server/mysql-5.5/data数据目录

设置开启启动

chkconfigmysqld5.5 oncd /server/mysql-5.5/scripts/

创建初始数据库

spacer.gif







执行数据库脚本

./mysql_install_db--defaults-file=/etc/my.cnf --basedir=/server/mysql-5.5--datadir=/server/mysql-5.5/data --user=mysql

查看数据库

启动数据库

# /etc/init.d/mysqld5.5 start

查看

spacer.gif





编译PHP

安装软件包—编译-测试

tar -jxvf php-5.4.45.tar.bz2; cd/root/lamp/php-5.4.45

./configure    --prefix=/server/php-5.4 --with-mysql=/server/mysql-5.5--with-apxs2=/usr/local/apache2/bin/apxs--with-config-file-path=/server/php-5.4

# make -j 4 ;make install

拷贝php的配置文件

# cp/root/lamp/php-5.4.45/php.ini-production /server/php-5.4/php.ini



要让apache 知道php的存在 并且 关联起来

修改配置文件 249行处

改DirectoryIndexindex.html

为 DirectoryIndex index.html index.php

在76行处追加

AddType application/x-compress .Z

377    AddType application/x-gzip .gz .tgz

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps



测试

# cd/usr/local/apache2/htdocs/

# ls

index.html

# mv index.htmlindex.html.bak

# ls

index.html.bak

# vim index.php

# cat index.php

<?php

phpinfo();

?>

重启appache ,测试

#/etc/init.d/apachectl restart


页: [1]
查看完整版本: LAMP环境的搭建