php7文件下载:https://download.csdn.net/download/qq_36490086/11185621
php安装
1.解压,重命名(便于之后操作)
tar -xzxvf php-7.0.9.tar.gz
mv php-7.0.9 php7
cd php7
2.安装依赖
yum -y install gcc libxml2 libxml2-devel httpd-devel.x86_64 openssl openssl-devel curl-devel libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 libjpeg-devel bzip2-devel.x86_64 libXpm-devel gmp-devel icu libicu libicu-devel epel-release php-mcrypt libmcrypt libmcrypt-devel postgresql-devel libxslt-devel
3.配置安装选项
./configure \
--prefix=/usr/local/php7 \
--exec-prefix=/usr/local/php7 \
--bindir=/usr/local/php7/bin \
--sbindir=/usr/local/php7/sbin \
--includedir=/usr/local/php7/include \
--libdir=/usr/local/php7/lib/php \
--mandir=/usr/local/php7/php/man \
--with-config-file-path=/usr/local/php7/etc \
--with-mysql-sock=/var/lib/mysql/mysql.sock \
--with-mcrypt=/usr/include \
--with-mhash \
--with-openssl \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gd \
--with-iconv \
--with-zlib \
--enable-zip \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir \
--enable-opcache \
--enable-fpm \
--enable-fastcgi \
--with-fpm-user=apache \
--with-fpm-group=apache \
--without-gdbm \
--with-mcrypt=/usr/local/lib/libmcrypt \
--disable-fileinfo \
--with-apxs2=/usr/bin/apxs \
--enable-mbstring
4.编译安装,耐心等待
make && make install
5.配置php
cp php.ini-production /usr/local/php7/etc/php.ini
cp /root/php7/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
cd /usr/local/php7/lib/php/extensions/
ls
查看下面的文件名,比如我的是no-debug-non-zts-20151012
vim /usr/local/php7/etc/php.ini
在php.ini中找到extension_dir = "./"修改为:
extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/"
6.添加php变量
echo -e '\nexport PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH\n' >> /etc/profile && source /etc/profile
7.安装并配置php-fpm
yum -y install php-fpm
mkdir -p /var/log/php-fpm/ && mkdir -p /var/run/php-fpm && cd /var/run/ && chown -R root:root php-fpm
8.修改session配置开机启动
mkdir -p /var/lib/php/session
chown -R apache:apache /var/lib/php
systemctl start php-fpm
systemctl enable php-fpm
9.重点:配置Apache解析php文件并自动关联
vim /etc/httpd/conf/httpd.conf
找到:DirectoryIndex index.html改为:DirectoryIndex index.html index.htm index.php
找到:AddType application/x-gzip .gz .tgz在该行下面添加:AddType application/x-httpd-php .php
重启Apache:systemctl restart httpd
参考内容:https://blog.csdn.net/u010347814/article/details/81502867