CentOS 5.5 下配置Nginx+mysql+php

LNMP配置

根据网上的一些资料,综合总结了在Centos5.5 下安装NMP的方式。同时通过修改配置文件达到解决框架的路由问题。

1、安装前首先使用yum命令安装、升级所需的程序库(可选,但是安装过程中如果遇到缺少依赖包的话则必须得安装了)

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 ssse2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

2、安装MySQL5.1.57

检查是否已安装mysql

Rpm –qa|grep mysql

Rpm包可用以下命令删除 rpm –e mysqlXXX –-nodeps

源码编译安装可用

进入上次安装mysql的源码包

执行 make uninstall 和 make clean

#useradd mysql 添加用户

#tar zxvf mysql-5.1.57.tar.gz 解压包

#cd mysql-5.1.57 进入mysql目录

编译前配置

#./configure

--prefix=/usr/local/mysql 安装位置

--datadir=/videodata/mysqldata/data 数据位置

--with-extra-charsets=all charsets扩展

--with-charset=gbk

--with-charset=utf8 支持字符集GBKUTF-8)

--with-innodb 启用innodb引擎

注:mysql 默认不支持innodb如果要启用innodb需要在编译的时候 --with-innodb

或者–with-plugins=innobase (根据版本不一样选择)

编译

#make && make install

安装后的调整:
cp support-files/my-medium.cnf /etc/my.cnf 产生配置文件


初使数据库:
/usr/local/mysql/bin/mysql_install_db --user=mysql


设置用户及用户组:
chown -R root:mysql /usr/local/mysql
chown -R mysql /usr/local/mysql/var

启动数据库:
/usr/local/mysql/bin/mysqld_safe --user=mysql & 以mysql用户启动mysql

修改密码

#/usr/local/mysql/bin/mysqladmin -u root password 123456 设置MySQL密码

开机启动:

#echo “/usr/local/mysql/bin/mysqld_safe &” >>/etc/rc.local

备注:

可以进入mysql 使用show engines;查看是否有innodb引擎

3.安装nginx

因为nginx的路径和重写是需要靠prce来支持的。所以先安装pcre。

检查是否安装有pcre

Rpm –qa|grep pcre

#cp /lib/libpcre.so.0 / 保存出来 后面需要用

删除

Rpm –e pcreXX

#tar zvxf pcre-xxx 解压pcre源码包

#cd pcrexxx 进入源码文件夹

#cp /libpcre.so.0 /lib/ 复制进去

#./configure

//配置PCRE,因为PCRE是一个库,而不是像pachephp、postfix等这样的程序,所以我们安装时选择默认路径即可,这样会在后面安装其它东西时避免一些不必要的麻烦,执行完这部后会显示出下图,上面显示了我们对PCRE的配置

编译安装

#make && make install

安装nginx

#tar zvxf nginx-xxxx

#./configure

--with-http_stub_status_module 开启模块

--prefix=/usr/local/nginx 安装路径

编译安装
make&& make install

备注:

若想测试安装是否成功,可以使用 nginx安装路径/sbin/nginx 开启nginx 然后输入localhost测试,若成功会显示 welcome to nginx!

4.安装PHP扩展库

1. libiconv安装

#tar zxvf libiconv-1.8.tar.gz

#cd libiconv-1.8/

#./configure

--prefix=/usr/local/webserver/libiconv

#make && make install

2. 安装zlib2 (zlib是提供数据压缩用的函式库)

#tar zxvf zlib-1.2.3.tar.gz
#cd zlib-1.2.3
#./configure

--prefix=/usr/local/zlib
#make
#make install

3. 安装PNG (图像文件存储格式)

#tar zxvf libpng-1.2.26.tar.gz
#cd libpng-1.2.26
#cp scripts/makefile.linux ./makefile
#./configure

--prefix=/usr/local/libpng
#make
#make install

4. 安装freetype (freetype是字体的支持 )

#tar zxvf freetype-2.3.5.tar.gz
#cd freetype-2.3.5
#./configure

--prefix=/usr/local/freetype
#make
#make install

