热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

CentOS7.3下安装PHP5.6.30服务

关于php-fpmnginx本身不能处理PHP,它只是个web服务器,当接收到请求后,如果是php请求,则发给php解释器处理,并把结果返回给客户端。nginx一般是把请求发fastcg

关于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 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官方教程地址)

#user  nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
worker_connections 1024;
}


http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 88;
server_name localhost;
root /mnt/project/cakephp/app/webroot;
index index.php;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
try_files $uri $uri/ /index.php?$uri&$args;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /mnt/project/cakephp/app/webroot;
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 4k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}


# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;

# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}



推荐阅读
  • 本文详细介绍了Java编程语言中的核心概念和常见面试问题,包括集合类、数据结构、线程处理、Java虚拟机(JVM)、HTTP协议以及Git操作等方面的内容。通过深入分析每个主题,帮助读者更好地理解Java的关键特性和最佳实践。 ... [详细]
  • centos7.2下编译安装php7.1.3步骤教程centos7编译安装php-7.1.3的步骤在官网下载php-7.1.3的php压缩包,centos7安装php-7.1.3的 ... [详细]
  • 简介Tengine是由淘宝网发起的Web服务器项目。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。它的目的是打造一个高效、安全的Web平台。发展Ten ... [详细]
  • sudoyum-yinstallcurl-develbzip2bzip2-devellibxml2libxml2-devellibjpeglibpngfreetypeli ... [详细]
  • 【PHP】PHP开发环境搭建——windows篇(apache2.2.22+php5.3.29+mysql5.7)
    一直有学习php的想法,也稍微弄过一点点php,以前是用xmpp或者wamp来实现这会让很多初学者盲目,不知道是啥。现在来搭建一遍开发环境,并且说明下每一个的用途。1、下载apache的h ... [详细]
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • 本文介绍了如何利用JavaScript或jQuery来判断网页中的文本框是否处于焦点状态,以及如何检测鼠标是否悬停在指定的HTML元素上。 ... [详细]
  • 本文详细介绍了如何使用PHP检测AJAX请求,通过分析预定义服务器变量来判断请求是否来自XMLHttpRequest。此方法简单实用,适用于各种Web开发场景。 ... [详细]
  • centos7.3配置python2、3环境与配置各自pip
    环境:CentOS-7-x86_64-Everything-1611No.1查看CentOS对Python的默认依赖[root@cs~]#lsusrbinpython* ... [详细]
  • 1、创建数据库[root@controller~]#mysql-uroot-p-eCREATEDATABASEkeystone;Enterpassword:[root ... [详细]
  • Centos7下Mysql5.7的安装
    1:卸载自带的mysqlrpm-qa|grepmariadb卸载自带数据库:rpm-e--nodeps1、安装YUMRepo ... [详细]
  • https:www.kernel.org这里从3.10升级到指定版本4.9.39[root@docker-dev~]#yumgroupi ... [详细]
  • 如果不加载PHP都没问题只要一加入LoadModulephp5_moduleC:phpphp5apache2.dllapache就启动不起来路径没问题apach ... [详细]
  • 范例1:路由规则和分组支持绑定模型数据,例如:usethink\Route;Route::rule(hello:id,indexindexhello,GET,[ext ... [详细]
  • 将wdcp中php5.2.17升级到php5.3方法:1、首先下载wdcpphp5.3升级脚本wgethttp:down.wdlinux.cninphp_up53.sh2、进行安 ... [详细]
author-avatar
老薛很厚道
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有