源碼包編譯搭建LNMP+FastCGI平臺

源碼包編譯搭建LNMP+FastCGI平臺

搭建環境:

CentOS 6.5

軟件包版本:

nginx-1.2.0.tar.gz

mysql-5.5.13.tar.gz

php-5.4.9.tar.gz

PHP依賴包:

mhash-0.9.9.9.tar.gz

libiconv-1.13.tar.gz

libmcrypt-2.5.8.tar.gz

libevent-2.0.21-stable.tar.gz

IP地址設置:

server10.21.1.80

client10.21.1.81

一、安裝nginx

[root@dev-16 ~]# useradd -s /sbin/nologin -M nginx

[root@dev-16 lnmp+memcached]# tar -zxf nginx-1.2.0.tar.gz -C /usr/src/

[root@dev-16 lnmp+memcached]# cd /usr/src/nginx-1.2.0/

[root@dev-16 nginx-1.2.0]# ./configure \

--prefix=/usr/local/nginx \

--pid-path=/usr/local/nginx/nginx.pid \

--user=nginx \

--group=nginx \

--with-http_ssl_module \

--with-http_flv_module \

--with-http_stub_status_module \

--with-http_gzip_static_module \

--http-client-body-temp-path=/usr/local/nginx/client \

--http-proxy-temp-path=/usr/local/nginx/proxy \

--http-fastcgi-temp-path=/usr/local/nginx/fcgi \

--http-uwsgi-temp-path=/usr/local/nginx/uwsgi \

--http-scgi-temp-path=/usr/local/nginx/scgi \

--with-pcre

[root@dev-16 nginx-1.2.0]# make && make install

二、安裝mysql

1、安裝mysql配置工具cmake

[root@dev-16 lnmp+memcached]# tar -zxf cmake-2.8.10.2.tar.gz -C /usr/src/

[root@dev-16 lnmp+memcached]# cd /usr/src/cmake-2.8.10.2/

[root@dev-16 cmake-2.8.10.2]# ./bootstrap –prefix=/usr/local/cmake

[root@dev-16 cmake-2.8.10.2]# make

[root@dev-16 cmake-2.8.10.2]# make install

2、安裝源碼mysql

1)創建mysql用戶

[root@dev-16 ~]# useradd -s /sbin/nologin -M mysql

2)解包,配置,編譯,安裝mysql

[root@dev-16 lnmp+memcached]# tar -zxf mysql-5.5.13.tar.gz -C /usr/src/

[root@dev-16 lnmp+memcached]# cd /usr/src/mysql-5.5.13/

[root@dev-16 mysql-5.5.13]#/usr/local/cmake/bin/cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DSYSCONFDIR=/etc \

-DMYSQL_DATADIR=/usr/local/mysql/data \

-DMYSQL_TCP_PORT=3306 \

-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \

-DMYSQL_USER=mysql \

-DEXTRA_CHARSETS=all \

-DWITH_READLINE=1 \

-DWITH_SSL=system \

-DWITH_EMBEDDED_SERVER=1 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

[root@dev-16 mysql-5.5.13]# make && make install

2mysql初始化設置

[root@dev-16 mysql-5.5.13]# cd /usr/local/mysql/

[root@dev-16 mysql]# chown -R mysql.mysql .

[root@dev-16 mysql]# ./scripts/mysql_install_db –user=mysql //初始化操作

3)創建配置文件my.cnf

[root@dev-16 ~]# cd /usr/src/mysql-5.5.13/support-files/

[root@dev-16 support-files]# cp my-medium.cnf /etc/my.cnf //配置文件

[root@dev-16 support-files]# cp mysql.server /etc/init.d/mysqldd //創建啓動腳本

[root@dev-16 support-files]# chmod +x /etc/init.d/mysqldd //添加啓動腳本執行權限

[root@dev-16 support-files]# chkconfig --add mysqldd

[root@dev-16 support-files]# chkconfig --list mysqldd

mysqldd       0:關閉 1:關閉 2:啓用 3:啓用 4:啓用 5:啓用 6:關閉

[root@dev-16 support-files]# service mysqldd start //啓動服務

3)將mysql提供的命令添加到PATH變量中

[root@dev-16 support-files]# export PATH=/usr/local/mysql/bin/:$PATH

[root@dev-16 ~]# vim /etc/bashrc //文件末尾添加一行記錄

export  PATH=/usr/local/mysql/bin:$PATH