5. 安装JPEG6 ((图像文件存储格式)

#tar zxvf jpegsrc.v6b.tar.gz
#cd jpeg-6b
#mkdir -pv /usr/local/libjpeg/{,bin,lib,include,man/man1,man1}
#./configure

--prefix=/usr/local/libjpeg

--enable-shared --enable-static

#make
#make install

6. 安装 libxml2 (xml c语言版的解析器)
#tar zxvf libxml2-2.6.31.tar.gz
#cd libxml2-2.6.31
#./configure

--prefix=/usr/local/libxml2
#make
#make install
#cp xml2-config /usr/bin

7. 安装 libmcrypt-2.5.7.tar.gz (是加密算法扩展库)
#
tar zxvf libmcrypt-2.5.7.tar.gz
#cd libmcrypt-2.5.7
#./configure
#make
#make install

8. 安装Fontconfig (字体管理)
#
tar -zxvf fontconfig-2.4.2.tar.gz
#cd fontconfig-2.4.2
#./configure

--prefix=/usr/local/fontconfig --with-freetype-config=/usr/local/freetype/bin/freetype-config

#make
#make install


9. mhash安装

#tar zxvf mhash-0.9.9.9.tar.gz

#cd mhash-0.9.9.9/

#./configure

#make && make install

(忽略)#/sbin/ldconfig

10 mcrypt安装

#tar zxvf mcrypt-2.6.8.tar.gz

#cd mcrypt-2.6.8/

#./configure

#make && make install

安装到mcrypt的时候出现了问题
./configure
提示出错,首先提示
*** Could not run libmcrypt test program, checking why…
*** The test program failed to compile or link. See the file config.log for the
*** exact error that occured. This usually means LIBMCRYPT was incorrectly installed
*** or that you have moved LIBMCRYPT since it was installed. In the latter case, you
*** may want to edit the libmcrypt-config script: no
configure: error: *** libmcrypt was not found
找了相关资料,得出解决方法明明我安装了libmcrypt 2.5.8 ,可是竟然提示没有发现!然后在/usr/local/bin/找到了LIBMCRYPT_CONFIG ,这一步明确了是PATH变量的问题
方法是ln -s /usr/local/bin/libmcrypt_config /usr/bin/libmcrypt_config
之后继续进行./configure
仍然报错:
*** Could not run libmcrypt test program, checking why…
*** The test program compiled, but did not run. This usually means
*** that the run-time linker is not finding LIBMCRYPT or finding the wrong
*** version of LIBMCRYPT. If it is not finding LIBMCRYPT, you’ll need to set your
*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point
*** to the installed location Also, make sure you have run ldconfig if that
*** is required on your system
***
*** If you have an old version installed, it is best to remove it, although
*** you may also be able to get things to work by modifying LD_LIBRARY_PATH
***
configure: error: *** libmcrypt was not found

继续查找,还是变量的问题
解决方法如下:运行 export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH
然后make make install
完成

11. 安装GD
#tar zxvf gd-2.0.35.tar.gz
#cd gd-2.0.35
#./configure

--prefix=/usr/local/libgd

--with-png=/usr/local/libpng

--with-freetype=/usr/local/freetype

--with-jpeg=/usr/local/libjpeg

--with-fontconfig=/usr/local/fontconfig

看到下面的信息, 呵呵 很多都显示支持了
Support for PNG library: yes
Support for JPEG library: yes
Support for Freetype 2.x library: yes
Support for Fontconfig library: yes
Support for Xpm library: no
Support for pthreads: yes
#make
#make install


(make时可能会是出现以下错误
cd . && /bin/sh /root/gd-2.0.35/config/missing --run aclocal-1.9 -I config
aclocal:configure.ac:64: warning: macro `AM_ICONV' not found in library
cd . && /bin/sh /root/gd-2.0.35/config/missing --run automake-1.9 --foreign
cd . && /bin/sh /root/gd-2.0.35/config/missing --run autoconf
configure.ac:64: error: possibly undefined macro: AM_ICONV
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
make: *** [configure] Error 1
把报错信息“configure.ac:64: error: possibly undefined macro: AM_ICONV”拿到google里搜索,得到“But you need to have gettext”没有gettext这个包。
然后直接运行:yum install gettext 在做make 就好了(centos5.5 安装iso里面也有 复制gettextXXX.RPMgettext-develepXX.RPM) 安装

#cp /usr/local/png/include/png.h ./

#cp /usr/local/png/include/pngconf.h ./

#make && make install

5、安装PHP

如果pdolinux下出现exception 'PDOException' with message 'could not find driver'则问题是php编译时少加--with-pdo-mysql=/usr/local/mysql

(用这个的话,自动启动PDO支持mysql了,不需要再次编译了)

一.编译的时候开启php扩展库

#tar zxvf php-5.2.9.tar.gz

#gzip -cd php-5.2.9-fpm-0.5.10.diff.gz | patch -d php-5.2.9 -p1

#cd php-5.2.9/

#./configure

--prefix=/usr/local/webserver/php

--with-config-file-path=/usr/local/webserver/php/etc

--with-mysql=/usr/local/webserver/mysql

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

--with-iconv-dir=/usr/local/webserver/libconv

--with-freetype-dir =/usr…. gd库需要使用

--with-jpeg-dir =/usrgd库需要使用

--with-png-dir =/usr gd库需要使用

--with-zlib zlib是提供数据压缩用的函式库

--with-zlib-dir=/usr/local/webserver/zlib

--with-libxml-dir=/usr 使用xml

--enable-xml

--disable-rpath

--enable-discard-path

--enable-safe-mode

--enable-bcmath

--enable-shmop

--enable-sysvsem –

-enable-inline-optimization

--with-curl

--with-curlwrappers

--enable-mbregex

--enable-fastcgi

--enable-fpm 启和nginx的通信 pphp 5.3.3以后集成了 可以直接开启使用

--enable-force-cgi-redirect

--enable-mbstring 开启mbstring函数

--with-mcrypt

--with-gd 使用gd

--enable-gd-native-ttf

--with-openssl

--with-mhash

--enable-pcntl

--enable-sockets

--with-ldap

--with-ldap-sasl

#make

#make install

#cp php.ini-dist /usr/local/webserver/php/etc/php.ini

#cd ../

注:php5.3.3以后集成了fpm 可以 ./configure –-prefix=/usr/local/php

– -enable-fpm

不需要再装php-fpm插件了

可能会出现下面的问题 php5.4.4

Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/usr/sky/soft/php/php-5.3.8/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar
Installing PDO headers: /usr/local/php/include/php/ext/pdo/

解决方法

5.3.3以上版本

#cp php.ini-production /usr/local/php/lib/php.ini


#vim /usr/local/php/lib/php.ini (
增加/usr/local/php/lib/phpinclude_path)


执行

#/usr/sky/soft/php/php-5.3.8/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin


#ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar

Php5.4.4集成了php-fpm所以可以使用以下启动nginx

#/usr/local/php/sbin/php-fpm –c php.ini(位置)

查看phpnginx是否启动

#ps -aux | grep nginx

#ps -aux | grep php

Php-fpm 开机启动

#echo “/usr/local/php/sbin/php-fpm start” >>/etc/rc.local

修改nginx配置文件以支持php-fpm

nginx安装完成后,修改nginx配置文件为 nginx/conf/nginx.conf

其中server段增加如下配置,注意标红内容配置,否则会出现No input file specified.错误

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
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;
}

创建测试php文件

创建php文件

在/usr/local/nginx/html下创建index.php文件,输入如下内容

<? echo phpinfo(); ?>

启动服务

启动php-fpm和nginx

/usr/local/php/sbin/php-fpm (手动打补丁的启动方式/usr/local/php/sbin/php-fpm start)

sudo /usr/local/nginx/nginx

上传2M多的附件时,出现如下错误
413 Request Entity Too Large
nginx/0.8.48

这是由于上传的附件超过了nginx的设置(nginx默认允许上传的附件的大小为1M)
#vi /usr/local/nginx/conf/nginx.conf


lient_max_body_size 20m; #可以根据自己的实际需要去定义上传附件的大小;

修改完之后,重启

果断打开nginx/conf/nginx.conf,在http模块中增加

client_max_body_size 10m;

nginx/sbin/nginx -s reload

注意:默认nginx是不支持path_info 所以ci等框架的

Localhost/ci/index.php/class/function是用不了的

需要修改nginx文件

新版nginxpathinfo配置小结

(1)设置fastcgi_param SCRIPT_NAME $fastcgi_script_name;

php-cgi如果找不到文件或者没有权限访问的话 会提示No input file specified. 或者Access denied.

(2)php.inicgi.fix_pathinfo

cgi.fix_pathinfo boolean

对CGI提供了真正的PATH_INFO/PATH_TRANSLATED支持。以前PHP的行为是将 PATH_TRANSLATED 设为 SCRIPT_FILENAME,而不管 PATH_INFO 是什么。有关 PATH_INFO 的更多信息见 cgi 规格。将此值设为 1 将使 PHP CGI 修正其路径以遵守规格。设为 0 将使 PHP 的行为和从前一样。默认为零。用户应该修正其脚本使用 SCRIPT_FILENAME 而不是 PATH_TRANSLATED

when cgi.fix_pathinfo was set to “1〃 it caused a lot of checks in order to find which part of SCRIPT_FILENAME is a file name and which is PATH_INFO. In case of missing file it caused NULL in path_translated, which caused the crash.

于是,修改nginx.confphp部分配置参数如下

红色为需要注意的部分

location ~ \.php(/|$) {

#root html

fastcgi_pass 127.0.0.1:9000;

fastcgi_split_path_info ^(.+\.php)(/.+)$;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_param PATH_INFO $fastcgi_path_info;

fastcgi_index index.php;

include fastcgi_params;

}

注释掉 fastcgi_param 里的这里# fastcgi_param SCRIPT_FILENAME $request_filename;

大功告成 ;-)

转载于:https://my.oschina.net/feek/blog/94636

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值