CentOS7.3下安装PHP5.6.30服务

前端之家收集整理的这篇文章主要介绍了CentOS7.3下安装PHP5.6.30服务前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

关于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下载的)

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

下载下来的是一个mirror文件,改成我们需要的文件

  1. #mv mirror PHP-5.6.30.tar.gz
  2. #tar zxvf PHP-tar.gz
  3. #cd PHP-30

配置安装

进入到目录,我们需要在安装的时候将安装目录配置到/usr/local/PHP/里

  1. #./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:

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

解决办法

安装libxml2相关组件

yum install libxml2 #install libxml2-devel -y

错误2:

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

安装curl相关组件

install curl curl-devel

错误3:

  1. configure: error: png.h not found.

安装libpng相关组件

install libpng #install libpng-devel

错误4:

  1. freetype-config not found.

安装freetype相关组件

install freetype-devel

错误5:

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

安装libxslt相关组件

  1. #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进行配置

  1. # cp -a PHP.ini-production /usr/local/PHP/etc/PHP.ini //拷贝安装包里的PHP配置文件到安装目录下
  1. # rm -rf /etc/PHP.ini //删除默认的PHP配置文件
  1. # ln -s /usr/local/PHP/etc/PHP.ini /etc/PHP.ini //建立软链接

PHP-fpm配置

拷贝PHP-fpm启动配置文件

  1. # cp -a ./sapi/fpm/PHP-fpm.conf /usr/local/PHP/etc/PHP-fpm.conf //拷贝安装包里的PHP-fpm配置文件到安装目录下
  1. # cp -a ./sapi/fpm/init.d.PHP-fpm /etc/init.d/PHP-fpm //拷贝启动文件

启动

  1. service PHP-fpm start

查看PHP是否启动成功

ps aux | grep PHP

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

重启及关闭

  1. service PHP-fpm restart service PHP-fpm stop

配置Nginx支持PHP

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

  1. #vim Nginx.conf

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

修改完,这段代码变为,红色部分为我们主机目录为/mnt/project,需要修改fastcgi_param SCRIPT_FILENAME指向对应目录即可:

@H_403_244@ 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 index index.html index.PHP;
}

保存退出

根据Nginx章的解释,我们重启Nginx服务。

  1. #/etc/init.d/Nginx restart

如果你没有按照我们在Nginx方法配置,可以按照以下的方式重启Nginx服务

  1. # /usr/local/Nginx/sbin/Nginx -s reload

重启成功!下面我们在/mnt/project目录下添加一个新文件

  1. #vim /mnt/project/PHPinfo.PHP

插入以下内容

  1. <?PHP
  2. PHPinfo();
  3. ?>

在浏览器中打开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. 遇到问题:“Fatalerror:Uncaughtexception'CacheException'withmessage'Cacheengine_cake_core_isnotproperlyconfigured”,请参考:

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. }

猜你在找的CentOS相关文章