編譯安裝LAMP,及配置phpmyadmin

1.安裝環境,此處使用rhel7.2,安裝httpd2.4.18,php5.6.26,mariadb使用的是之前已經編譯安裝好的mariadb。
A.編譯安裝httpd
1.解決依賴關係。httpd-2.4.18需要較新版本的apr和apr-util,因此需要事先對其進行升級。升級方式有兩種,一種是通過源代碼編譯安裝,一種是直接升級rpm包。這裏選擇使用編譯源代碼的方式進行
(1) 編譯安裝apr

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

(2) 編譯安裝apr-util

# 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

(3) httpd-2.4.18編譯過程也要依賴於pcre-devel軟件包,需要事先安裝。此軟件包系統光盤自帶,因此,使用本地yum源安裝即可。

(4)還需要安裝openssl-devel模塊,此處使用本地yum源安裝。

2.編譯安裝httpd-2.4.18

# tar xf httpd-2.4.18.tar.bz2
# cd httpd-2.4.18
# ./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的主配置文件,設置其Pid文件的路徑

編輯/etc/httpd/httpd.conf,添加如下行即可:

PidFile  "/var/run/httpd.pid"

4.提供SysV服務腳本/etc/rc.d/init.d/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/httpd24/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/httpd

加入服務列表:
# chkconfig --add httpd

配置httpd環境變量,讓系統可以調用httpd命令

echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
輸出httpd的頭文件至系統頭文件路徑
ln -sv /usr/local/apache/include /usr/include/apache
輸出httpd的庫文件給系統庫查找路徑
echo '/usr/local/apache/lib/' > /etc/ld.so.conf.d/apache.conf
重載系統庫
ldconfig
輸出httpd的man手冊到man命令的查找路徑
vim /etc/man_db.conf 
添加如下字段:
MANDATORY_MANPATH                       /usr/local/apache/man

以上httpd安裝完成了。

B.編譯安裝php5.6.26

先安裝開發包組
#yum -y groupinstall "Desktop Platform Development"
#yum -y groupinstall "Development tools"
php依賴libmcrypt 需先安裝libmcrypt-devel 在編譯安裝時啓用xml模塊需要安裝libxml2-devel
本地系統光盤有的版本不帶此rpm包,可以到aliyun鏡像上下載安裝。
解壓安裝包
#tar -xf php-5.6.26.tar.gz
#cd php-5.6.26
#./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-mysqli=mysqlnd --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  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts
說明:
1、這裏爲了支持apache的worker或event這兩個MPM,編譯時使用了--enable-maintainer-zts選項。
2、如果使用PHP5.3以上版本,爲了鏈接MySQL數據庫,可以指定mysqlnd,這樣在本機就不需要先安裝MySQL或MySQL開發包了。mysqlnd從php 5.3開始可用,可以編譯時綁定到它(而不用和具體的MySQL客戶端庫綁定形成依賴),但從PHP 5.4開始它就是默認設置了。
# ./configure --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd
# make -j 8   // 用make -j帶一個參數,可以把項目在進行並行編譯,比如在一臺雙核的機器上,完全可以用make -j4,讓make最多允許4個編譯命令同時執行,這樣可以更有效的利用CPU資源。
# make -j 8 test 
# make -j 8 install 

安裝完成,爲php提供配置文件。

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

編輯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是否已經可以正常使用。

測試頁面index.php示例如下:

   <?php
      $link = mysql_connect('10.33.133.160','sqladmin','123456');
      if ($link)
        echo "Success...";
      else
        echo "Failure...";

      mysql_close();
      phpinfo();
    ?>

以上配置就算完成。

安裝phpmyadmin方便遠程管理數據庫。
下載phpmyadmin ,此處下載的是phpMyAdmin-4.4.15.8-all-languages.tar.bz2版本。
將此文件解壓到httpd的文件目錄

# tar -xf phpMyAdmin-4.4.15.8-all-languages.tar.bz2 -C /usr/local/apache/htdocs/phpmyadmin 

打開phpmyadmin目錄,在此目錄下是否有config.sample.inc.php文件,如果存在,那麼將其改名爲config.inc.php。(根據版本不同,有可能直接就有config.inc.php文件,那就無需改名,也有可能根本就沒有config.sample.inc.php或者config.inc.php,那我們就到phpmyadmin\libraries目錄下將config.default.php複製到phpmyadmin目錄下並改名爲config.inc.php)。

#cp config.sample.inc.php config.inc.php

修改config.inc.php配置文件如下:

$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = '10.33.133.160';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
$cfg['PmaAbsoluteUri'] = 'http://sqladmin1.xiewl.com/phpmyadmin/';
$cfg['Servers'][$i]['user'] = '';
$cfg['Servers'][$i]['password'] = '';

修改完成,訪問頁面,使用在mysql上已授權的用戶登錄即可。
這裏寫圖片描述

發佈了26 篇原創文章 · 獲贊 6 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章