編譯安裝lamp


 編譯安裝軟件需要安裝開發環境,關閉iptables和selinux

# yum groupinstall "Development Tools"  "Server Platform Development"


一、編譯安裝httpd

httpd2.4需要apr、apr-util依賴包

1.編譯安裝apr、apr-util

# tar xf apr-1.5.0.tar.bz2 
# cd apr-1.5.0
# ./configure --prefix=/usr/local/apr
# make && make install
# tar  xf apr-util-1.5.3.tar.bz2 
# cd apr-util-1.5.3
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install


2.編譯安裝httpd

在安裝之前需要安裝pcre-devel包,因爲在編譯安裝http時會安裝pcre,這個包依賴於pcre-devel,系統自帶沒有pcre-devel這個包

# yum install pcre-devel
# tar xf httpd-2.4.10.tar.bz2  
# cd httpd-2.4.10
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --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-modules=most --enable-mpms-shared=all --with-mpm=event
# make && make install


3.啓動httpd服務

編譯安裝的httpd自帶有啓動腳本:apachectl,所以執行/usr/local/apache/bin/apachectl命令即可啓動httpd服務

直接使用apachectl命令需做一下步驟:

# vim /etc/profile.d/httpd.sh
# .  /etc/profile.d/httpd.sh
# echo $PATH 
# cat   /etc/profile.d/httpd.sh
export PATH=/usr/local/apache/bin:$PATH


4.修改httpd的主配置文件 vim  /etc/httpd24/httpd.conf ,添加下行即可:

PidFile  "/var/run/httpd.pid"


5.將之前的httpd sysv服務腳本拷貝過來並修改配置文件中的以下數據:

cp /etc/rc.d/init.d/httpd   /etc/rc.d/init.d/httpd24
# pidfile: /var/run/httpd.pid
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
pidfile=${PIDFILE-/var/run/httpd.pid}


#!/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 /etc/rc.d/init.d/httpd24


6.加入服務列表並啓動服務:

# chkconfig --add httpd24
# chkconfig httpd24 on
# service httpd24 status
# service httpd24 start


二、編譯安裝mysql

1.新建一個lvm,然後將其掛載到數據庫目錄下:

# fdisk /dev/sda
# partx -a /dev/sda
# partx -a /dev/sda
# pvcreate /dev/sda5
# vgcreate myvg /dev/sda5
# lvcreate -L 5G -n mylv myvg
# mkfs.ext4 /dev/myvg/mylv
# mkdir -pv /mydata/data 
# mount /dev/myvg/mylv /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

# tar xf mariadb-5.5.43-linux-x86_64.tar.gz  -C /usr/local
# cd /usr/local
# ln -sv mariadb-5.5.43-linux-x86_64 mysql
# cd mysql
# chown -R root:mysql ./*
# scripts/mysql_install_db  --datadir=/mydata/data/ --user=mysql     //初始化數據庫


4.爲數據庫創建主配置文件

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


5.修改配置文件:添加如下幾行,並修改此文件中thread_concurrency的值爲你的CPU個數乘以2

datadir = /mydata/data           //數據存放目錄
innodb_file_per_table= on       //每個innnodb表使用單個表文件
skip_name_resolve = on        //跳過主機名稱解析


6.爲mysql提供sysv服務腳本,並添加至服務列表

# cp support-files/mysql.server   /etc/rc.d/init.d/mysqld
# chmod +x /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld


7.在配置文件中定義“pid-file”文件路徑,否則啓動mysql會出現錯誤

vim /etc/my.cnf 
pid-file=/mydata/data/mysql.pid
vim /etc/rc.d/init.d/mysqld
mysqld_pid_file_path=/mydata/data


8.輸出mysql的man手冊至man命令中:

# vim /etc/man.config   添加下行即可:
MANPATH  /usr/local/mysql/man


9.輸出mysql的頭文件至系統文件路徑/usr/include:

# ln -sv /usr/local/mysql/include  /usr/include/mysql


10.輸出mysql的庫文件給系統庫查找路徑:

# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf


重新加載系統庫:

# ldconfig


11.修改PATH環境變量,讓系統可以直接使用mysql的相關命令:

vim /etc/profile.d/mysqld.sh
# export PATH=/usr/local/mysql/bin:$PATH
# . /etc/profile.d/mysqld.sh 
# service mysqld start


三、編譯安裝php

1.開始安裝php所需依賴環境:

# yum -y groupinstall "Desktop Platform Development" 
# yum -y install bzip2-devel libmcrypt-devel libxml2-devel
// libmcrypt-devel  本地光盤沒有在epel源裏面。其他的是epel源.,編譯安裝libmcrypt
如何安裝epel源?
先安裝yum優先級插件:
# yum install yum-priorities
安裝epel:
# rpm -Uvh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
#rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
導入epel:
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
修改epel配置文件中epel的源級別:加入下行就OK了
priority=11  
創建緩存:
# yum makecache


 

2.編譯安裝libmcrypt

# tar xf libmcrypt-2.5.7.tar.gz  
# cd libmcrypt-2.5.7
# ./configure --prefix=/usr/local/libmcrypt
# make && make install


3.開始編譯安裝php:

# tar xf php-5.4.40.tar.bz2
# cd php-5.4.40
# ./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 --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt=/usr/local/libcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d  --with-bz2 --enable-maintainer-zts
//msqli:對應mysql另外的一個接口  ,freetype:多種字體 libxml:處理xml的文檔 socket:支持socket   apxs:支持http第三方模塊   zts:如果之前安裝過httpd且模塊是prefork則不需要,否則必須安裝上去
# make -j     //啓用多線程安裝(由於php安裝比較耗時)
# make install


默認情況下http是不支持php的,所以需要修改配置文件:

# cp  /etc/httpd24/httpd.conf /etc/httpd24/httpd.conf.bak


4.爲php提供配置文件:

# cp  php.ini-production  /etc/php.ini


確認php模塊是否加載進來:

wKioL1arM2SQLMeNAAAbxxLLN1A290.png

5.編輯apache文件使其支持php:

在文件中添加入下行:

DirectoryIndex   index.php  index.html
  
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps


6.重置下httpd服務:

# /usr/local/apache/bin/apachectl reload


7.默認測試頁面在/usr/local/apache/htdocs,添加一個index.php測試文件:

<?php
      $link = mysql_connect('127.0.0.1','root',' ');
      if ($link)
        echo "Success...";
      else
        echo "Failure...";
        phpinfo();
      mysql_close();
?>


8.測試網頁http://hostloaclIP


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