Linux (centos )下Nginx+PHP+MySQL配置——自己的lnmp配置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux (centos )下Nginx+PHP+MySQL配置——自己的lnmp配置相关的知识,希望对你有一定的参考价值。
说明:所有软件都是从官网上下载最新版的stable版本
###################
#
# 获取最新源码包
#
#####################
#建立独立的webserver
#mkdir -pv /usr/local/webserver
#放置源码包的目录
#mkdir -pv /usr/local/webserver/src
#cd /usr/local/webserver/src
## php源代码
#wget http://www.php.net/get/php-5.3.4.tar.bz2/from/tw2.php.net/mirror
##php加速器
#wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
##memcache客户端
#wget http://pecl.php.net/get/memcache-3.0.5.tgz
##memcached服务器端
#wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
## mysql数据库
#wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.48.tar.gz/from/http://mysql.cdpa.nsysu.edu.tw/
## nginx 最新稳定版
#wget http://www.nginx.org/download/nginx-0.8.54.tar.gz
#下载php-fpm,一个简单健壮的php FastCGI管理工具。这里对应的是php-5.3.X。官网推荐使用svn方式提取
#tar jxvf php-5.3.4.tar.bz2
#cd php-5.3.
#svn co http://svn.php.net/repository/php/php-src/branches/PHP_5_3/sapi/fpm sapi/fpm
(后注:php-5.3.5开始已经集成了fpm,不必再次co)
#查看fpm是否已经检出
#ls sapi/fpm
######################
#
# 安装
#
######################
## 安装mysql 5.5
安装依赖包
依赖的软件类库:
gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel*
#安装gccyum -y install gcc*
#安装cmakeyum install -y cmake.x86_64
#安装bisonyum install -y bison.x86_64 bison-devel.x86_64
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql5.5.23 \-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_MEMORY_STORAGE_ENGINE=1 \-DWITH_READLINE=1 \-DENABLED_LOCAL_INFILE=1 \-DMYSQL_DATADIR=/data/mysql/3306 \-DMYSQL_USER=mysql \-DMYSQL_TCP_PORT=3306
## 安装php
##安装php的时候可能很多组件都会缺失,可以直接用yum安装这些缺失的组件
yum install gd gd-devel.x86_64
yum install libjpeg libjpeg-devel
yum install -y libxml2-devel.x86_64 xml2
yum install -y openssl openssl-devel
yum install libmcrypt-devel.x86_64 libmcrypt.x86_64 curl-devel.x86_64 curl.x86_64
# ./configure –prefix=/usr/local/webserver/php –with-config-file-path=/usr/local/webserver/php/etc –with-gd –with-mysql=/usr/local/webserver/mysql –enable-mbstring –with-curl –with-mcrypt –with-zlib –with-mhash –enable-fpm –enable-pcntl –enable-sysvsem –enable-shmop –with-jpeg-dir=/usr –with-iconv-dir=/usr/local
#make
#make install
注意:若编译的时候出现 iconv.c:1017: undefined reference to `libiconv_open’可以采取下列措施:
【我的方法】
NOTE: For centos >= 5.4 iconv-devel is provided by glibc
libiconv包含在glibc里,所以安装glic类库即可
#yum install -y glibc-devel.x86_64
【网上的方法】
解决方法:
#wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
#tar -zxvf libiconv-1.13.1.tar.gz
#cd libiconv-1.13.1
# ./configure –prefix=/usr/local/libiconv
# make
# make install
再在php configure的时候添加 –with-iconv=/usr/local/libiconv
据说还有以下两种办法(没有试过):
A: 編輯 Makefile 大約 77 行左右的地方:
EXTRA_LIBS = ….. -lcrypt
在最後加上 -liconv,例如:
EXTRA_LIBS = ….. -lcrypt -liconv
再运行make就可以了。
B: #make ZEND_EXTRA_LIBS=’-liconv’
#make install
安装memcache 客户端
具体安装详细参见: http://www.php.net/manual/en/memcache.installation.php
#tar zxvf memcache-3.0.5.tgz
#cd memcache-3.0.5/
#/usr/local/webserver/php/bin/phpize
#./configure –with-php-config=/usr/local/webserver/php/bin/php-config
#生成 /usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/memcach.so
#make && make install
安装memcached 服务器端
#tar zxvf
# ./configure –prefix=/usr/local/webserver/memcached
#make && make install
#启动memcached
#/usr/local/webserver/memcached -d -m 256 -u root
安装ea
#cd /usr/local/webserver/src/eaccelerator-0.9.6.1
#/usr/local/webserver/php/bin/phpize #### 使用生成configure文件
# ./configure –enable-eaccelerator=shared –with-php-config=/usr/local/webserver/php/bin/php-config
#生成 /usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so
安装nginx
# nginx需要pcre库
#yum install pcre-devel
# 对https需要 安装ssl
#yum install openssl openssl-devel
#cd nginx-0.8.54
#./configure
#make
#make install
配置
server {
listen 80;
server_name www.abc.com;
charset utf-8;
access_log logs/host.access.log main;
location / {
root /home/nginx;
index index.html index.htm index.php;
index index.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/nginx/$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
location ~ /\.ht {
deny all;
}
}
######################################
以上是关于Linux (centos )下Nginx+PHP+MySQL配置——自己的lnmp配置的主要内容,如果未能解决你的问题,请参考以下文章
centos6 LNMP的搭建(linux+nginx+mysql+php)
Nginx配置CI框架问题(Linux平台下Centos系统)