lamp = centos6.8 + httpd2.4.29 +
安裝順序:httpd, MariaDB, php
httpd+php的模式:
modules: 把php編譯成httpd的DSO對(duì)象;
prefork: libphp5
event, worker: libphp5-zts
--enable-maintainer-zts
cgi:
fpm(fastcgi):php作為獨(dú)立的服務(wù)
httpd對(duì)fastcgi協(xié)議的支持:
httpd-2.2: 需要額外安裝fcgi模塊;
httpd-2.4: 自帶fcgi模塊;
第一步編譯安裝httpd2.4
- 編譯安裝依賴解決:
yum groupinstall "development tools" -y
yum install pcre-devel -y
yum install openssl-devel -y
yum install expat-devel -y
以上為編譯安裝時(shí)必備的依賴庫 - 解決httpd依賴apr(Apache portable Run-time libraries,Apache可移植運(yùn)行庫)以及編譯安裝httpd
使用如下命令獲取官網(wǎng)信息:
yum info httpd
yum info apr
下面附上官網(wǎng)地址:
httpd官網(wǎng):http://httpd.apache.org/
apr官網(wǎng):http://apr.apache.org/
下載后放置到文件夾:

建立好相應(yīng)的目錄夾,放好從官網(wǎng)下載的壓縮包。以下為httpd編譯安裝命令集合:
建立目錄和放置壓縮包過程省略;
cd /usr/local/lamp/httpd/source
ls |xargs -i tar xf {} #全部解壓縮
./configure --prefix=/usr/local/lamp/httpd/apr
make && make install #編譯安裝apr
./configure --prefix=/usr/local/lamp/httpd/apr-util --with-apr=/usr/local/lamp/httpd/apr
make && make install #編譯安裝apr-util
#編譯安裝apr-iconv(可選)
./configure --prefix=/usr/local/lamp/httpd/apr-iconv --with-apr=/usr/local/lamp/httpd/apr
make && make install
#編譯安裝httpd
./configure --prefix=/usr/local/lamp/httpd/httpd --sysconf=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/lamp/httpd/apr --with-apr-util=/usr/local/lamp/httpd/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
- 完成以上操作以及結(jié)束httpd的編譯安裝,接下來修改一些環(huán)境變量和啟動(dòng)腳本
將原本系統(tǒng)自帶的http啟動(dòng)腳本cp成httpd24版本,并且需要修改某些變量
cd /etc/init.d/
cp httpd httpd24

