一、安装依赖包和开发工具:
yum install vim vim-enhanced wget zip unzip telnet ntsysv compat* apr* nasm* gcc gcc* gcc-c++ ntp make imake cmake automake autoconf python-devel zlib zlib-devel glibc glibc-devel glib2 libxml glib2-devel libxml2 libxml2-devel bzip2 bzip2-devel libXpm libXpm-devel libidn libidn-devel libtool libtool-ltdl-devel* libmcrypt libmcrypt-devel libevent-devel libmcrypt* libicu-devel libxslt-devel postgresql-devel curl curl-devel perl perl-Net-SSLeay pcre pcre-devel ncurses ncurses-devel openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers krb5 krb5-devel e2fsprogs e2fsprogs-devel libjpeg libpng libjpeg-devel libjpeg-6b libjpeg-devel-6b libpng-devel libtiff-devel freetype freetype-devel fontconfig-devel gd gd-devel kernel screen sysstat flex bison nss_ldap pam-devel compat-libstdc++-
二、清除系统中php痕迹:
yum remove php rm -rvf /etc/php rm -rvf /etc/php.ini rm -rvf /usr/bin/php
三、安装php所需软件包:
tar zxvf autoconf-2.68.tar.gz -C /usr/src cd /usr/src/autoconf-2.68/ ./configure && make && make install tar zxvf libiconv-1.14.tar.gz -C /usr/src cd /usr/src/libiconv-1.14/srclib/ sed -i -e '/gets is a security/d' ./stdio.in.h cd /usr/src/libiconv-1.14/ ./configure && make && make install tar zxvf libmcrypt-.tar.gz -C /usr/src cd /usr/src/libmcrypt-/ ./configure && make && make install ldconfig cd libltdl/ ./configure --enable-ltdl-install make && make install export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH tar zxvf mhash-0.9.9.9.tar.gz -C /usr/src cd /usr/src/mhash-0.9.9.9/ ./configure && make && make install tar zxvf mcrypt-.tar.gz -C /usr/src cd /usr/src/mcrypt-/ ./configure && make && make install
四、加载php动态模块:
ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la ln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so ln -s /usr/local/lib/libmcrypt.so. /usr/lib64/libmcrypt.so. ln -s /usr/local/lib/libmcrypt.so. /usr/lib64/libmcrypt.so. ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.a ln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.la ln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.so ln -s /usr/local/lib/libmhash.so. /usr/lib64/libmhash.so. ln -s /usr/local/lib/libmhash.so. /usr/lib64/libmhash.so. cp -R /usr/lib64/libpng.* /usr/lib/ cp -R /usr/lib64/libjpeg.* /usr/lib/
五、配置模块认证:
echo "/lib" >> /etc/ld.so.conf echo "/usr/lib" >> /etc/ld.so.conf echo "/usr/lib64" >> /etc/ld.so.conf echo "/usr/local/lib" >> /etc/ld.so.conf echo "* soft nproc 65535" >> /etc/security/limits.conf echo "* hard nproc 65535" >> /etc/security/limits.conf echo "* soft nofile 65535" >> /etc/security/limits.conf echo "* hard nofile 65535" >> /etc/security/limits.conf echo "fs.file-max=65535" >> /etc/sysctl.conf ldconfig
六、解压、配置、编译、安装php:
tar zxvf php-.tar.gz -C /usr/src cd /usr/src/php-/ ./configure --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --with-fpm-user=www \ --with-fpm-group=www \ --with-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-pgsql \ --with-iconv \ --with-iconv-dir=/usr/ \ --with-freetype-dir=/usr/ \ --with-jpeg-dir=/usr/ \ --with-png-dir=/usr/ \ --with-libxml-dir=/usr \ --with-gettext \ --with-gd \ --with-pear \ --with-curl \ --with-zlib \ --with-zlib-dir \ --with-mcrypt \ --with-mhash \ --with-openssl \ --with-xmlrpc \ --with-xsl \ --with-pcre-regex \ --with-kerberos \ --enable-fpm \ --enable-opcache \ --enable-gd-native-ttf \ --enable-exif \ --enable-mysqlnd \ --enable-ftp \ --enable-zip \ --enable-sockets \ --enable-static \ --enable-xml \ --enable-xmlreader \ --enable-xmlwriter \ --enable-soap \ --enable-mbstring \ --enable-bcmath \ --enable-sysvshm \ --enable-sysvsem \ --enable-intl \ --enable-wddx \ --enable-shmop \ --enable-pcntl \ --enable-mbregex \ --enable-calendar \ --enable-inline-optimization \ --disable-maintainer-zts \ --disable-ipv6 \ --disable-rpath \ --disable-debug \ --disable-fileinfo make ZEND_EXTRA_LIBS='-liconv' make install
七、链接php可执行文件:
ln -s /usr/local/php/bin/php /usr/bin/php ln -s /usr/local/php/bin/phpize /usr/bin/phpize ln -s /usr/local/php/sbin/php-fpm /usr/bin/php-fpm
八、创建php相关目录:
mkdir -p /home/php/log mkdir -p /home/php/pid
九、编辑php.ini配置文件:
cp /usr/src/php-/php.ini-production /usr/local/php/etc/php.ini ln -s /usr/local/php/etc/php.ini /etc/php.ini vim /etc/php.ini
[PHP] engine = On short_open_tag = On asp_tags = Off precision = output_buffering = On output_buffering = zlib.output_compression = Off implicit_flush = Off unserialize_callback_func= serialize_precision = disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket disable_classes = zend.enable_gc = On expose_php = Off max_execution_time = max_input_time = memory_limit = 512M error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT display_errors = Off display_startup_errors = Off log_errors = On log_errors_max_len = ignore_repeated_errors = Off ignore_repeated_source = Off report_memleaks = On track_errors = Off html_errors = On variables_order = "EGPCS" request_order = "CGP" register_globals = Off register_long_arrays = Off register_argc_argv = Off auto_globals_jit = On post_max_size = 100M auto_prepend_file = auto_append_file = default_mimetype = "text/html" default_charset = "UTF-8" doc_root = user_dir = extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/" open_basedir = enable_dl = Off cgi.fix_pathinfo= file_uploads = On upload_max_filesize = 50M max_execution_time = allow_url_fopen = On allow_url_include = Off default_socket_timeout = safe_mode = Off [CLI Server] cli_server.color = On [Date] date.timezone = Asia/Shanghai [filter] [iconv] [intl] [sqlite] [Pcre] [Pdo] [Pdo_mysql] pdo_mysql.cache_size = pdo_mysql.default_socket= [Phar] [mail function] [Syslog] define_syslog_variables = Off [mail function] SMTP = localhost smtp_port = sendmail_path = /usr/sbin/sendmail -t -i mail.add_x_header = On [SQL] sql.safe_mode = Off [ODBC] odbc.allow_persistent = On odbc.check_persistent = On odbc.max_persistent = - odbc.max_links = - odbc.defaultlrl = odbc.defaultbinmode = [Interbase] ibase.allow_persistent = ibase.max_persistent = - ibase.max_links = - ibase.timestampformat = "%Y-%m-%d %H:%M:%S" ibase.dateformat = "%Y-%m-%d" ibase.timeformat = "%H:%M:%S" [MySQL] mysql.allow_persistent = On mysql.allow_local_infile = On mysql.cache_size = mysql.max_persistent = - mysql.max_links = - mysql.default_port = mysql.default_socket = mysql.default_host = mysql.default_user = mysql.default_password = mysql.connect_timeout = mysql.trace_mode = Off [MySQLi] mysqli.max_links = - mysqli.allow_persistent = On mysqli.max_links = - mysqli.cache_size = mysqli.default_port = mysqli.default_socket = mysqli.default_host = mysqli.default_user = mysqli.default_pw = mysqli.reconnect = Off [mSQL] msql.allow_persistent = On msql.max_persistent = - msql.max_links = - [mysqlnd] mysqlnd.collect_statistics = On mysqlnd.collect_memory_statistics = Off [OCI8] [PostgresSQL] pgsql.allow_persistent = On pgsql.auto_reset_persistent = Off pgsql.max_persistent = - pgsql.max_links = - pgsql.ignore_notice = pgsql.log_notice = [Sybase] sybase.allow_persistent = On sybase.max_persistent = - sybase.max_links = - sybase.min_error_severity = sybase.min_message_severity = sybase.compatability_mode = Off [Sybase-CT] sybct.allow_persistent = On sybct.max_persistent = - sybct.max_links = - sybct.min_server_severity = sybct.min_client_severity = [bcmath] bcmath.scale = [browscap] [Informix] ifx.default_host = ifx.default_user = ifx.default_password = ifx.allow_persistent = On ifx.max_persistent = - ifx.max_links = - ifx.textasvarchar = ifx.byteasvarchar = ifx.charasvarchar = ifx.blobinfile = ifx.nullformat = [Session] session.save_handler = files session.save_path = "/tmp" session.use_strict_mode = session.use_cookies = session.use_only_cookies = session.name = PHPSESSID session.auto_start = session.cookie_lifetime = session.cookie_path = / session.cookie_domain = session.cookie_httponly = session.serialize_handler = php session.gc_probability = session.gc_divisor = session.gc_maxlifetime = session.referer_check = session.entropy_length = session.entropy_file = session.cache_limiter = nocache session.cache_expire = session.use_trans_sid = session.hash_function = session.hash_bits_per_character = url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry" [MSSQL] mssql.allow_persistent = On mssql.max_persistent = - mssql.max_links = - mssql.min_error_severity = mssql.min_message_severity = mssql.compatability_mode = Off mssql.secure_connection = Off [Assertion] [COM] [mbstring] [FrontBase] [gd] [exif] [Tidy] tidy.clean_output = Off [soap] soap.wsdl_cache_enabled= soap.wsdl_cache_dir="/tmp" soap.wsdl_cache_ttl= soap.wsdl_cache_limit = [sysvshm] [ldap] ldap.max_links = - [mcrypt] [dba] [opcache] [curl] [openssl]
十、配置php-fpm.conf配置文件:
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf vim /etc/php-fpm.conf
;;;;;;;;;;;;;;;;;;;; FPM Configuration ;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;; Global Options ;;;;;;;;;;;;;;;;;;;; [global] pid = /home/php/pid/php-fpm.pid error_log = /home/php/log/php-fpm_error.log log_level = warning emergency_restart_threshold = emergency_restart_interval = 60s process_control_timeout = 5s daemonize = yes ;;;;;;;;;;;;;;;;;;;; Pool Definitions ;;;;;;;;;;;;;;;;;;;; [www] listen = /dev/shm/php-cgi.sock listen.backlog = - listen.allowed_clients = 127.0.0.1 listen.owner = www listen.group = www listen.mode = user = www group = www pm = dynamic pm.max_children = pm.start_servers = pm.min_spare_servers = pm.max_spare_servers = pm.max_requests = pm.process_idle_timeout = 10s request_terminate_timeout = request_slowlog_timeout = pm.status_path = /php-fpm_status ping.path = /php-fpm_ping ping.response = pong slowlog = /home/php/log/slow.log rlimit_files = rlimit_core = catch_workers_output = yes ;env[HOSTNAME] = $HOSTNAME env[PATH] = /usr/local/bin:/usr/bin:/bin env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmp
十一、编写php-fpm启动脚本:
vim /etc/init.d/php-fpm
#!/bin/sh # chkconfig: # Description: Start and Stop php-fpm # Provides: php-fpm # Default-Start: # Default-Stop: prefix=/usr/local/php exec_prefix=${prefix} php_fpm_BIN=${prefix}/sbin/php-fpm php_fpm_CONF=${prefix}/etc/php-fpm.conf php_fpm_PID=/home/php/pid/php-fpm.pid php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID" wait_for_pid () { ; do case "$1" in 'created') if [ -f "$2" ] ; then try='' break fi ;; 'removed') if [ ! -f "$2" ] ; then try='' break fi ;; esac echo -n . ` sleep done } case "$1" in start) echo -n "Starting php-fpm..." $php_fpm_BIN --daemonize $php_opts ] ; then echo " failed" exit fi wait_for_pid created $php_fpm_PID if [ -n "$try" ] ; then echo " failed" exit else echo " done" fi ;; stop) echo -n "Stoping php-fpm..." if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit fi kill -QUIT `cat $php_fpm_PID` wait_for_pid removed $php_fpm_PID if [ -n "$try" ] ; then echo " failed. Use force-quit" exit else echo " done" fi ;; force-quit) echo -n "Terminating php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit fi kill -TERM `cat $php_fpm_PID` wait_for_pid removed $php_fpm_PID if [ -n "$try" ] ; then echo " failed" exit else echo " done" fi ;; restart) $ stop $ start ;; reload) echo -n "Reload service php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit fi kill -USR2 `cat $php_fpm_PID` echo " done" ;; *) echo "Usage: $0 {start|stop|force-quit|restart|reload}" exit ;; esac
十二、添加php-fpm系统服务:
chmod a+x /etc/init.d/php-fpm chkconfig --add php-fpm chkconfig --level php-fpm on chkconfig --list | grep php-fpm
十三、启动php-fpm服务:
service php-fpm start ps -aux | grep php-fpm
十四、测试:
vim /home/www/html/index.php
<?php phpinfo(); ?>
chown www:www /home/www/html/index.php