lenga 发表于 2013-4-18 08:48:44

LAMP的创建--linux+apache+mysql+php

编译配置LAMP:
       Linux, Apache, MySQL, PHP(Python, Perl)
其大概步骤大致可以分为
       httpd --> MySQL --> Php
所以稍微理清了下思绪,我们开始来进行试验!
前提:
因为要用到yum安装,所以请事先确保好yum的配置是否已经妥当。可参照http://407711169.blog./6616996/1179601中前几步介绍的步骤。以及事先准备好相应的软件包,:httpd-2.4.3.tar + mysql-5.5.28 + php-5.4.8 apr-util-1.4.1.tar,apr-1.4.6.tar 。
另外需要查看selinux是否开启。同样可参照上边博客中的方法来实现关闭selinux

[*]# getenforce
[*]Enforcing   
[*]# setenforce 0   
[*]# getenforce
[*]Permissive   
[*]//当然。这里也需要到vim /etc/selinux/config将其中的SELINUX=enforcing替换为SELINUX=permissive

一、编译安装apache
注意:事先把httpd-2.4.3.tar,apr-util-1.4.1.tar,apr-1.4.6.tar 这三个包放到/usr/local/src/目录中,方法具体不在介绍xshell与window界面拖拽。另外需要注意的是,要将虚拟机里linux的时间做同步。--hwclock -s
1、解决依赖关系
(1) 编译安装apr

[*]# ls
[*]apr-1.4.6.tar.bz2 apr-util-1.4.1.tar.bz2 httpd-2.4.3.tar.bz2
[*]# tar xf apr-1.4.6.tar.bz2   
[*]# cd apr-1.4.6
[*]# ./configure --prefix=/usr/local/apr // prefix指定路径
[*] # make && make install //这里稍微简略了下步骤
[*]//这个时候,apr已经安装好了 。然后去安装apr-util
(2) 编译安装apr-util

[*]# cd ..
[*]# tar xf apr-util-1.4.1.tar.bz2   
[*]# cd apr-util-1.4.1
[*]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr //-with-apr告诉其apr的路径
[*]# make
[*]# make install
[*](3) httpd-2.4.3编译过程也要依赖于pcre-devel软件包,需要事先安装。此软件包系统光盘自带,因此,找到并安装即可。
[*]# cd ..
[*]# yum install pcre-devel

2、编译安装httpd-2.4.3

[*]# tar xf httpd-2.4.3.tar.bz2   
[*]# cd httpd-2.4.3
[*]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-mpms-shared=all --with-mpm=event   //mpm=even默认使用event
[*]# make
[*]# make install
补充:

(1)构建MPM为静态模块
在全部平台中,MPM都可以构建为静态模块。在构建时选择一种MPM,链接到服务器中。如果要改变MPM,必须重新构建。为了使用指定的MPM,请在执行configure脚本 时,使用参数 --with-mpm=NAME。NAME是指定的MPM名称。编译完成后,可以使用 ./httpd -l 来确定选择的MPM。 此命令会列出编译到服务器程序中的所有模块,包括 MPM。

(2)构建 MPM 为动态模块

在Unix或类似平台中,MPM可以构建为动态模块,与其它动态模块一样在运行时加载。 构建 MPM 为动态模块允许通过修改LoadModule指令内容来改变MPM,而不用重新构建服务器程序。在执行configure脚本时,使用--enable-mpms-shared选项即可启用此特性。当给出的参数为all时,所有此平台支持的MPM模块都会被安装。还可以在参数中给出模块列表。默认MPM,可以自动选择或者在执行configure脚本时通过--with-mpm选项来指定,然后出现在生成的服务器配置文件中。编辑LoadModule指令内容可以选择不同的MPM。

3、修改httpd的主配置文件,设置其Pid文件的路径

[*]# vim /etc/httpd/httpd.conf
[*]//添加如下内容
[*]PidFile "/var/run/httpd.pid"
4、提供SysV服务脚本/etc/rc.d/init.d/httpd,内容如下:

