php
cd /usr/local/src
wget http://cn2.php.net/get/php-7.2.9.tar.gz/from/this/mirror
ls = mirror
tar -zxvf mirror =解压
cd php-7.2.9
查看编译PHP的相关信息(编译的PHP要有功能:连接mysql,gd,ttf(字体-验证码),以及fpm(fastcgi)方式运行)
./configure --prefix=/usr/local/php\
--with-curl\
--enable-mysqlnd \
--with-gd \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--enable-fpm
nginx + php的编译
apache 一般是把PHP当做自己的一个模块来启动的,而nginx则是把http请求变量(如 get,user_agent等)转发给PHP进程,即PHP独立进程,与nginx进行通信,成为fastcgi运行方式;
Apache所编译的PHP是不能用于nginx;nginx把请求的信息转发个9000端口的PHP进程,让PHP进程处理指定目录下的PHP文件;
yum install libxml2;
yum -y install openssl
yum -y install openssl-devel
yum -y install curl
yum -y install curl-devel
yum -y install libjpeg
yum -y install libjpeg-devel
yum -y install libpng
yum -y install libpng-devel
yum -y install freetype
yum -y install freetype-devel
yum -y install pcre
yum -y install pcre-devel
yum -y install libxslt
yum -y install libxslt-devel
yum -y install bzip2
yum -y install bzip2-devel
配置扩展pdo
./configure --with-php-config=/usr/local/php/bin/php-config --enable-pdo=shared
配置pdo_mysql[Mysql的安装目录为/usr/local/mysql]
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-gd-jis-conv --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip等
提示如果缺少库,则需要依赖的库如:libpng,devel包没安装;
yum install libpng
yum install libpng-devel
安装依赖库齐全后,重新编译OK如下
make 编译时间可能会有点长(大约15分钟),编译完成之后: echo $? 0: 编译完成
执行安装:make install
php的默认安装位置上面已经指定为/usr/local/php,接下来配置相应的文件:
cp php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp sapi/fpm/php-fpm /usr/local/bin
然后设置php.ini,使用: vim /usr/local/php/lib/php.ini 打开php配置文件找到cgi.fix_pathinfo配置项,这一项默认被注释并且值为1,根据官方文档的说明,这里为了当文件不存在时,阻止Nginx将请求发送到后端的PHP-FPM模块,从而避免恶意脚本注入的攻击,所以此项应该去掉注释并设置为0
启动php-fpm:error:
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
/usr/local/php/sbin/php-fpm -t
(cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm
/etc/init.d/php-fpm)
修改nginx配置: vim /usr/local/nginx/conf/nginx.conf,重启nginx服务;
创建phpinfo.php测试文件,访问:
安装Composer: curl -sS https://getcomposer.org/installer | /usr/local/php/bin/php
mv composer.phar /usr/local/bin/composer
主要是php安装文件不在/usr/local/bin。安装在/usr/local/php中,找到php的可执行文件,/usr/local/php/bin/php,把可执行文件连接过去就可以了。
ln -s /usr/local/php/bin/php /usr/local/bin/php