centos7 離線安裝PHP及PHP相關擴充套件
1、安裝PHP7
下載php7(php-7.1.12.tar.gz)包匯入centos7 /data/rj
2.解壓包
tar -zxvf php-7.1.12.tar.gz
3.安裝php 之前需要安裝mcrypt
1).下載Libmcrypt,mhash,mcrypt安裝包
2) .先安裝Libmcrypt
tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
###/usr/local/php5/bin/phpize #動態編譯php模組,使其可以使用configure編譯。
./configure
make
make install # libmcript預設安裝在/usr/local
3).安裝mhash
tar -zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make
make install
4).安裝mcrypt
tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure
make
make install
注: 可能會出現的錯誤 configure: error: *** libmcrypt was not found解決方案
()安裝到mcrypt的時候出現了問題
./configure
提示出錯,首先提示
*** Could not run libmcrypt test program, checking why…
*** The test program failed to compile or link. See the file config.log for the
*** exact error that occured. This usually means LIBMCRYPT was incorrectly installed
*** or that you have moved LIBMCRYPT since it was installed. In the latter case, you
*** may want to edit the libmcrypt-config script: no
configure: error: *** libmcrypt was not found
找了相關資料,得出解決方法明明我安裝了libmcrypt 2.5.8 ,可是竟然提示沒有發現!然後在/usr/local/bin/找到了LIBMCRYPT_CONFIG ,這一步明確了是PATH變數的問題 !
方法是ln -s /usr/local/bin/libmcrypt_config /usr/bin/libmcrypt_config
之後繼續進行./configure
仍然報錯:
*** Could not run libmcrypt test program, checking why…
*** The test program compiled, but did not run. This usually means
*** that the run-time linker is not finding LIBMCRYPT or finding the wrong
*** version of LIBMCRYPT. If it is not finding LIBMCRYPT, you’ll need to set your
*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point
*** to the installed location Also, make sure you have run ldconfig if that
*** is required on your system
***
*** If you have an old version installed, it is best to remove it, although
*** you may also be able to get things to work by modifying LD_LIBRARY_PATH
***
configure: error: *** libmcrypt was not found
繼續查詢,還是變數的問題
解決方法如下:執行
export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH
然後make ; make install
完成
4.下載php及PHP擴充套件相關的包
這裡需要的包很多就不一一列出了, 可以檢視我的連結
連結: php相關擴充套件包 (https://pan.baidu.com/s/1XTowCqLTE4hDiGpE9hYmQw) 密碼: sqwr
也可以通過centos的映象包中查詢相關的rpm包
將已下載的相關包放到/data/other
rpm -Uvh /data/other/*.rpm --nodeps --force
注:--nodeps就是安裝時不檢查依賴關係,比如你這個rpm需要A,但是你沒裝A,這樣你的包就裝不上,
用了--nodeps你就能裝上了。--force就是強制安裝,比如你裝過這個rpm的版本1,如果你想裝這個
rpm的版本2,就需要用--force強制安裝
5. 切換到 php7解壓包後的目錄
cd php-7.1.12
如果已安裝mysql 可以加 --with-mysqli=/usr/bin/mysql_config --with-pdo-mysql=/usr/bin/mysql
./configure --prefix=/usr/local/php7 --with-config-file-path=/etc --with-bz2 --with-curl --with-gd --with-openssl -with-gettext --with-xsl --with-zlib-dir --enable-pcntl --enable-sockets --enable-calendar --enable-exif --enable-ftp --enable-mbstring --enable-fpm --enable-zip --with-mcrypt --with-mysqli=/usr/bin/mysql_config --with-pdo-mysql=/usr/bin/mysql
其中:###
--prefix=/usr/local/php7 將php7安裝到指定目錄
--enable-fpm 編譯 PHP 時需要 --enable-fpm 配置選項來啟用 FPM 支援。
如果安裝mysql
--with-mysqli=--with-mysqli=/usr/bin/mysql_config(檢視mysql_config位置)
--with-pdo-mysql=/usr/bin/mysql(檢視mysql安裝位置)
####
出現(Thank you for using PHP.即為成功)
make (如果看到Don't forget to run 'make test' 編譯成功)
make install
6. 測試PHP安裝是否成功
cd
vi test.php
<?php
phpinfo();
使用PHP命令執行test.php檔案
/usr/local/php7/bin/php test.php
cd /usr/local/php7/bin/
./php -m 檢視PHP已安裝的擴充套件包
配置環境變數
將 PHP放入環境變數才能執行 php xxx.php 否則執行php為 /usr/local/php7/bin/php test.php
vi /etc/profile
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
export PATH=$PATH:/usr/local/php7/bin
儲存後
source /etc/profile
php -v
php -m
重啟nginx
systemctl restart nginx
配置PHP
cp php.ini-production /usr/local/php7/etc/php.ini
vi /usr/local/php7/etc/php.ini
zend_extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/opcache.so
複製php-fpm.conf
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
vim /usr/local/php7/etc/php-fpm.conf
把pid 改成 /run/php-fpm.pid
編輯php-fpm配置www.conf會載入在php-fpm.conf中
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
加php-fpm管理器到systemctl中
vi /usr/lib/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/php7/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php7/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
儲存退出
重啟php
systemctl start php-fpm.service
systemctl enable php-fpm.service
systemctl is-enabled php-fpm.service
systemctl指令
systemctl enable *.service #開機執行服務
systemctl disable *.service #取消開機執行
systemctl is-enabled *.service #服務是否開機執行
systemctl start *.service #啟動服務
systemctl stop *.service #停止服務
systemctl restart *.service #重啟服務
systemctl reload *.service #重新載入服務配置檔案
systemctl status *.service #查詢服務執行狀態
systemctl --failed #顯示啟動失敗的服務
可以檢視:http://bbs.qcloud.com/thread-9907-1-1.html
修改php.ini
vi /usr/local/php7/etc/php.ini
expose_php=Off ##為了防止黑客獲取伺服器中php版本的資訊,可以關閉該資訊斜路在http頭中
error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE