1. 程式人生 > >CentOS6源碼安裝LAMP----基於fastcgi方式(2臺機器)

CentOS6源碼安裝LAMP----基於fastcgi方式(2臺機器)

centos6 源碼安裝lamp 基於fastcgi方式 (2臺機器)

源碼搭建LAMP

CentOS6源碼安裝LAMP----基於fastcgi方式(2臺機器)

軟件包下載源:

搜狐鏡像源:http://mirrors.sohu.com/

apache下載網:http://mirror.bit.edu.cn/apache/

pcre官網:http://www.pcre.org/

apr官網:http://apr.apache.org/

apache官網:http://httpd.apache.org/

mysql官網:https://www.mysql.com/

php官網:http://php.net/

freetds:http://download.csdn.net/download/xhu_eternalcc/7457555

官網:http://www.freetds.org/


實驗環境:

CentOS6.5-x86_64 單臺機器

IP 192.168.9.176 php

IP 192.168.9.225 apache+mysql

版本:

apr-1.5.2

apr-util-1.5.4

httpd-2.4.20

php-5.6.22

mysql-5.6.32


說明,因為php要連接mysql,所以安裝順序為apache,mysql,php

註:httpd2.4版本需要較新的apr和apr-util



註:新機器要初始化:參考http://wupengfei.blog.51cto.com/7174803/1955545

註:(生產環境一般包放內網ftp下載比較快,一般前端用nginx反向代理至後端apache,通過fastcgi連接php,mysql獨立並做集群)


一、編譯安裝apache
1、#yum安裝httpd依賴軟件
[[email protected] ~]# yum install -y gcc gcc-c++ libtool libtool-ltdl-devel make gd-devel freetype-devel libxml2-devel libjpeg-devel libpng-devel openssl-devel patch  
[[email protected] ~]# yum install -y curl-devel bzip2 pcre-devel zip2-devel bzip2-devel 
[[email protected]
/* */ ~]# yum install -y mcrypt-devel zlib-devel wget 2、#編譯安裝apr [[email protected] ~]# cd /usr/local/src/ [[email protected] src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.5.2.tar.bz2 [[email protected] src]# tar xf apr-1.5.2.tar.bz2 [[email protected] src]# cd apr-1.5.2 [[email protected] apr-1.5.2]# ./configure --prefix=/usr/local/apr [[email protected] apr-1.5.2]# make && make install 3、編譯安裝apr-util [[email protected] apr-1.5.2]# cd /usr/local/src/ [[email protected] src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.5.4.tar.bz2 [[email protected] src]# tar xf apr-util-1.5.4.tar.bz2 [[email protected] src]# cd apr-util-1.5.4 [[email protected] apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr [[email protected] apr-util-1.5.4]# make && make install 4、編譯安裝httpd [[email protected] apr-util-1.5.4]# useradd -s /sbin/nologin www [[email protected] apr-util-1.5.4]# cd /usr/local/src/ [[email protected] src]# wget http://apache.fayea.com//httpd/httpd-2.4.20.tar.bz2 [[email protected] src]# tar xf httpd-2.4.20.tar.bz2 [[email protected] src]# cd httpd-2.4.20 [[email protected] httpd-2.4.20]# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork [[email protected] httpd-2.4.20]# make [[email protected] httpd-2.4.20]# make install [[email protected] httpd-2.4.20]# sed -i ‘s/User daemon/User www/g‘ /usr/local/apache/conf/httpd.conf [[email protected] httpd-2.4.20]# sed -i ‘s/Group daemon/Group www/g‘ /usr/local/apache/conf/httpd.conf [[email protected] httpd-2.4.20]# sed -i "/ServerName/s/#ServerName.*/ServerName localhost/g" /usr/local/apache/conf/httpd.conf 6、啟動方法 #/usr/local/apache/bin/apachectl -k start|reload|restart|stop 7、測試驗證 [[email protected] httpd-2.4.20]# curl -I http://192.168.9.176 HTTP/1.1 200 OK Date: Fri, 11 Aug 2017 15:22:43 GMT Server: Apache/2.4.20 (Unix) Last-Modified: Mon, 11 Jun 2007 18:53:14 GMT ETag: "2d-432a5e4a73a80" Accept-Ranges: bytes Content-Length: 45 Content-Type: text/html


二、編譯安裝MySQL

1、#下載安裝包
[[email protected] httpd-2.4.20]# cd /usr/local/src/
[[email protected] src]# wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz

2、#建立運行mysql用戶和組為系統賬號  
[[email protected] src]# groupadd -r mysql
[[email protected] src]# useradd -r -g mysql -s /sbin/nologin mysql

