Centos搭建PHP5.3.8+Nginx1.0.9+Mysql5.5.17

huidaoli發表於2014-09-05

操作環境

 

  作業系統:Mac Os Lion

  虛擬主機:VMware Fusion

  虛擬系統:Centos 5.5+

  操作使用者:Root

  實現目的:搭建LNMP環境.

 

安裝依賴庫和開發環境

 

複製程式碼
#依賴庫和開發工具
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

#Nginx
yum -y install pcre-devel zlib-devel

#Php
yum -y install gd-devel libjpeg-devel libpng-devel freetype-devel libxml2-devel curl-devel freetype-devel
 
#Mysql
yum -y install bison gcc gcc-c++ autoconf automake zlib* libxml* ncurses-devel libtool-ltdl-devel* mysql-devel
 
複製程式碼

 

下載軟體包

 

複製程式碼

#建立目錄
mkdir /web 
cd /web 
 
#PHP5.3.7 
wget http://cn.php.net/distributions/php-5.3.8.tar.bz2 
 
#PHP庫檔案
wget http://ncu.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
wget http://ncu.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
wget http://ncu.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

#Nginx1.0.9
wget http://www.nginx.org/download/nginx-1.0.9.tar.gz

#Nginx(pcre)
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.13.tar.gz

#Mysql5.5.17
wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.17.tar.gz/from/http://mysql.ntu.edu.tw/

#Mysql(cmake)
wget http://www.cmake.org/files/v2.8/cmake-2.8.6.tar.gz
 
複製程式碼

 

安裝Mysql

 

複製程式碼
#安裝cmake
tar -zxvf cmake-2.8.6.tar.gz
cd cmake-2.8.6/
./configure
gmake && gmake install && cd ../

#新增mysql使用者
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql

#安裝Mysql
tar -zxvf mysql-5.5.17.tar.gz
cd mysql-5.5.17
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc/
make && make install

#設定Mysql
#在support-files目錄中有五個配置資訊檔案:
#my-small.cnf (記憶體<=64M)
#my-medium.cnf (記憶體 128M)
#my-large.cnf (記憶體 512M)
#my-huge.cnf (記憶體 1G-2G)
#my-innodb-heavy-4G.cnf (記憶體 4GB)
cd /usr/local/mysql
cp ./support-files/my-medium.cnf /etc/my.cnf
vi /etc/my.cnf
#在 [mysqld] 段增加
datadir = /data/mysql
wait-timeout = 30
max_connections = 512
default-storage-engine = MyISAM
#在 [mysqld] 段修改
max_allowed_packet = 16M

#生成授權表
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql

#更改密碼
/usr/local/mysql/bin/mysqladmin -u root password 123456

#開啟mysql
/usr/local/mysql/bin/mysqld_safe &

#測試連線mysql
/usr/local/mysql/bin/mysql -u root -p 123456
show databases;
exit;

#設定開機啟動
vi /etc/rc.d/rc.local

#加入
/usr/local/mysql/bin/mysqld_safe &
複製程式碼

 

安裝PHP

 

複製程式碼
#1
tar -zxvf libiconv-1.14.tar.gz && cd libiconv-1.14/
./configure --prefix=/usr/local
make && make install && cd ../

#2
tar -zxvf libmcrypt-2.5.8.tar.gz && cd libmcrypt-2.5.8/
./configure && make && make install
/sbin/ldconfig && cd libltdl/ && ./configure --enable-ltdl-install
make && make install && cd ../

#3
tar -zxvf mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9/ && ./configure
make && make install && cd ../

#4
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

#5
tar -zxvf mcrypt-2.6.8.tar.gz &&cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make && make install && cd ../

#6
tar -xjvf php-5.3.8.tar.bz2
cd php-5.3.8

./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-iconv-dir=/usr/local/ --with-freetype-dir \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-jpeg-dir --with-png-dir --with-zlib \
--with-mhash --enable-sockets --enable-ftp \
--with-libxml-dir --enable-xml --disable-rpath \
--enable-safe-mode --enable-bcmath \
--enable-shmop --enable-sysvsem \
--enable-inline-optimization --with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-mbstring --with-mcrypt --with-gd \
--enable-gd-native-ttf --with-openssl --with-mhash \
--enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl \
--enable-fpm \
--with-xmlrpc --enable-zip --enable-soap \
--without-pear \


make ZEND_EXTRA_LIBS='-liconv'

#注意這裡容易出現 make: *** [ext/phar/phar.php] 錯誤 127

#出現mysql client解決方法
#ln -s /usr/local/mysql/lib/libmysqlclient.so /usr/lib/
#ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18

#或者chmod: 無法訪問 “ext/phar/phar.phar”: 沒有那個檔案或目錄
#make: [ext/phar/phar.phar] 錯誤 1 (忽略)
#解決方法在編譯的時候加--without-pear引數

#如果還不行,make的時候不新增 ZEND_EXTRA_LIBS='-liconv' 引數

make install

#選擇PHP.ini配置檔案
cp php.ini-production /usr/local/php/etc/php.ini
複製程式碼

 

更改PHP-FPM

 

複製程式碼
#新增WWW使用者
/usr/sbin/groupadd www && /usr/sbin/useradd -g www www
mkdir -p /var/log/nginx && chmod +w /var/log/nginx &&chown -R www:www /var/log/nginx
mkdir -p /data/www && chmod +w /data/www && chown -R www:www /data/www

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf

#去掉/更改 配置檔案中的;
pm.max_children = 64
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 1024
user = www
group = www 

#檢查語法是否正確
/usr/local/php/sbin/php-fpm -t
#出現NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful 測試成功
/usr/local/php/sbin/php-fpm &
#設定開機啟動
vi /etc/rc.d/rc.local
#在行末加入
/usr/local/php/sbin/php-fpm &

#返回安裝包目錄 
cd /web 
複製程式碼

 

安裝Nginx

 

複製程式碼
#安裝pcre庫
tar -zxvf pcre-8.13.tar.gz && cd pcre-8.13/ && ./configure
make && make install && cd ../

#安裝Nginx
tar -zxvf nginx-1.0.9.tar.gz && cd nginx-1.0.9 &&
./configure --user=www --group=www \
--prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-pcre \
--lock-path=/var/run/nginx.lock \
--pid-path=/var/run/nginx.pid

make && make install && cd ../

#更改配置
vi /usr/local/nginx/conf/nginx.conf

#修改一些引數,別直接替換檔案,這只是一部分
user www

events {
use epoll;
worker_connections 1024;
}

location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

#注意這裡
#$document_root$fastcgi_script_name;
#檢測配置檔案
/usr/local/nginx/sbin/nginx -t

#提示表示成功
#nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
#nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

#開啟Nginx
/usr/local/nginx/sbin/nginx &
#平滑重啟Nginx
/usr/local/nginx/sbin/nginx -s reload

#新增開機啟動
vi /etc/rc.d/rc.local
#最後移行加入
/usr/local/nginx/sbin/nginx

#測試
cd /usr/local/nginx/html/
touch index.php
vi /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
複製程式碼





允許任何人轉載,幫助更多的人,解決遇到的問題:
原文連結地址:http://www.cnblogs.com/wubaiqing/archive/2011/11/08/2241195.html

相關文章