CentOS7.3下安装PHP5.6.30服务(转)

2 篇文章 0 订阅
1 篇文章 0 订阅

原文出处:

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的版本列表

右击,复制链接地址,在远程主机登录,下载该软件(我选的是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已经配置完成啦!

接下来我们只需要编译安装即可完成php的安装

#make && make install

看到这句话,表明安装完成!

为了保险起见,我们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

看到这些,表明你的php已经启动成功啦!

重启及关闭

service php-fpm restart      service php-fpm stop

配置Nginx支持PHP

进入nginx主目录,需要修改nginx.conf

#vim nginx.conf

代开下面代码,让Nginx支持PHP,在server代码段里。

修改完,这段代码变为,红色部分为我们主机目录为/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

看到这个页面,恭喜你,你的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.  
  4. #error_log logs/error.log;

  5. #error_log logs/error.log notice;

  6. #error_log logs/error.log info;

  7.  
  8. #pid logs/nginx.pid;

  9.  
  10.  
  11. events {

  12. worker_connections 1024;

  13. }

  14.  
  15.  
  16. http {

  17. include mime.types;

  18. default_type application/octet-stream;

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

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

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

  23.  
  24. #access_log logs/access.log main;

  25.  
  26. sendfile on;

  27. #tcp_nopush on;

  28.  
  29. #keepalive_timeout 0;

  30. keepalive_timeout 65;

  31.  
  32. #gzip on;

  33.  
  34. server {

  35. listen 88;

  36. server_name localhost;

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

  38. index index.php;

  39.  
  40. #charset koi8-r;

  41.  
  42. #access_log logs/host.access.log main;

  43.  
  44. location / {

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

  46. }

  47.  
  48. #error_page 404 /404.html;

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

  51. #

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

  53. location = /50x.html {

  54. root html;

  55. }

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

  58. #

  59. #location ~ \.php$ {

  60. # proxy_pass http://127.0.0.1;

  61. #}

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

  64. #

  65. location ~ \.php$ {

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

  67. try_files $uri =404;

  68. fastcgi_pass 127.0.0.1:9000;

  69. fastcgi_index index.php;

  70. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

  71. include fastcgi_params;

  72. fastcgi_buffer_size 128k;

  73. fastcgi_buffers 256 4k;

  74. fastcgi_busy_buffers_size 256k;

  75. fastcgi_temp_file_write_size 256k;

  76. }

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

  79. # concurs with nginx's one

  80. #

  81. #location ~ /\.ht {

  82. # deny all;

  83. #}

  84. }

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

  88. #

  89. #server {

  90. # listen 8000;

  91. # listen somename:8080;

  92. # server_name somename alias another.alias;

  93.  
  94. # location / {

  95. # root html;

  96. # index index.html index.htm;

  97. # }

  98. #}

  99.  
  100.  
  101. # HTTPS server

  102. #

  103. #server {

  104. # listen 443 ssl;

  105. # server_name localhost;

  106.  
  107. # ssl_certificate cert.pem;

  108. # ssl_certificate_key cert.key;

  109.  
  110. # ssl_session_cache shared:SSL:1m;

  111. # ssl_session_timeout 5m;

  112.  
  113. # ssl_ciphers HIGH:!aNULL:!MD5;

  114. # ssl_prefer_server_ciphers on;

  115.  
  116. # location / {

  117. # root html;

  118. # index index.html index.htm;

  119. # }

  120. #}

  121.  
  122. }

推荐一个很不错的视频教程店,里面东西还是挺不错的,店主是个实在人:

https://shop60974085.taobao.com/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值