您好,登錄后才能下訂單哦!
介紹LAMP
LAMP(Linux-Apache-MySQL-PHP)網(wǎng)站架構(gòu)是目前國(guó)際流行的Web框架,該框架包括:Linux操作系統(tǒng),Apache網(wǎng)絡(luò)服務(wù)器,MySQL數(shù)據(jù)庫(kù),Perl、PHP或者Python編程語(yǔ)言,所有組成產(chǎn)品均是開(kāi)源軟件,是國(guó)際上成熟的架構(gòu)框架,很多流行的商業(yè)應(yīng)用都是采取這個(gè)架構(gòu),和Java/J2EE架構(gòu)相比,LAMP具有Web資源豐富、輕量、快速開(kāi)發(fā)等特點(diǎn),微軟的.NET架構(gòu)相比,LAMP具有通用、跨平臺(tái)、高性能、低價(jià)格的優(yōu)勢(shì),因此LAMP無(wú)論是性能、質(zhì)量還是價(jià)格都是企業(yè)搭建網(wǎng)站的首選平臺(tái)。
首先,安裝順序?yàn)閍pache--->mysql--->php
環(huán)境:RHEL5.8 I386
Development Libraries
Development Tools
軟件包: httpd: 2.4.4
php: 5.4.13
MySQL: 5.6.10 通用二進(jìn)制包
準(zhǔn)備:
確保你的系統(tǒng)沒(méi)有安裝lamp環(huán)境,如mysql,httpd,php
安裝
apache2.4的安裝
由于apache2.4需要apr,apr-utils較新版本,這里我們使用源碼包編譯安裝
apr-1.4.6.tar.gz
apr-util-1.4.1.tar.gz
tar xf apr-util-1.4.1.tar.gz &&tar xf apr-1.4.6.tar.gz
cd apr-1.4.6
./configure --prefix=/usr/local/apr
make &&make install
cd ../apr-util-1.4.1
./cofigure --prefix=/usr/local/apr-utils --with-apr=/usr/local/apr
make &&make install
tar xf httpd-2.4.4.tar.bz2
cd httpd-2.4.4
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewirte --enable-ssl --enable-cgi --enable-cgid --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
make &&make install
為了方便以后使用,制做sysV風(fēng)格服務(wù)啟動(dòng)腳本:
一般情況,如果是手動(dòng)編譯的話(huà),apache是沒(méi)有啟動(dòng)腳本的,也就是說(shuō)用戶(hù)不能通過(guò)簡(jiǎn)單的/etc/init.d/httpd(start|stop|restart)來(lái)啟動(dòng)/關(guān)閉/重新啟動(dòng)。其實(shí)在源碼里已經(jīng)有啟動(dòng)的腳本,我們要修改下即可,把Apache加入系統(tǒng)SysV服務(wù)中來(lái)。
在源碼httpd-2.x.x/build/rpm中存在httpd.init拷貝命令如下:
cp httpd.init/etc/init.d/httpd
拷貝之后,注意其中有三處主要的地方需要修改下的:
httpd=${HTTPD-/usr/local/apache/bin/httpd}
pidfile=${PIDFILE-/usr/local/apache/logs/${prog}.pid}
CONFFILE=/usr/local/apache/conf/httpd.conf
請(qǐng)根據(jù)自己的實(shí)際情況更改相應(yīng)的路徑!
然后運(yùn)行如下命令:
chmod +x/etc/init.d/httpd
chkconfig--add httpd
chkconfig --level2345 httpd on
這樣一來(lái),啟動(dòng)、停止、重啟Apache就可以用以下方式了:
/etc/init.d/httpdstart
/etc/init.d/httpdstop
/etc/init.d/httpdrestart
輸出PATH變量
vim /etc/profile.d/httpd.sh
export PATH=$PATH:/usr/local/apache/bin
安裝mysql
tar xvf mysql-5.5.28-linux2.6-i686.tar.gz
mv mysql-5.5.28-linux2.6-i686 /usr/local
ln -s mysql-5.5.28-linux2.6-i686 /usr/local/mysql
注:以上是官方要求的
useradd -r mysql
cp support-files/my-large.cnf /etc/my.cnf
chown -R mysql:mysql .
scripts/mysql_install_db --user=mysql
注:如果你的data不打算放在默認(rèn)的文件系統(tǒng)上,也可以加上--datadir=/data/db
如果你修改了默認(rèn)目錄,需要修改/etc/my.cnf文件
在【mysqld】 項(xiàng)下增加
datadir = /data/db
chown -R root:mysql .
chown -R mysql:mysql /data/db
chmod -R 750 .
cp support-files/mysql.server /etc/init.d/mysqld
mysql命令工具
vim /etc/profile.d/mysqld.sh
export PATH=$PATH:/usr/local/mysql/bin
man手冊(cè)設(shè)置
vim /etc/man.config
新增一行:
MANPATH /usr/local/mysql/man
lib庫(kù)文件設(shè)置
vim /etc/ld.so.conf.d/mysql.conf
新增一行:
/usr/local/mysql/lib
重新加載系統(tǒng)庫(kù)文件
lddconfig -v
include頭文件設(shè)置
ln -s /usr/local/mysql/include /usr/include/mysql
安裝php
tar xvf php-5.4.13.tar.bz2
cd php-5.4.13
./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 --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
此處安裝會(huì)報(bào)錯(cuò):
configure: error: mcrypt.h not found.Please reinstall libmcrypt.
我們需要安裝加密庫(kù)需要的軟件包:
rpm -ivh mhash-devel-0.9.2-6.el5.i386.rpm mhash-0.9.2-6.el5.i386.rpm libmcrypt-devel-2.5.7-5.el5.i386.rpm libmcrypt-2.5.7-5.el5.i386.rpm
make &&make install
此時(shí),php安裝完畢
整合
要使得apache與php能工作,還需要為httpd做相應(yīng)設(shè)置
vim /etc/httpd/httpd.conf
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.html index.php
重啟或啟動(dòng)httpd服務(wù)
測(cè)試服務(wù)是否都正常
vim /usr/local/apache/htdocs/index.php
<?php
$conn=mysql_connect('localhost','root','');
if($conn)
echo "OK";
else
echo "Error";
?>
<?php
phpinfo();
?>
安裝xcache2.0.0
tar xvf xcache-3.0.4.tar.gz
cd xcache-3.0.4
ls
cat INSTALL
/usr/local/php/bin/phpize
./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
make &&make install
mkdir /etc/php.d
cp xcache.ini /etc/php.d/
vim /etc/php.d/xcache.ini
zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
;zend_extension_ts = c:/php/extensions/php_xcache.dll
上面路徑是在安裝完php后的最后一條提示
回到主頁(yè),可以看到xcache己加載進(jìn)來(lái)了
其它解說(shuō):
對(duì)于源碼安裝的apache如果我們需要使用虛擬主機(jī),需要修改/etc/httpd/httpd.conf
啟用Include /etc/httpd/extra/httpd-vhosts.conf,然后在/etc/httpd/extra/httpd-vhosts.conf中設(shè)置虛擬主機(jī)
在設(shè)置ACL時(shí),需與apache2.2區(qū)別開(kāi)來(lái),它們的區(qū)別比較多
如果需要啟用ssl,也要啟用相應(yīng)的模塊
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
在這里我們需要弄清LAMP工作機(jī)制:
在apache需要解析PHP腳本時(shí)才會(huì)用到PHP解析器,PHP與apahe有多種工作機(jī)制
1、Modules方式,也就是本文的配置過(guò)程
2、fastCGI(在PHP中也稱(chēng)FPM)
3、還有Apache的CGI
這里就不講這些機(jī)制的具體配置,以后有時(shí)間再編了,但是大多數(shù)生產(chǎn)環(huán)境用到的都是三層結(jié)構(gòu),也就是使用的是fastCGI模式。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。