天天看點

CentOS7.3下安裝PHP5.6.30服務(轉)

原文出處:

https://blog.csdn.net/hemin1003/article/details/77434862

關于php-fpm

nginx本身不能處理PHP,它隻是個web伺服器,當接收到請求後,如果是php請求,則發給php解釋器處理,并把結果傳回給用戶端。

nginx一般是把請求發fastcgi管理程序處理,fascgi管理程序選擇cgi子程序處理結果并傳回被nginx。

PHP-FPM是一個PHP FastCGI管理器,是隻用于PHP的。

PHP在 5.3.3 之後已經講php-fpm寫入php源碼核心了。是以已經不需要另外下載下傳了。

擷取PHP下載下傳位址

打開php的官網:http://php.NET/,檢視php的版本清單

CentOS7.3下安裝PHP5.6.30服務(轉)

右擊,複制連結位址,在遠端主機登入,下載下傳該軟體(我選的是Australia的主機mirror下載下傳的)

# wget  http://au1.php.net/get/php-5.6.30.tar.gz/from/this/mirror      

下載下傳下來的是一個mirror檔案,改成我們需要的檔案名

#mv mirror php-5.6.30.tar.gz
#tar zxvf php-5.6.30.tar.gz
#cd php-5.6.30      

配置安裝

進入到目錄,我們需要在安裝的時候将安裝目錄配置到/usr/local/php/裡

#./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-MySQL --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      

配置的過程中可能會報如下錯誤

錯誤1:

xml2-config not found. Please check your libxml2 installation.      

解決辦法

安裝libxml2相關元件

#yum install libxml2
#yum install libxml2-devel -y      

錯誤2:

Please reinstall the libcurl distribution -
    easy.h should be in <curl-dir>/include/curl/      

安裝curl相關元件

#yum install curl curl-devel      

錯誤3:

configure: error: png.h not found.      

安裝libpng相關元件

#yum install libpng
#yum install libpng-devel      

錯誤4:

freetype-config not found.      

安裝freetype相關元件

#yum install freetype-devel      

錯誤5:

xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution      

安裝libxslt相關元件

#yum install libxslt-devel      

好的,當我們看到下面這句話的時候,說明你的php已經配置完成啦!

CentOS7.3下安裝PHP5.6.30服務(轉)

接下來我們隻需要編譯安裝即可完成php的安裝

#make && make install      

看到這句話,表明安裝完成!

CentOS7.3下安裝PHP5.6.30服務(轉)

為了保險起見,我們make test一把,看看是否真的成功了。

配置相關

php.ini配置

首先我們需要配置的是php.ini這個檔案

安裝目錄有2個檔案:php.ini-development和php.ini-production

php.ini-production 線上版本使用

php.ini-development 開發版本使用

我們選擇production進行配置

# cp -a php.ini-production /usr/local/php/etc/php.ini      //拷貝安裝包裡的php配置檔案到安裝目錄下      
# rm -rf /etc/php.ini      //删除預設的php配置檔案      
# ln -s /usr/local/php/etc/php.ini /etc/php.ini       //建立軟連結      

php-fpm配置

拷貝php-fpm啟動配置檔案

# cp -a ./sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf     //拷貝安裝包裡的php-fpm配置檔案到安裝目錄下      
# cp -a ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm      //拷貝啟動檔案      

啟動

service php-fpm start       

檢視php是否啟動成功

#ps aux | grep php      
CentOS7.3下安裝PHP5.6.30服務(轉)

看到這些,表明你的php已經啟動成功啦!

重新開機及關閉

service php-fpm restart      service php-fpm stop      

配置Nginx支援PHP

進入nginx主目錄,需要修改nginx.conf

#vim nginx.conf      

代開下面代碼,讓Nginx支援PHP,在server代碼段裡。

CentOS7.3下安裝PHP5.6.30服務(轉)

修改完,這段代碼變為,紅色部分為我們主機目錄為/mnt/project,需要修改fastcgi_param SCRIPT_FILENAME指向對應目錄即可:

 location ~ \.php$ {

            root           /mnt/project;     //項目根目錄

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /mnt/project$fastcgi_script_name;       在$符前面加上項目根目錄

            include        fastcgi_params;

        }

設定主目錄設定為/mnt/project。

location / {

            root   /mnt/project;      //項目根目錄

            index  index.html  index.php;

        }

儲存退出。

根據Nginx章的解釋,我們重新開機Nginx服務。

#/etc/init.d/nginx restart      

如果你沒有按照我們在Nginx的方法配置,可以按照以下的方式重新開機Nginx服務

# /usr/local/nginx/sbin/nginx -s reload      

 重新開機成功!下面我們在/mnt/project目錄下添加一個新檔案。

