1、准备工作
安装 libmcrypt-2.5.8
安装 mhash-0.9.9.9
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
LD_LIBRARY_PATH=/usr/local/lib ./configure
make
make install
yum -y install libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype \
freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2-devel \
ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl \
openssl-devel openldap openldap-devel
2、安装
tar zxvf php-2.7.9.tar.gz
cd php-2.7.9
./configure --help
Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
--datadir=DIR read-only architecture-independent data [DATAROOTDIR]
--infodir=DIR info documentation [DATAROOTDIR/info]
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
--mandir=DIR man documentation [DATAROOTDIR/man]
--docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE]
--htmldir=DIR html documentation [DOCDIR]
--dvidir=DIR dvi documentation [DOCDIR]
--pdfdir=DIR pdf documentation [DOCDIR]
--psdir=DIR ps documentation [DOCDIR]
# yum install openldap* compat-openldap
# cp -frp /usr/lib64/libldap* /usr/lib
Configure PHP. Remove any options you don't need (like MySQL or Postgres (--with-pdo-pgsql))
./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-mbstring \
--disable-debug \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--enable-mbregex \
--with-mhash \
--with-pcre-regex \
--with-gd \
--with-jpeg-dir \
--with-freetype-dir \
--enable-calendar \
--enable-bcmath \
--with-ldap \
--with-gettext \
--enable-mysqlnd \
--with-mysqli \
--with-pdo-mysql \
--with-pdo-mysql=mysqlnd \
--enable-bcmath \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-zip \
--with-zlib \
--with-curl \
--with-pear \
--with-openssl \
--enable-pcntl
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
config.status: creating php7.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/www.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
make
出现错误:/usr/bin/ld: ext/ldap/.libs/ldap.o: undefined reference to symbol 'ber_scanf'
vi Makefile
/^EXTRA_LIBS
行尾加上 “-llber”,存盘退出
compile the binaries by typing: make
If no errors, install by typing: make install
Copy the PHP.ini file to the install directory
cp php.ini-development /usr/local/php/lib/
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/www.conf
cp php.ini-production /usr/local/php/etc/php.ini
create symbolic links for your for your binary files
# cd /usr/bin/
# ln -s /usr/local/php/bin/php php
# ln -s /usr/local/php/bin/php-cgi php-cgi
# ln -s /usr/local/php/bin/php-config php-config
# ln -s /usr/local/php/bin/phpize phpize
# ln -s /usr/local/php/bin/phar.phar phar
# ln -s /usr/local/php/bin/pear pear
# ln -s /usr/local/php/bin/phpdbg phpdbg
# cd /usr/sbin/
# ln -s /usr/local/php/sbin/php-fpm php-fpm
# chown -R www.www php
3、启动 PHP-FPM
# php-fpm
# ps -aux|grep php-fpm
root 7943 0.0 0.0 218948 6240 ? Ss 14:15 0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
www 7944 0.0 0.0 218948 5988 ? S 14:15 0:00 php-fpm: pool www
www 7945 0.0 0.0 218948 5788 ? S 14:15 0:00 php-fpm: pool www
# netstat -an|grep 0.0.0.0
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
cat php/var/log/php-fpm.log
[10-Sep-2018 14:15:13] NOTICE: fpm is running, pid 7943
[10-Sep-2018 14:15:13] NOTICE: ready to handle connections
4、调整防火墙
iptables -I INPUT 5 -p tcp -i lo --sport 9000 -j ACCEPT
iptables -I INPUT 5 -p tcp -i lo --dport 9000 -j ACCEPT
iptables -I OUTPUT 5 -p tcp -o lo --sport 9000 -j ACCEPT
iptables -I OUTPUT 5 -p tcp -o lo --dport 9000 -j ACCEPT
service iptables save
5、调整nginx配置,支持php
vi nginx.conf
location / {
root html;
index index.php index.html index.htm;
}
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;
}
# systemctl stop nginx
# systemctl start nginx
cat /usr/local/nginx/html
cat phpinfo.php
# cat phpinfo.php
<?php
phpinfo();
php?>
在浏览器输入 http://ip/phpinfo.php
6、开机启动
#vi php-fpm.conf
pid = run/php-fpm.pid
#vi /etc/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
#systemctl enable php-fpm
#systemctl start php-fpm