一、PHP简介
PHP是一种创建动态交互性站点的强有力的服务器端脚本语言。PHP是目前动态网页开发中使用最为广泛的语言之一。PHP能运行在包括Windows、Linux等在内的绝大多数操作系统环境中
PHP是免费的,并且使用非常广泛。同时,对于像微软 ASP 这样的竞争者来说,PHP 无疑是另一种高效率的选项。
给大家介绍下CentOS 7.4下如何通过编译去安装php7.1.5,教程为本人亲测。
1、下载php-7.1.5软件包
下载地址:https://mirrors.yangxingzhen.com/php/php-7.1.5.tar.gz
[root@localhost ~]# wget -c https://mirrors.yangxingzhen.com/php/php-7.1.5.tar.gz
2、解压php7
[root@localhost ~]# tar zxf php-7.1.5.tar.gz
3、移动解压之后的文件夹到/usr/local/
[root@localhost ~]# mv php-7.1.5 /usr/local/php
4、进入php目录
[root@localhost ~]# cd /usr/local/php
5、安装依赖包
[root@localhost php]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
6、编译配置(如果出现错误,基本都是上一步的依赖文件没有安装所致),嫌麻烦的可以从这一步起参考PHP官方安装说明:http://php.net/manual/zh/install.unix.nginx.php (极简安装)
[root@localhost php]# ./configure /
--prefix=/usr/local/php /
--with-config-file-path=/etc /
--enable-fpm /
--with-fpm-user=www /
--with-fpm-group=www /
--enable-inline-optimization /
--disable-debug /
--disable-rpath /
--enable-shared /
--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 /
--enable-mbregex /
--enable-mbregex-backtrack /
--with-libmbfl /
--with-onig /
--enable-pdo /
--with-mysqli=mysqlnd /
--with-pdo-mysql=mysqlnd /
--with-zlib-dir /
--with-pdo-sqlite /
--with-readline /
--enable-session /
--enable-shmop /
--enable-simplexml /
--enable-sockets /
--enable-sysvmsg /
--enable-sysvsem /
--enable-sysvshm /
--enable-wddx /
--with-libxml-dir /
--with-xsl /
--enable-zip /
--enable-mysqlnd-compression-support /
--with-pear /
--enable-opcache
7、正式安装
[root@localhost php]# make && make install
8、配置php-fpm
[root@localhost php]# cp php.ini-production /etc/php.ini
[root@localhost php]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost php]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
[root@localhost php]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php]# chmod +x /etc/init.d/php-fpm
9、创建www用户,启动php-fpm
[root@localhost php]# useradd www
[root@localhost php]# /etc/init.d/php-fpm start
至此就已经安装好php7.1.5了,希望可以帮助到大家。如需转载请注明出处。
附一键安装脚本,脚本内容如下:
#!/bin/bash
#2019-6-7 09:58:44
#Author blog:
# https://nuoyo.cn
#Author site:
# https://nuoyo.cn/sitemap.html
#Author mirrors site:
# https://mirrors.yangxingzhen.com
#About the Author
# BY:、、、小柒
# QQ:675583110
# Mail:675583110@qq.com
#Auto Install PHP-7 Soft
PHP_URL=https://mirrors.yangxingzhen.com/php
PHP_FILE=php-7.1.5.tar.gz
PHP_FILE_DIR=php-7.1.5
PHP_PREFIX=/usr/local/php
USER=www
function install_php {
if [ ! -d ${PHP_PREFIX} ];then
wget -c ${PHP_URL}/${PHP_FILE}
tar zxf ${PHP_FILE}
mv ${PHP_FILE_DIR} ${PHP_PREFIX}
cd ${PHP_PREFIX}
#安装依赖包
yum –y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
./configure /
--prefix=/usr/local/php /
--with-config-file-path=/etc /
--enable-fpm /
--with-fpm-user=${USER} /
--with-fpm-group=${USER} /
--enable-inline-optimization /
--disable-debug /
--disable-rpath /
--enable-shared /
--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 /
--enable-mbregex /
--enable-mbregex-backtrack /
--with-libmbfl /
--with-onig /
--enable-pdo /
--with-mysqli=mysqlnd /
--with-pdo-mysql=mysqlnd /
--with-zlib-dir /
--with-pdo-sqlite /
--with-readline /
--enable-session /
--enable-shmop /
--enable-simplexml /
--enable-sockets /
--enable-sysvmsg /
--enable-sysvsem /
--enable-sysvshm /
--enable-wddx /
--with-libxml-dir /
--with-xsl /
--enable-zip /
--enable-mysqlnd-compression-support /
--with-pear /
--enable-opcache
if [ $? -eq 0 ];then
make && make install
else
exit 1
fi
fi
}
function config_php {
cp php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
useradd ${USER}
/etc/init.d/php-fpm start
}
install_php
config_php