4)指定mysql庫文件的位置

[root@dev-16 ~]# cat /etc/ld.so.conf

include ld.so.conf.d/*.conf

/usr/local/mysql/lib/

[root@dev-16 ~]# ldconfig

三、安裝PHP

1)安裝PHP依賴包

mhashlibiconvlibmcrypt直接編譯安裝就可以

libmcrypt包中包含一個libltdl的工具,該工具也需要安裝

[root@dev-16 libmcrypt-2.5.8]# cd libltdl/

[root@dev-16 libltdl]# ./configure --with-gmetad --enable-gexec –enable-ltdl-install

[root@dev-16 libltdl]# make && make install

2)指定擴展包庫文件的位置

[root@dev-16 ~]# ln -sv /usr/local/lib/libmcrypt* /usr/lib/

[root@dev-16 ~]# ln -sv /usr/local/lib/libmhash.* /usr/lib/

[root@dev-16 ~]# ldconfig -v //系統加載當前鏈接文件

3)安裝PHP

進入解壓後目錄

配置:

./configure --prefix=/usr/local/php5nginx \

--with-config-file-path=/usr/local/php5nginx/etc \

--with-mysql=/usr/local/mysql \

--with-mysqli=/usr/local/mysql/bin/mysql_config \

--with-iconv-dir=/usr/local \

--with-freetype-dir \

--with-jpeg-dir \

--with-png-dir \

--with-zlib \

--with-libxml-dir=/usr \

--enable-xml \

--disable-rpath \

--enable-bcmath \

--enable-shmop \

--enable-sysvsem \

--enable-inline-optimization \

--with-curl \

--with-curlwrappers \

--enable-mbregex \

--enable-fpm \

--enable-mbstring \

--with-mcrypt \

--with-gd \

--enable-gd-native-ttf \

--with-openssl \

--with-mhash \

--enable-pcntl \

--enable-sockets \

--with-ldap \

--with-ldap-sasl \

--with-xmlrpc \

--enable-zip \

--enable-soap

配置完成後執行編譯:

[root@dev-16 php-5.4.9]# make ZEND_EXTRA_LIBS='-liconv'

[root@dev-16 php-5.4.9]# make install

4)爲PHP程序創建php配置文件

進入php源碼目錄:

[root@dev-16 php-5.4.9]# cp php.ini-production /usr/local/php5nginx/etc/php.ini

四、整合NginxFastCGI

1)生成php-fpm住配置文件

進入php的安裝目錄下的etc目錄

[root@dev-16 etc]# cp php-fpm.conf.default php-fpm.conf //生成php-fpm的配置文件

2)準備php-fpm的啓動腳本

進入php源碼目錄下:

[root@dev-16 ~]# cd /usr/src/php-5.4.9/sapi/fpm/

[root@dev-16 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm

[root@dev-16 fpm]# chmod +x /etc/init.d/php-fpm

[root@dev-16 fpm]# chkconfig --add php-fpm

[root@dev-16 fpm]# chkconfig --list php-fpm

php-fpm       0:關閉 1:關閉 2:啓用 3:啓用 4:啓用 5:啓用 6:關閉

[root@dev-16 ~]# service php-fpm start

3)編輯nginx配置文件,整合nginxFastCGI

[root@dev-16 ~]# cd /usr/local/nginx/conf/

[root@dev-16 conf]# vim nginx.conf

……

location / {

root  html;

index index.html index.php;

}

……

location ~ \.php$ {

root   html;

fastcgi_pass  127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME  /scripts$fastcgi_script_name;

include fastcgi_params;

}

……

4)修改fastcgi_params文件內容,重啓nginx服務

[root@dev-16 conf]# vim fastcgi_params //添加一行配置

fastcgi_param SCRIPT_FILENAME    $document_root$fastcgi_script_name;

重啓nginx服務:

[root@dev-16 sbin]# ./nginx -s stop

[root@dev-16 sbin]# ./nginx

5)測試

  [root@dev-16 ~]# cat /usr/local/nginx/html/test.php          //測試php解析

<?php

phpinfo();

?>


d[root@dev-16 ~]# cat /usr/local/nginx/html/db.php            //測試數據庫鏈接

<?php

$link=mysql_connect('localhost','test','');    //連數據庫

if($link) echo "恭喜你,數據庫連接成功啦 !!";  //成功時的提示

mysql_close();     //關數據庫

?>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章