PHP
一、介绍
在Httpd中,PHP以模块的形式存在
在Nginx中,PHP以进程的形式存在。
PHP5.4下载地址:http://cn2.php.net/distributions/php-5.4.23.tar
二、安装编译环境
[root@Dynamic packets]# yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel
安装加密扩展库
[root@Dynamic packets]# tar zxvf libmcrypt-2.5.8.tar.gz
[root@Dynamic packets]# cd libmcrypt-2.5.8
[root@Dynamic libmcrypt-2.5.8]# ./configure
[root@Dynamic libmcrypt-2.5.8]#make & make install
三、安装PHP
[root@Dynamic php-5.5.36]# ./configure --prefix=/apps/php5.5.36 --with-config-file-path=/apps/php-5.5.36/etc --with-mysql=/apps/mysql --with-mysql-sock --with-mysqli=/apps/mysql/bin/mysql_config --enable-fpm --with-from-user=nginx --with-fpm-froup=nginx --with-ncurses --enable-soap --with-libxml-dir --with-XMLrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --disable-mbregex --disable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-pdo-mysql --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sqlite-utf8 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-bcmath
./configure --prefix=/apps/php-5.5.38 --with-config-file-path=/apps/php-5.5.38/etc --with-config-file-scan-dir=/apps/php-5.5.38/etc/php.d --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --with-gd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-xml --with-mhash --with-bz2 --with-mcrypt --with-curl --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-bcmath --with-gettext
(--with-from-user=nginx --with-fpm-group=nginx 要和php-fpm.conf里的user group一样,否则会提示权限错误)
为了支持apache的worker或event这两个MPM,编译时使用了–enable-maintainer-zts选项。
- php各参数配置详解
--prefix=/usr/local/php //指定 php 安装目录 --with-apxs2=/usr/local/apache/bin/apxs //整合apache,apxs功能是使用mod_so中的LoadModule指令,加载指定模块到 apache,要求 apache 要打开SO模块 --with-config-file-path=/usr/local/php/etc //指定php.ini位置 --with-MySQL=/usr/local/mysql //mysql安装目录,对mysql的支持 --with-mysqli=/usr/local/mysql/bin/mysql_config //mysqli扩展技术不仅可以调用MySQL的存储过程、处理MySQL事务,而且还可以使访问数据库工作变得更加稳定。 --enable-safe-mode //打开安全模式 --enable-ftp //打开ftp的支持 --enable-zip //打开对zip的支持 --with-bz2 //打开对bz2文件的支持 --with-jpeg-dir //打开对jpeg图片的支持 --with-png-dir //打开对png图片的支持 --with-freetype-dir //打开对freetype字体库的支持 --without-iconv //关闭iconv函数,各种字符集间的转换 --with-libXML-dir //打开libxml2库的支持 --with-XMLrpc //打开xml-rpc的c语言 --with-zlib-dir //打开zlib库的支持 --with-gd //打开gd库的支持 --enable-gd-native-ttf //支持TrueType字符串函数库 --with-curl //打开curl浏览工具的支持 --with-curlwrappers //运用curl工具打开url流 --with-ttf //打开freetype1.*的支持,可以不加了 --with-xsl //打开XSLT 文件支持,扩展了libXML2库 ,需要libxslt软件 --with-gettext //打开gnu 的gettext 支持,编码库用到 --with-pear //打开pear命令的支持,PHP扩展用的 --enable-calendar //打开日历扩展功能 --enable-mbstring //多字节,字符串的支持 --enable-bcmath //打开图片大小调整,用到zabbix监控的时候用到了这个模块 --enable-sockets //打开 sockets 支持 --enable-exif //图片的元数据支持 --enable-magic-quotes //魔术引用的支持 --disable-rpath //关闭额外的运行库文件 --disable-debug //关闭调试模式 --with-mime-magic=/usr/share/file/magic.mime //魔术头文件位置
- CGI方式安装才用的参数:
--enable-fpm //打上PHP-fpm 补丁后才有这个参数,CGI方式安装的启动程序 --enable-fastCGI //支持fastcgi方式启动PHP --enable-force-CGI-redirect //重定向方式启动PHP --with-ncurses //支持ncurses 屏幕绘制以及基于文本终端的图形互动功能的动态库 --enable-pcntl //freeTDS需要用到的,可能是链接mssql 才用到 --with-mcrypt //mcrypt算法的扩展 --with-mhash //mhash算法的扩展 //以上函数库需要安装 --with-gmp //应该是支持一种规范 --enable-inline-optimization //优化线程 --with-openssl //openssl的支持,加密传输时用到的 --enable-dbase //建立DBA 作为共享模块 --with-pcre-dir=/usr/local/bin/pcre-config //perl的正则库案安装位置 --disable-dmalloc --with-gdbm //dba的gdbm支持 --enable-sigchild --enable-sysvsem --enable-sysvshm --enable-zend-multibyte //支持zend的多字节 --enable-mbregex --enable-wddx --enable-shmop --enable-soap
创建软链接,方便多版本切换。
[root@Dynamic php-5.5.36]# ln -s /apps/php5.5.36/ /apps/php
四、支持apche
[root@Dynamic ~]# vim /apps/apache2.2.31/conf/httpd.conf LoadModule php5_module modules/libphp5.so AddType application/x-httpd-php .php .phtml AddType application/x-httpd-php-source .phps DirectoryIndex index.php index.html
五、支持Nginx
[root@Dynamic php-5.5.36]# vim conf/nginx.conf location ~ \.(php|php5)?$ { root html/www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; }
六、配置
拷贝配置文件
[root@Dynamic php-5.5.36]# cp /packets/php-5.5.36/php.ini-production /apps/php5.5.36/etc/php.ini [root@Dynamic php-5.5.36]# cp /apps/php5.5.36/etc/php-fpm.conf.default /apps/php5.5.36/etc/php-fpm.conf
编辑php.ini文件
[root@Dynamic php-5.5.36]# vim /apps/php5.5.36/etc/php.ini date.timezone = PRC、 short_open_tag = On
拷贝启动文件
[root@Dynamic php-5.5.36]# cp /packets/php-5.5.36/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm [root@Dynamic php-5.5.36]# chmod +x /etc/rc.d/init.d/php-fpm
查看PHP编译参数
[root@Dynamic php-5.5.36]# /apps/php/bin/php -i |grep configure Configure Command => './configure' '--prefix=/apps/php5.5.36' '--with-apxs2=/apps/apache2.2.31/bin/apxs' '--with-mysql=/apps/mysql' '--with-mysql-sock' '--with-mysqli=/apps/mysql/bin/mysql_config' '--enable-fpm' '--with-ncurses' '--enable-soap' '--with-XMLrpc' '--with-openssl' '--with-mcrypt' '--with-pcre-regex' '--with-sqlite3' '--with-zlib' '--enable-bcmath' '--with-iconv' '--with-bz2' '--enable-calendar' '--with-curl' '--with-cdb' '--enable-dom' '--enable-exif' '--enable-fileinfo' '--enable-filter' '--with-pcre-dir' '--enable-ftp' '--with-gd' '--with-openssl-dir' '--with-jpeg-dir' '--with-png-dir' '--with-freetype-dir' '--enable-gd-native-ttf' '--enable-gd-jis-conv' '--with-gettext' '--with-gmp' '--with-mhash' '--enable-json' '--enable-mbstring' '--disable-mbregex' '--disable-mbregex-backtrack' '--with-libmbfl' '--with-onig' '--enable-pdo' '--with-pdo-mysql' '--with-zlib-dir' '--with-pdo-sqlite' '--with-readline' '--enable-session' '--enable-shmop' '--enable-simplexml' '--enable-sockets' '--enable-sqlite-utf8' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--enable-wddx' '--with-libxml-dir' '--with-xsl' '--enable-zip' '--enable-mysqlnd-compression-support' '--with-pear'
七、启动。如果编译时没指定--with-config-file-path参数,启动时则一定要加 -c 参数指定配置文件,否则将会以默认配置启动,会导致安装了插件但没有加载。
[root@Dynamic php-5.5.36]# php-fpm -c /apps/php/etc/php.ini -y /apps/php/etc/php-fpm.conf
问题:PHP和mysql不在同一台服务器上,如何部署?
解决:
- 在安装PHP上的服务器同时安装mysql服务,但不需要mysql install初始化数据库
- 直接拷贝二进制文件的PHP软件
- 源码编译时加参数 --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd
生产环境插件的安装建议
- 功能性插件,如果开发人员没需求,可以暂时不用考虑,如:PDO_MYSQL、Memcache、imagick
- 性能优化插件:eaccelerator、xcache。任意安装一种
问题:数据库IP改了,连接不了
解决:
- 在程序源码里修改连接配置文件
- 在WEB服务器上配置hosts文件,连接数据库时用域名解析IP地址
问题:HTTP报502错误
解决:
PHP没启动。
没有帐号? 立即注册