[CentOs 7] - 安装php

一. 软件源安装

  1. 添加源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
  1. 安装php以及扩展
yum install php70w php70w-cli php70w-common php70w-devel
yum install php70w-embedded php70w-fpm php70w-gd php70w-mbstring php70w-mysql php70w-opcache php70w-pdo php70w-xml
  1. 修改配置文件
    此处配置文件在etc目录下的php.ini
vim /etc/php.ini

二. 源码安装

  1. 安装需要的软件
yum install -y gcc-c++ libc-devel pcre-devel linux-headers curl gnupg
yum install -y pcre pcre-devel openssl openssl-devel zlib zlib-devel
yum install -y gd gd-devel geoip geoip-devel libxslt-devel wget
  1. 下载源码并解压
wget -c http://docs.php.net/distributions/php-7.0.31.tar.gz -O php-7.0.31.tar.gz
tar -zxvf /usr/src/php-7.0.31.tar.gz
  1. 进入解压缩的源码目录
cd php-7.0.31
  1. 预编译
    根据自己需要添加模块和设置
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --modules-path=/usr/local/nginx/modules
 --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/usr/local/nginx/logs/error.log
 --http-log-path=/usr/local/nginx/logs/access.log --pid-path=/usr/local/nginx/run/nginx.pid
 --lock-path=/usr/local/nginx/run/nginx.lock --with-http_ssl_module --with-http_realip_module
 --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module
 --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module
 --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module
 --with-http_auth_request_module --with-http_xslt_module=dynamic
 --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-threads
 --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-stream_realip_module
 --with-stream_geoip_module=dynamic --with-http_slice_module --with-mail --with-mail_ssl_module
 --with-compat --with-file-aio --with-http_v2_module
  1. 编译安装
make -j2 # 一般是CPU核心数的两倍,用于加快编译速度
make install

你可能感兴趣的:([CentOs 7] - 安装php)