LAMP的創建過程

LAMP的製作

一、LAMP的簡單介紹

LAMPLinux + Apache+ MySQL + PHP的合併之後的簡稱。

二、安裝前的準備工作

需要安裝一些開發包組

  # yum groupinstall "Development Tools" "Development Libraries"

  # yum install gcc openssl-devel pcre-devel zlib-devel

三、開始安裝LNMP

(1)先安裝Apache

httpd-2.4.1需要較新版本的aprapr-util,因此需要事先對其進行升級。升級方式有兩種,一種是通過源代碼編譯安裝,一種是直接升級rpm包。這裏選擇使用後一種方式進行。共需要如下4個軟件包:

apr-1.4.6-1.i386.rpm

apr-devel-1.4.6-1.i386.rpm

apr-util-1.4.1-1.i386.rpm

apr-util-devel-1.4.1-1.i386.rpm

  # rpm -Uvh apr-1.4.6-1.i386.rpm apr-devel-1.4.6-1.i386.rpm

  # rpm -Uvh apr-util-1.4.1-1.i386.rpm apr-util-devel-1.4.1-1.i386.rpm

從網上下載httpd-2.4.1.tar.bz2然後執行下面的命令

  # tar xf httpd-2.4.1.tar.bz2

  # cd httpd-2.4.1

  # ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib

  # make

  # make install

編寫apache的腳本執行文件

  # vim /etc/rc.d/init.d/apache 其腳本內容如下

#!/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  

  #vim /etc/httpd/httpd.conf 修改httpd的主配置文件,設置其Pid文件的路徑

PidFile  "/var/run/httpd.pid"

  # chmod +x /etc/rc.d/init.d/httpd 給文件執行權限

  # chkconfig --add  httpd        添加到開機啓動列表        

  # chkconfig  httpd on          讓其在指定的級別打開

  # service httpd  start             開啓其服務 

(2)安裝mysql

在我們實際的工作中,由於數據庫的文件會不斷的變大,所以我們要把mysql建在一個LVM上,所以我們要準備以下工作

在磁盤上新建一個分區,並將類型改爲8e

  # partprobe /dev/sda                    同步一下

  # pvcreate /dev/sda5                    創建PV

  # vgcreate myvg /dev/sda5               創建VG

  # lvcreate -L 2G -n mydata -p rw myvg     創建LV

  # mke2fs -j /dev/myvg/mydata            LV進行格式化

  # vim /etc/fstab                        編寫配置文件讓其開機自起

/dev/myvg/mydata        /mydata                 ext3    defaults        0 0

  # mkdir /mydata                       創建目錄mydata

  # mount -a                            將其掛載上

  # mount                              查看是否掛載上

/dev/mapper/myvg-mydata on /mydata type ext3 (rw)

mysql添加用戶和組

  # groupadd -r mysql

  # useradd -g mysql -r -s /sbin/nologin -M mysql

下載mysql的安裝文件mysql-5.5.20-linux2.6-i686.tar.gz ,然後執行下面的命令

  # tar xf mysql-5.5.20-linux2.6-i686.tar.gz -C /usr/local/

  # cd /usr/local/ 

  # ln -sv mysql-5.5.20-linux2.6-i686 mysql          創建鏈接用着方便

  # chown -R mysql:mysql /mydata/data/

  # chown -R mysql:mysql mysql/*

  # scripts/mysql_install_db --user=mysql --datadir=/mydata/data

  # chown -R root . 

mysql提供配置文件

  # cp /usr/local/mysql/support-files/my-large.cnf  /etc/my.cnf

  # vim /etc/my.cnf

將此文件中thread_concurrency的值爲你的CPU個數乘以2,比如這裏使用如下行:

thread_concurrency = 2

另外還需要添加如下行指定mysql數據文件的存放位置:

datadir = /mydata/data

mysql提供服務腳本

  # cp /usr/local/mysql/support-files/mysql.server  /etc/rc.d/init.d/mysqld

  # chkconfig --add mysqld

  # chkconfig mysqld on

  # service mysqld start

Starting MySQL                                            [  OK  ] 說明啓動成功

  # ln -sv /usr/local/mysql/include /usr/include/mysql 創建鏈接使輸出mysql的頭文件至系統頭文件路徑/usr/include

  # echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf 給系統庫輸出mysql的庫文件查找路徑

  # vim /etc/man.config 在其添加如下一行使可以使用man命令查找mysql

 MANPATH  /usr/local/mysql/man

  # vim /etc/profile 修改環境變量,添加如下一行

PATH=$PATH:/usr/local/mysql/bin

這樣mysql就創建成功了

(3)安裝php

如果想讓編譯的php支持mcrypt擴展,此處還需要下載這幾個rpm包並安裝之:

libmcrypt-2.5.8-4.el5.centos.i386.rpm

libmcrypt-devel-2.5.8-4.el5.centos.i386.rpm

由於rpm包只有這幾個,所有可以執行下面的命令進行升級

  # rpm -Uvh *.rpm --nodeps

下載php-5.3.6.tar.bz2然後進行安裝

  # tar xf php-5.3.6.tar.bz2

  # cd php-5.3.6

  #./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  --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt

  # make

  # make install

  # cp php.ini-production /etc/php/php.ini php提供配置文件

 

(4)apachephp進行整合

  # 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

# cat > /www/htdocs/index.php << EOF  創建測試頁面

<?php

phpinfo();

?>

而後重新啓動httpd,或讓其重新載入配置文件即可測試php是否已經可以正常使用。

 

(5)安裝phpMyAdmin

在網上下載並安裝,執行下面的命令

# tar xf phpMyAdmin-3.4.10.1-all-languages.tar

# mkdir /www/htdocs/pma

# mv phpMyAdmin-3.4.10.1-all-languages /www/htdocs/pma

然後在瀏覽器中輸入www.feng.com/pma 即可進入數據庫了

 

記得在你自己的的主機的瀏覽器中,要使檢查能夠成功,需要在hosts文件中,將你的虛擬機的IP和網址寫在裏面。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章