修改上述截圖中的路徑為自己編譯安裝時(shí)的路徑即可,然后可以通過chkconfig --add http24加入到開機(jī)自啟,自己選擇是否需要在相應(yīng)級(jí)別啟動(dòng)。
注意:
- 如果之前使用過系統(tǒng)自帶的httpd命令,需要執(zhí)行hash -r來清理掉shell的命令查詢緩存。
- pidfile編譯安裝之后默認(rèn)是放在/path/to/httpd/logs中,所以這個(gè)配置需要和httpd主配置文件中的Pidfile對(duì)應(yīng)起來
啟動(dòng)腳本添加完成后需要添加環(huán)境變量:
vim /etc/profile.d/httpd.sh
#在文件中添加如下:
export PATH=/usr/local/lamp/httpd/httpd/bin:$PATH
#然后source一下文件
. /etc/profile.d/httpd.sh
httpd -t #檢查配置文件語法(此時(shí)可以使用hash命令查看一下使用的路徑)
到此為止httpd2.4已結(jié)安裝完成,可以使用/etc/init.d/httpd24 start啟動(dòng)并使用ss -lnt查看端口或者使用ps查看啟動(dòng)的進(jìn)程。
注意:
可以使用如下命令建立軟連接方便使用
ln -sv /usr/local/lamp/httpd/httpd /usr/local/httpd
如有需要可以添加man路徑以及include文件加入/usr/include中
第二步編譯安裝mariadb
推薦使用添加到y(tǒng)um源使用yum安裝:
https://downloads.mariadb.org/mariadb/repositories/#mirror=neusoft&distro=CentOS&distro_release=centos6-amd64--centos6&version=10.2
- 下載編譯好的壓縮包:https://downloads.mariadb.org/(自己編譯源碼耗費(fèi)時(shí)間,難度較大)
- rz傳到服務(wù)器相應(yīng)目錄,解壓
- 創(chuàng)建mysql用戶以及數(shù)據(jù)目錄夾
tar xf mariadb-10.2.12-linux-x86_64.tar.gz -C /usr/local/lamp/mariadb/
useradd -r mysql
mkdir -p /data
chown -R mysql:mysql /data/
ln -s /usr/local/lamp/mariadb/mariadb-10.2.12-linux-x86_64 /usr/local/mysql
- 通過腳本安裝并且配置好啟動(dòng)腳本以及環(huán)境變量
cd /usr/local/mysql
chown -R root.mysql ./*
scripts/mysql_install_db --datadir=/data --user=mysql #安裝
(根據(jù)安裝提示可以使用./bin/mysql_secure_installation來進(jìn)行數(shù)據(jù)庫初始化)
mkdir /etc/mysql
cp support-files/my-large.cnf /etc/mysql/my.cnf #拷貝示例的配置文件
vim /etc/mysql/my.cnf #修改配置文件
thread_concurrency改為cpu個(gè)數(shù)*2
datadir = /data
innodb_file_per_table = on
skip_name_resolve = on
cp support-files/mysql.server /etc/rc.d/init.d/mysqld #提供腳本
vim /etc/rc.d/init.d/mysqld
basedir=/usr/local/mysql #設(shè)置安裝路徑
datadir=/data #設(shè)置數(shù)據(jù)目錄
chkconfig --add mysqld #添加mysqld為系統(tǒng)服務(wù)
chkconfig mysqld on #添加為開機(jī)啟動(dòng)
#添加環(huán)境變量
echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
#初始化
mysql_secure_installation
為了使用mariadb的安裝符合系統(tǒng)使用規(guī)范,并將其開發(fā)組件導(dǎo)出給系統(tǒng)使用,這里還需要進(jìn)行如下步驟:
1.輸出mariadb的man手冊至man命令的查找路徑:
編輯/etc/man.config,添加如下行即可:
MANPATH /usr/local/mysql/man
- 輸出mariadb的頭文件至系統(tǒng)頭文件路徑/usr/include:
ln -sv /usr/local/mysql/include /usr/include/mysql - 輸出mariadb的庫文件給系統(tǒng)庫查找路徑:
echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
然后使用 ldconfig 重新載入動(dòng)態(tài)庫
到此已完成mariadb安裝
第三步編譯安裝PHP
根據(jù)你需要部署的業(yè)務(wù)下載合適版本的php,部署WordPress以及phpmyadmin所以選擇版本為7.2。
下載地址:http://php.net
- 上傳到相應(yīng)目錄,解壓
- 安裝依賴
yum -y groupinstall "Desktop Platform Development"
yum -y install bzip2-devel libmcrypt-devel(使用php5.6需要安裝) libxml2-devel
注意以上的libmcrypt為epel源,使用國內(nèi)的epel源查看這里
- 編譯安裝(編譯成模塊形式)
./configure --prefix=/usr/local/lamp/php/php --with-openssl --with-pdo-mysql=mysqlnd --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/httpd/bin/apxs --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
說明:
1、這里為了支持apache的worker或event這兩個(gè)MPM,編譯時(shí)使用了--enable-maintainer-zts選項(xiàng)。
2、如果使用PHP5.3以上版本,為了鏈接MySQL數(shù)據(jù)庫,可以指定mysqlnd,這樣在本機(jī)就不需要先安裝MySQL或MySQL開發(fā)包了。mysqlnd從php 5.3開始可用,可以編譯時(shí)綁定到它(而不用和具體的MySQL客戶端庫綁定形成依賴),但從PHP 5.4開始它就是默認(rèn)設(shè)置了。./configure --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd3、--with-mcrypt php7.2已經(jīng)放棄這種加密方式
4、--with-apxs2=/usr/local/httpd/bin/apxs 使用apache的模塊方式安裝
接著運(yùn)行make && make install 即可
- 編譯安裝完成后配置
# 為php提供配置文件:
cp php.ini-production /etc/php.ini
ln -sv /usr/local/lamp/php/php /usr/local/php
vim /etc/httpd/conf/httpd.conf
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php index.html
#默認(rèn)不支持php格式,需要添加如上配置,然后reload httpd
- 測試頁面
vim /usr/local/httpd/htdocs/index.php
添加下列內(nèi)容(php7):
<?php
$connect=new mysqli();//獲取mysqli對(duì)象
$connect->connect('127.0.0.1','root','redhat');//使用connect方法連接數(shù)據(jù)庫
//判斷數(shù)據(jù)庫是否連接成功
if($connect->connect_error){
echo "連接失敗";
}
else{
echo '連接成功';
}
$connect->close();
phpinfo();
?>
在瀏覽器訪問虛擬機(jī)IP地址即可測試httpd調(diào)用php連接mariadb是否成功。
到此,lamp環(huán)境已經(jīng)編譯安裝完畢。
PS:
- 簡單部署phpMyadmin測試:
上傳包-->解壓到htdocs目錄-->cp config.sample.inc.php config.inc.php-->修改配置文件(修改隨機(jī)字串即可cfg['blowfish_secret']) - php7不再需要xcache,需要使用opcache來加速,具體配置還在研究