LNMP环境配置之PHP篇 - 一、安装PHP7.1.7

17 篇文章 0 订阅
14 篇文章 0 订阅

1.个人习惯,我喜欢将开发的包都放在这个文件夹下

cd /usr/local/webserver

2.安装依赖包,下面依赖包应该比较齐全,足够MySQL和php使用了

yum -y install autoconf automake bison bzip2 bzip2-devel cmake curl epel-release fiex* freetype freetype-devel gcc gcc-c++ gcc-g77 gmp gmp-devel libcurl libcurl-devel libmcrypt* libmcrypt-devel libjpeg libjpeg-devel libpng libpng-devel libtool* libtool-ltdl-devel* libicu-devel libaio-devel libbz2-dev libcurl4-openssl-dev libmcrypt libmcrypt-devel libxml* libxml2 libxml2-devel libxslt libxslt-devel libxslt-devel* mcrypt mhash ncurses-devel openssl openssl-devel pcre-devel perl php-mcrypt postgresql-devel re2c readline readline-devel systemd-devel zlib* zlib-devel

3.为防止意外,更新依赖包

yum update

4.解压php7.1.7源文件

tar zxvf php-7.1.7.tar.gz

5.重命名文件夹

mv php-7.1.7 php-7.1.7.package

6.不要着急初始化。

先确定几件事,

(1).如果你的电脑已经装了MySQL,找到MySQL安装地址,确定mysql.sock、libmysqlclient.so和libmysqlclient.so.18的所在位置,最后的数字不一定是18,依据MySQL版本而定。

我的几个路径如下:

MySQL安装路径

/usr/local/webserver/mysql-5.6.16/

libmysqlclient.so和libmysqlclient.so.18的所在位置

/usr/local/webserver/mysql-5.6.16/lib/

mysql.sock的所在位置

/tmp/mysql.sock

初始化命令带上

--with-mysqli=/usr/local/webserver/mysql-5.6.16/bin/mysql_config \
--with-mysql-sock=/tmp/mysql.sock \
--with-pdo-mysql=/usr/local/webserver/mysql-5.6.16/bin/mysql \

因为我是centos系统所以执行以下软连接

ln -s /usr/local/webserver/mysql-5.6.16/lib/libmysqlclient.so /usr/lib/ \
ln -s /usr/local/webserver/mysql-5.6.16/lib/libmysqlclient.so.18 /usr/lib/

(2).如果还没装MySQL,初始化命令带上这三句

--with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd \
--with-mysql-sock \

7.进入文件夹,并初始化

cd php-7.1.7.package

初始化之前执行一下

./configure --help

 查看帮助文档,对于一下下面的初始化语句。理解一下每一行的用处具体是什么。要知其然还要知其所以然。

./configure \
--prefix=/usr/local/webserver/php-7.1.7 \
--with-bz2 \
--with-config-file-path=/usr/local/webserver/php-7.1.7/etc \
--with-cdb \
--with-curl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-gmp \
--with-iconv \
--with-iconv-dir \
--with-jpeg-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libmbfl \
--with-libxml-dir \
--with-mcrypt \
--with-mhash \
--with-mysqli=/usr/local/webserver/mysql-5.6.16/bin/mysql_config \
--with-mysql-sock=/tmp/mysql.sock \
--with-onig \
--with-openssl \
--with-openssl-dir \
--with-pcre-dir \
--with-pcre-regex \
--with-pdo-mysql=/usr/local/webserver/mysql-5.6.16/bin/mysql \
--with-pdo-sqlite \
--with-pear \
--with-pgsql \
--with-png-dir \
--with-readline \
--with-sqlite3 \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--with-zlib-dir \
--without-gdbm \
--enable-bcmath \
--enable-calendar \
--enable-debug \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--enable-fpm \
--enable-ftp \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--enable-inline-optimization \
--enable-json \
--enable-libxml \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--enable-mysqlnd \
--enable-mysqlnd-compression-support \
--enable-opcache \
--enable-pcntl \
--enable-pdo \
--enable-session \
--enable-shared \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-soap \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--enable-xml \
--enable-zip \
--disable-rpath

php7已经全面放弃mysql扩展,以更有效率的mysqlnd替代,如果你要用,加上这一行

--with-mysql=mysqlnd

--enable 是启用软件源码包自带 --enable-包名[=arg],但是默认不启用的功能模块。

--with 是指定依赖的资源库的位置 --with-依赖包名称[=依赖包目录],如果是默认位置,l路径就可以留空。

--prefix,初始化后php将安装到这个位置,请牢记,这个位置很重要

8.

make & make install

执行完,会神奇的发现php已经安装到

--prefix=/usr/local/webserver/php-7.1.7 \

这条命令定义的路径

9.进入路径检查php.ini和php-fpm.conf

php-fpm.conf应该是还没定义,复制一份。

cp php-fpm.conf.default php-fpm.conf
cd php-fpm.c
cp www.conf.default www.conf
cp /usr/local/webserver/php-7.1.7.package/php.ini-development /usr/local/webserver/php-7.1.7/etc/php.ini

10.测试php-fpm配置是否正确

/usr/local/webserver/php-7.1.7/sbin/php-fpm -t

如果正确会有以下提示

[04-Oct-2018 02:01:53] NOTICE: configuration file /usr/local/webserver/php-7.1.7/etc/php-fpm.conf test is successful

11.这一步是个人配置,每个人可能有所不同,我是根据我自己的习惯配置的,各位看官的配置不必完全一致

第一步:
cp /usr/local/webserver/php-7.1.7/sbin/php-fpm /etc/rc.d/init.d/php-fpm7107
第二步:
cp /usr/local/webserver/php-7.1.7.package/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm7107
第三步
vi /etc/rc.local //编辑配置文件

写下面两行
# Start PHP 7.1.7 Service
/etc/init.d/php-fpm7107 start

:wq
第四步:
chmod a+x /etc/rc.d/init.d/php-fpm7107
第五步:
chkconfig --add php-fpm7107
第六步:
chkconfig php-fpm7107 on
第七步 开启php-fpm
/etc/init.d/php-fpm7107 start

到此完成。得意

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值