3、#編譯安裝
[[email protected] src]# yum install -y libaio libaio-devel numactl numactl-devel cmake ncurses-devel libxml2-devel libtool-ltdl-devel gcc-c++ autoconf automake bison zlib-devel
[[email protected] src]# tar xf mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz
[[email protected] src]# mv mysql-5.6.37-linux-glibc2.12-x86_64 /usr/local/mysql
#建議mysql使用獨立設備獨立目錄,本實驗只建立目錄,獨立設備請參考磁盤分區與掛載
[[email protected] src]# mkdir -p /data0/mysql
#更改屬主屬組
[[email protected] src]# chown -R mysql.mysql /usr/local/mysql
#初始化數據庫
[[email protected] src]# cd /usr/local/mysql
[[email protected] mysql]# ./scripts/mysql_install_db --datadir=/data0/mysql --user=mysql
[[email protected] mysql]# cp ./support-files/my-default.cnf /data0/mysql/my.cnf
[[email protected] mysql]# echo "basedir = /usr/local/mysql
datadir = /data0/mysql
port = 3306
server_id = 1000
socket = /tmp/mysql.sock" >>/data0/mysql/my.cnf
[[email protected] mysql]# chown -R mysql.mysql /data0/mysql/
4,啟動:
[[email protected] mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data0/mysql/my.cnf &
[[email protected] mysql]# echo "/usr/local/mysql/bin/mysqld_safe --defaults-file=/data0/mysql/my.cnf &" >> /etc/rc.d/rc.local

6、#安全初始化
#安全驗證初始化,設置root用戶密碼,刪除匿名用戶,禁止root用戶遠程連接,刪除test庫
[[email protected] mysql]# ./bin/mysql_secure_installation
#導出頭文件
[[email protected] mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql
#加載庫文件
[[email protected] mysql]# echo "/usr/local/mysql/lib/mysql/" >>/etc/ld.so.conf
[[email protected] mysql]# ldconfig
[[email protected] mysql]# echo "PATH=$PATH:/usr/local/mysql/bin/" >> /etc/profile


三、編譯安裝PHP

1、#編譯安裝libmcrypt擴展
[[email protected] src]# cd /usr/local/src/
[[email protected] src]# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
[[email protected] src]# tar xf libmcrypt-2.5.7.tar.gz 
[[email protected] src]# cd libmcrypt-2.5.7
[[email protected] libmcrypt-2.5.7]# ./configure
[[email protected] libmcrypt-2.5.7]# make && make install

2、#編譯安裝freetds擴展
[[email protected] local]# cd /usr/local/src/
[[email protected] src]# wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-patched.tar.gz
[[email protected] src]# tar xf freetds-patched.tar.gz 
[[email protected] src]# cd freetds-1.00.53/
[[email protected] freetds-1.00.53]# ./configure --prefix=/usr/local/freetds --with-tdsver=7.4 --enable-msdblib 
[[email protected] freetds-1.00.53]# make && make install
[[email protected] freetds-1.00.53]# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/freetds/lib/

4、#下載安裝包
[[email protected] src]# cd /usr/local/src/
[[email protected] src]# wget http://cn2.php.net/distributions/php-5.6.22.tar.bz2
[[email protected] src]# tar xf php-5.6.22.tar.bz2 
[[email protected] src]# cd php-5.6.22
[[email protected] php-5.6.22]#  ./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-mssql=/usr/local/freetds --with-bz2 --enable-maintainer-zts --with-curl --enable-ftp --enable-bcmath --with-gd --with-freetype-dir --enable-gd-native-ttf --with-iconv-dir --enable-mbstring --enable-calendar --with-gettext --enable-dom --enable-fpm
#說明:如果php5.3以上的版本,為了鏈接數據庫,可以指定mysqlnd,這樣本機就可以不用安裝mysql和mysql開發包。5.4已經是默認設置。
如: --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd
[[email protected] php-5.6.22]# make
[[email protected] php-5.6.22]# make install

#為php提供配置文件
[[email protected] php-5.6.22]# cp php.ini-development /usr/local/php/etc/php.ini

5、編輯apache配置文件httpd.conf,apache支持php
[[email protected] php-5.6.22]# sed -i ‘/LoadModule php5_module/ aAddType application/x-httpd-php-source .phps‘ /usr/local/apache/conf/httpd.conf
[[email protected] php-5.6.22]# sed -i ‘/LoadModule php5_module/ aAddType application/x-httpd-php .php .php5‘ /usr/local/apache/conf/httpd.conf
[[email protected] php-5.6.22]# sed -i ‘/DirectoryIndex/ s/index.html/index.php index.html/‘ /usr/local/apache/conf/httpd.conf

#重啟httpd
[[email protected] php-5.6.22]# /usr/local/apache/bin/apachectl -k restart
4、測試驗證php
 "<?php
        phpinfo();
?>" > /usr/local/apache/htdocs/index.php
5、瀏覽器訪問:
http://192.168.9.168
5、測試驗證php連接數據庫
[[email protected] php-5.6.22]# vim index.php 

<?php
        $link = mysql_connect(‘127.0.0.1‘,‘root‘,‘123456‘);
        if ($link)
             echo "Success...";
        else
             echo "Failure...";
        mysql_close()
?>
#瀏覽器訪問
http://192.168.9.168

6、#ab壓力測試
[[email protected] php-5.6.22]# ab -c 100 -n 10000 

四、測試Xcache為php加速
1、#編譯安裝
[[email protected] htdocs]# cd /usr/local/src/
[[email protected] src]# tar xf xcache-3.2.0.tar.bz2 
[[email protected] src]# cd xcache-3.2.0
[[email protected] xcache-3.2.0]# /usr/local/php/bin/phpize
[[email protected] xcache-3.2.0]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config 
[[email protected] xcache-3.2.0]# make && make install
2、#編輯php.ini,整合php和xcache
[[email protected] xcache-3.2.0]# mkdir -p /etc/php.d
[[email protected] xcache-3.2.0]# cp xcache.ini /etc/php.d


#重啟apache
[[email protected] xcache-3.2.0]# apachectl -k restart
#壓力測試,看效果




CentOS6源碼安裝LAMP----基於fastcgi方式(2臺機器)