LAMP簡單搭建
一、編譯安裝apache
1、解決依賴關係
由於httpd-2.4.9的安裝需要較新版本的apr和apr-util這兩個包,因此需要事先對其進行升級:apr-1.5.0.tar.bz2
apr-util-1.5.3.tar.bz2
下載上述兩個個包後,對其進行升級,執行以下命令:
2、編譯安裝httpd-2.4.9
而後執行如下命令進行編譯安裝過程:
3、修改httpd的主配置文件,設置其Pid文件的存放位置
編輯/etc/httpd24/httpd.conf,添加如下行即可:
PidFile "/var/run/httpd.pid"
4、爲httpd提供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 Webserver. 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 swallowingup 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, serverbinary, 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 syntaxerror"
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}"
exit1
esac
exit $RETVAL
而後爲此腳本賦予執行權限:
# chmod +x /etc/rc.d/init.d/httpd
加入服務列表:
# chkconfig --add httpd
接下來就可以啓動服務進行測試了。
#service httpd start
在瀏覽器中輸入 172.16.249.53
apache安裝成功
二、安裝mysql-5.5.33
1、準備數據存放的文件系統
新建一個邏輯卷,並將其掛載至特定目錄即可。這裏不再給出過程。這裏假設其邏輯卷的掛載目錄爲/mysql,而後需要創建/mysql/data目錄做爲mysql數據的存放目錄。
2、新建用戶以安全方式運行進程:
# groupadd -r mysql
# useradd -g mysql -r -s /sbin/nologin -M -d/mysql/data mysql
# chown -R mysql:mysql /mysql/data
3、安裝並初始化mysql-5.5.33
選擇適應自身平臺的mysql
# tar xf mysql-5.5.33-linux2.6-i686.tar.gz-C /usr/local
# cd /usr/local/
# ln -sv mysql-5.5.33-linux2.6-i686 mysql
# cd mysql
# chown -R mysql:mysql .
# scripts/mysql_install_db --user=mysql--datadir=/mydata/data
# chown -R root .
4、爲mysql提供主配置文件:
# cd /usr/local/mysql
# cp support-files/my-large.cnf /etc/my.cnf
並修改此文件中thread_concurrency的值爲你的CPU個數乘以2,比如這裏使用如下行:
thread_concurrency = 2
另外還需要添加如下行指定mysql數據文件的存放位置:
datadir = /mysql/data
5、爲mysql提供sysv服務腳本:
# cd /usr/local/mysql
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
添加至服務列表:
# chkconfig --add mysqld
# chkconfig mysqld on
6、輸出mysql的man手冊至man命令的查找路徑:
編輯/etc/man.config,添加如下行即可:
MANPATH /usr/local/mysql/man
7、輸出mysql的頭文件至系統頭文件路徑/usr/include:
這可以通過簡單的創建鏈接實現:
# ln -sv /usr/local/mysql/include /usr/include/mysql
8、輸出mysql的庫文件給系統庫查找路徑:
# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
而後讓系統重新載入系統庫:
# ldconfig -v
9、修改PATH環境變量,讓系統可以直接使用mysql的相關命令。
在/etc/profile文件中添加以下內容:
PATH=$PATH:/usr/local/mysql/bin
10、啓動mysql
#service mysqldstart
三、編譯安裝php-5.4.26
1、解決依賴關係:
# yum -y groupinstall "Desktop PlatformDevelopment"
# yum -y install bzip2-devel libmcrypt-devel
2、編譯安裝php-5.4.26
首先下載php-5.4.26源碼包至本地目錄
# tar xf php-5.4.26.tar.bz2
# cd php-5.4.26
./configure --prefix=/usr/local/php--with-mysqlnd=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從php5.3開始可用,可以編譯時綁定到它(而不用和具體的MySQL客戶端庫綁定形成依賴),但從PHP 5.4開始它就是默認設置了。
爲php提供配置文件:
# cp php.ini-production /etc/php.ini
3、 編輯apache配置文件httpd.conf,以apache支持php
# vim /etc/httpd/httpd.conf
2、定位至DirectoryIndex index.html
修改爲:
DirectoryIndex index.php index.html
3、修改/usr/local/apache/htdocs/index.html
將其重命名爲:index.php
#mv /usr/local/apache/htdocs/index.html/usr/local/apache/htdocs/index.php
編輯/usr/local/apache/htdocs/index.php添加以下內容:
<?php
Phpinfor();
?>
保存退出
而後重新啓動httpd,或讓其重新載入配置文件即可測試php是否已經可以正常使用。
在瀏覽器中輸入172.16.249.53出現以下界面
4、驗證是否可以成功連接至mysql
編輯/usr/local/apache/htdocs/index.php,添加以下內容:
<?php
$link=mysql_connect('localhost','root','');
if ($link)
echo"Successfuly";
else
echo"Faile";
mysql_close();
?>
保存退出。
在瀏覽器中輸入 172.16.249.53,出現以下內容: