1.下載下傳PHP源碼檔案
通過wget下載下傳源碼
PHP版本以及下載下傳位址可以去 http://php.net/downloads.php 選擇,這裡我們以7.1.19來示範
cd /usr/local/src/
wget -O php-7.1.19.tar.gz http://cn2.php.net/get/php-7.1.19.tar.gz/from/this/mirror
安裝如出現下面這個wget未找到
使用yum 安裝一下wget
yum -y install wget
然後再下載下傳PHP
下載下傳完畢!
2.安裝PHP
先将檔案解壓
tar -zxvf php-7.1.19.tar.gz
解壓之後得到一個檔案夾,進入這個檔案夾
cd php-7.1.19
安裝之前先安裝一些支援庫
yum -y install gcc
yum -y install openssl openssl-devel
yum -y install curl-devel
yum -y install libjpeg-devel
yum -y install libpng-devel
yum -y install freetype-devel
yum -y install libxslt-devel
yum -y install libxml2 libxml2-devel
yum -y install epel-release
yum -y install libmcrypt-devel
配置PHP
./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc/ \
--with-curl \
--with-freetype-dir \
--with-gd \
--with-jpeg-dir \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-mysqli \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-gd-native-ttf \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip
編譯安裝
make && make install
拷貝配置檔案到PHP目錄
cp php.ini-production /usr/local/php/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
3.開啟php-fpm開機自啟動
vi /etc/systemd/system/php-fpm.service
寫入如下代碼
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
啟動php-fpm
systemctl start php-fpm.service
添加到開機啟動
systemctl enable php-fpm.service
4.配置環境變量
vi /etc/profile
把
PATH=$PATH:/usr/local/php/bin:
export PATH
放到檔案最後面
儲存退出
執行指令使配置生效
source /etc/profile
執行
php -v
檢視PHP資訊
安裝完畢