LNMP配置 php
根据网上的一些资料,综合总结了在Centos5.5 下安装NMP的方式。同时经过修改配置文件达到解决框架的路由问题。 html
1、安装前首先使用yum命令安装、升级所需的程序库(可选,可是安装过程当中若是遇到缺乏依赖包的话则必须得安装了) node
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 mysql
2、安装MySQL(5.1.57) linux
检查是否已安装mysql nginx
Rpm –qa|grep mysql c++
Rpm包可用如下命令删除 rpm –e mysqlXXX –-nodeps git
源码编译安装可用 web
进入上次安装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 支持字符集GBK和UTF-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是一个库,而不是像pache、php、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.RPM 和 gettext-develepXX.RPM) 安装
#cp /usr/local/png/include/png.h ./
#cp /usr/local/png/include/pngconf.h ./
#make && make install
5、安装PHP
若是pdo在linux下出现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 =/usr… gd库须要使用
--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/php到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
Php5.4.4集成了php-fpm因此可使用如下启动nginx
#/usr/local/php/sbin/php-fpm –c php.ini(位置)
查看php和nginx是否启动
#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文件
(1)设置fastcgi_param SCRIPT_NAME $fastcgi_script_name;
php-cgi若是找不到文件或者没有权限访问的话 会提示No input file specified. 或者Access denied.
(2)php.ini中cgi.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.conf里php部分配置参数以下
红色为须要注意的部分
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;
大功告成 ;-)