centos 7 安装PHP 7.* 步骤

PHP官网下载适合的版本 ,文中所用版本 http://am1.php.net/get/php-7.1.18.tar.gz/from/this/mirror

下载  PHP

wget  -0 php-7.1.18.tar.gz http://am1.php.net/get/php-7.1.18.tar.gz/from/this/mirror
tar -zxvf php-7.1.18.tar.gz

安装依赖

yum install -y 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

添加用户和用户组

groupadd -r nginx
useradd -r -g nginx -s /sbin/nologin nginx

编译配置

./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--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

编译安装

make && make install

配置环境变量

在/etc/profile末尾追加

export PATH=$PATH:/usr/local/php/bin

执行文件

source /etc/profile

查看php版本

php -v

配置php-fpm

安装完成后可以通过sapi/fpm/php-fpm.server来启动php-fpm了。不过为了以后管理方便,通常需要将配置文件统一放到/etc目录下,并将php-fpm.server添加至systemctl服务。如下

mkdir -p /etc/php-fpm.d
cp php.ini-production /etc/php.ini
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
cp /usr/local/php/etc/php-fpm.conf.derault /etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
修改/usr/lib/systemd/system/php-fpm.service文件使其执行正确的路径,如下:
vi /usr/lib/systemd/system/php-fpm.service
# It's not recommended to modify this file in-place, because it
# will be overwritten during upgrades. If you want to customize,
# the best way is to use the "systemctl edit" command.
  
[Unit]
Description=The PHP FastCGI Process Manager
After=network.target
  
[Service]
Type=simple
PIDFile=/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target

开机启动

systemctl enable php-fpm.service

启动php-fpm

  systemctl start php-fpm.service                                                                  


猜你喜欢

转载自blog.csdn.net/qazx123q/article/details/80776957