#vim /mnt/project/phpinfo.php      

插入以下内容

<?php  
phpinfo();  
?>        

在浏覽器中打開http://遠端ip/phpinfo.php

CentOS7.3下安裝PHP5.6.30服務(轉)

看到這個頁面,恭喜你,你的PHP已經安裝配置完成了。

補充說明:

1. 關于網址重寫功能以及樣式顯示問題,請參考:

https://book.cakephp.org/2.0/zh/installation/url-rewriting.html

https://yq.aliyun.com/ziliao/105485

2. 遇到問題:"It is not safe to rely on the system's timezone settings........",請參考:

http://php.net/manual/en/function.date-default-timezone-set.php

http://www.jb51.net/article/73059.htm

3. 遇到問題:“ php-fpm Permission denied”,請參考:

http://blog.csdn.net/k178441367/article/details/51613042,或者賦予php-fpm可執行權限

4. 遇到問題:“Fatal error: Uncaught exception 'CacheException' with message 'Cache engine _cake_core_ is not properly configured”,請參考:

https://stackoverflow.com/questions/42002751/uncaught-exception-cacheexception-with-message-cache-engine-cake-core-is

https://stackoverflow.com/questions/29408227/uncaught-exception-cacheexception-with-message-cache-engine-cake-core-is-no

http://bbs.csdn.net/topics/391014151

最後

附上我的nginx配置檔案内容:cakephp項目源碼下載下傳(github的一個添删查改功能,cakephp官方教程位址)

  1. #user nobody;

  2. worker_processes 1;

  3. #error_log logs/error.log;

  4. #error_log logs/error.log notice;

  5. #error_log logs/error.log info;

  6. #pid logs/nginx.pid;

  7. events {

  8. worker_connections 1024;

  9. }

  10. http {

  11. include mime.types;

  12. default_type application/octet-stream;

  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '

  14. # '$status $body_bytes_sent "$http_referer" '

  15. # '"$http_user_agent" "$http_x_forwarded_for"';

  16. #access_log logs/access.log main;

  17. sendfile on;

  18. #tcp_nopush on;

  19. #keepalive_timeout 0;

  20. keepalive_timeout 65;

  21. #gzip on;

  22. server {

  23. listen 88;

  24. server_name localhost;

  25. root /mnt/project/cakephp/app/webroot;

  26. index index.php;

  27. #charset koi8-r;

  28. #access_log logs/host.access.log main;

  29. location / {

  30. try_files $uri $uri/ /index.php?$uri&$args;

  31. }

  32. #error_page 404 /404.html;

  33. # redirect server error pages to the static page /50x.html

  34. #

  35. error_page 500 502 503 504 /50x.html;

  36. location = /50x.html {

  37. root html;

  38. }

  39. # proxy the PHP scripts to Apache listening on 127.0.0.1:80

  40. #

  41. #location ~ \.php$ {

  42. # proxy_pass http://127.0.0.1;

  43. #}

  44. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

  45. #

  46. location ~ \.php$ {

  47. root /mnt/project/cakephp/app/webroot;

  48. try_files $uri =404;

  49. fastcgi_pass 127.0.0.1:9000;

  50. fastcgi_index index.php;

  51. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

  52. include fastcgi_params;

  53. fastcgi_buffer_size 128k;

  54. fastcgi_buffers 256 4k;

  55. fastcgi_busy_buffers_size 256k;

  56. fastcgi_temp_file_write_size 256k;

  57. }

  58. # deny access to .htaccess files, if Apache's document root

  59. # concurs with nginx's one

  60. #

  61. #location ~ /\.ht {

  62. # deny all;

  63. #}

  64. }

  65. # another virtual host using mix of IP-, name-, and port-based configuration

  66. #

  67. #server {

  68. # listen 8000;

  69. # listen somename:8080;

  70. # server_name somename alias another.alias;

  71. # location / {

  72. # root html;

  73. # index index.html index.htm;

  74. # }

  75. #}

  76. # HTTPS server

  77. #

  78. #server {

  79. # listen 443 ssl;

  80. # server_name localhost;

  81. # ssl_certificate cert.pem;

  82. # ssl_certificate_key cert.key;

  83. # ssl_session_cache shared:SSL:1m;

  84. # ssl_session_timeout 5m;

  85. # ssl_ciphers HIGH:!aNULL:!MD5;

  86. # ssl_prefer_server_ciphers on;

  87. # location / {

  88. # root html;

  89. # index index.html index.htm;

  90. # }

  91. #}

  92. }

推薦一個很不錯的視訊教程店,裡面東西還是挺不錯的,店主是個實在人:

https://shop60974085.taobao.com/

繼續閱讀