[*]# cd /etc/rc.d/init.d/
[*]# vim httpd
[*]//添加如下内容
[*]#!/bin/bash
[*]#
[*]# httpd      Startup script for the Apache HTTP Server
[*]#
[*]# chkconfig: - 85 15
[*]# description: Apache is a World Wide Web server. It is used to serve \
[*]#            HTML files and CGI.
[*]# processname: httpd
[*]# config: /etc/httpd/conf/httpd.conf
[*]# config: /etc/sysconfig/httpd
[*]# pidfile: /var/run/httpd.pid
[*]   
[*]# Source function library.
[*]. /etc/rc.d/init.d/functions
[*]   
[*]if [ -f /etc/sysconfig/httpd ]; then
[*]      . /etc/sysconfig/httpd
[*]fi
[*]   
[*]# Start httpd in the C locale by default.
[*]HTTPD_LANG=${HTTPD_LANG-"C"}
[*]   
[*]# This will prevent initlog from swallowing up a pass-phrase prompt if
[*]# mod_ssl needs a pass-phrase from the user.
[*]INITLOG_ARGS=""
[*]   
[*]# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
[*]# with the thread-based "worker" MPM; BE WARNED that some modules may not
[*]# work correctly with a thread-based MPM; notably PHP will refuse to start.
[*]   
[*]# Path to the apachectl script, server binary, and short-form for messages.
[*]apachectl=/usr/local/apache/bin/apachectl
[*]httpd=${HTTPD-/usr/local/apache/bin/httpd}
[*]prog=httpd
[*]pidfile=${PIDFILE-/var/run/httpd.pid}
[*]lockfile=${LOCKFILE-/var/lock/subsys/httpd}
[*]RETVAL=0
[*]   
[*]start() {
[*]      echo -n $"Starting $prog: "
[*]      LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
[*]      RETVAL=$?
[*]      echo
[*]      [ $RETVAL = 0 ] && touch ${lockfile}
[*]      return $RETVAL
[*]}
[*]   
[*]stop() {
[*]       echo -n $"Stopping $prog: "
[*]       killproc -p ${pidfile} -d 10 $httpd
[*]       RETVAL=$?
[*]       echo
[*]       [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
[*]}
[*]reload() {
[*]    echo -n $"Reloading $prog: "
[*]    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
[*]      RETVAL=$?
[*]      echo $"not reloading due to configuration syntax error"
[*]      failure $"not reloading $httpd due to configuration syntax error"
[*]    else
[*]      killproc -p ${pidfile} $httpd -HUP
[*]      RETVAL=$?
[*]    fi
[*]    echo
[*]}
[*]   
[*]# See how we were called.
[*]case "$1" in
[*] start)
[*]       start
[*]       ;;
[*] stop)
[*]       stop
[*]       ;;
[*] status)
[*]      status -p ${pidfile} $httpd
[*]       RETVAL=$?
[*]       ;;
[*] restart)
[*]       stop
[*]       start
[*]       ;;
[*] condrestart)
[*]       if [ -f ${pidfile} ] ; then
[*]            stop
[*]            start
[*]       fi
[*]       ;;
[*] reload)
[*]      reload
[*]       ;;
[*] graceful|help|configtest|fullstatus)
[*]       $apachectl $@
[*]       RETVAL=$?
[*]       ;;
[*] *)
[*]       echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
[*]       exit 1
[*]esac
[*]   
[*]exit $RETVAL
[*]   
[*]    //而后为此脚本赋予执行权限:
[*]# chmod +x httpd
[*]# chkconfig --level 35 httpd on //设定运行级别
[*]# chkconfig --list httpd
[*]httpd             0:off       1:off       2:off       3:on 4:off       5:on 6:off
[*]//下面的步骤可忽略,这里只是可以设置为bash可以直接执行
[*]# vim /etv/profile.d/httpd.sh
[*]# export PATH=$PATH:/usr/local/apache/bin
[*]   


二、安装mysql-5.5.28
前提:这里使用mysql-5.5.28-linux2.6-tar,提前下载放入linux中
1、准备数据存放的文件系统
新建一个逻辑卷,这里假设其逻辑卷的挂载目录为/mydata,而后需要创建/mydata/data目录做为mysql数据的存放目录。

[*]# fdisk /dev/sda
[*]//其中过程省略。。
[*]# partprobe /dev/sda
[*]//创建逻辑卷
[*]# pvcreate /dev/sda5   
[*] Writing physical volume data to disk "/dev/sda5"
[*] Physical volume "/dev/sda5" successfully created
[*]# vgcreate myvg /dev/sda5
[*] Volume group "myvg" successfully created
[*]# lvcreate -n mydata -L 5G myvg
[*] Logical volume "mydata" created
[*]# lvs
[*] LV   VG   Attr   LSize Origin Snap% Move Log Copy% Convert
[*] mydata myvg   -wi-a- 5.00G                                       
[*] lvtext vgtext -wi-a- 1.00G                                       
[*] home   vol0   -wi-ao 4.88G                                       
[*] root   vol0   -wi-ao 29.28G                                       
[*]# mke2fs -j /dev/myvg/mydata
[*]//设置开机挂载
[*]# mkdir /mydata
[*]# vim /etc/fstab
[*]//添加如下内容
[*]/dev/myvg/mydata      /mydata               ext3    defaults      0 0
[*]# mount –a //重新挂载
[*]# mkdir /mydata/data //作为数据的挂载目录
2、新建用户以安全方式运行进程:

[*]//创建用户
[*]# groupadd -r mysql
[*]# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
[*]# chown -R mysql:mysql /mydata/data
[*]   
3、安装并初始化mysql-5.5.28

[*]# cd /usr/local/src/
[*]# tar xf mysql-5.5.28-linux2.6-i686.tar.gz
[*]# cd ..
[*]# pwd
[*]/usr/local
[*]# ln -sv /usr/local/src/mysql-5.5.28-linux2.6-i686 mysql
[*]create symbolic link `mysql' to `/usr/local/src/mysql-5.5.28-linux2.6-i686'   
[*]# cd mysql
[*]# chown -R mysql:mysql *
[*]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data
[*]Installing MySQL system tables...
[*]#
4、为mysql提供主配置文件:

[*]# cp support-files/my-large.cnf /etc/my.cnf
[*]# vim /etc/my.cnf
[*]//并修改此文件中thread_concurrency的值为你的CPU个数乘以2,比如这里使用如下行:
[*]thread_concurrency = 2
[*]   
[*]//另外还需要添加如下行指定mysql数据文件的存放位置:
[*]datadir = /mydata/data   //添加此行指定mysql数据文件的存放位置

   5、为mysql提供sysv服务脚本:

[*]# pwd
[*]/usr/local/mysql
[*]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[*]# chmod +x /etc/rc.d/init.d/mysqld
[*]//添加至服务列表:
[*]# chkconfig --add mysqld
[*]# chkconfig mysqld on
[*]而后就可以启动服务测试使用了。


为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:
6、输出mysql的man手册至man命令的查找路径:

[*]# vim /etc/man.config
[*]#####################mysql#############
[*]MANPATH /usr/local/mysql/man

7、输出mysql的头文件至系统头文件路径/usr/include:
这可以通过简单的创建链接实现:

[*]# ln -sv /usr/local/mysql/include /usr/include/mysql
[*]create symbolic link `/usr/include/mysql' to `/usr/local/mysql/include'
8、输出mysql的库文件给系统库查找路径:

[*]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
9、修改PATH环境变量,让系统可以直接使用mysql的相关命令。

[*]# vim /etc/profile //需要重读或重启或重新登录
[*]PATH=$PATH:/usr/local/mysql/bin
[*]//另外export PATH=$PATH:/usr/local/mysql/bin 也可以起到上边的效果
[*]   
[*]PS:这个时候。就可以进入数据库创建表之类的东西了!


三、编译安装php-5.4.8
1、解决依赖关系:

[*]       请配置好yum源(可以是本地系统光盘)后执行如下命令:
[*]       # yum -y groupinstall "X Software Development"
[*]如果想让编译的php支持mcrypt扩展,此处还需要下载如下两个rpm包并安装之:
[*]libmcrypt-2.5.7-5.el5.i386.rpm
[*]libmcrypt-devel-2.5.7-5.el5.i386.rpm
[*]mhash-0.9.2-6.el5.i386
[*]mhash-devel-0.9.2-6.el5.i386
[*]   

2、编译安装php-5.4.8
将下载好的安装包放到linux的src中(过程同上)

[*]# tar xf php-5.4.8.tar.bz2
[*]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml--enable-sockets --enable-fpm --with-mcrypt--with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2
[*]# make
[*]# make test
[*]# make install
[*]为php提供配置文件:
[*]# cp php.ini-production /etc/php.ini

3、 编辑apache配置文件httpd.conf,以apache支持php

[*]# vim /etc/httpd/httpd.conf
[*]1、添加如下二行
[*]AddType application/x-httpd-php .php
[*]AddType application/x-httpd-php-source .phps
[*]
[*]2、定位至DirectoryIndex index.html   
[*]修改为:
[*]   DirectoryIndex index.php index.html
[*]后重新启动httpd,或让其重新载入配置文件即可测试php是否已经可以正常使用。

fish3129 发表于 2013-4-18 08:49:29

学习了,谢谢分享、、、

小雪崩 发表于 2013-5-18 03:48:46

爱护环境,人人有病。

wuaji 发表于 2013-5-19 15:59:41

男人靠的住,母猪能上树!

obeckham 发表于 2013-5-20 23:17:56

饭在锅里,我在床上*^_^*

cjcmay 发表于 2013-5-22 06:38:55

我是来刷分的,嘿嘿
页: [1]
查看完整版本: LAMP的创建--linux+apache+mysql+php