首页 > 系统相关 >centos安装php php-fpm 以及 配置nginx

centos安装php php-fpm 以及 配置nginx

时间:2023-08-08 11:01:13浏览次数:43  
标签:enable centos nginx fpm -- usr php



下载php源码包

http://www.php.net/downloads.php

安装php

tar -xvf php-5.5.13.tar.bz2

cd php-5.5.13

 ./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --with-readline --without-sqlite3 --without-pdo-sqlite --with-pear

可能出现的错误

出现错误: congigure error: xml2-config not found

解决办法:

1.执行命令: 

sudo yum install libxml2-devel

2.查看是否成功: 

find / -name "xml2-config"

出现错误: congigure error: Cannot find OpenSSL's <evp.h>

解决办法:

yum install openssl openssl-devel

ln -s /usr/lib64/libssl.so /usr/lib/




出现错误: configure: error: Please reinstall the BZip2 distribution

解决办法:

yum install bzip2 bzip2-devel




出现错误: configure: error: Please reinstall the libcurl distribution -easy.h should be in <curl-dir>/include/curl/

解决办法:

yum -y install curl-devel

 

出现错误:configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决办法:

sudo yum install libmcrypt libmcrypt-devel mcrypt mhash

 

出现错误:configure: error: Please reinstall readline - I cannot find readline.h

解决办法:

sudo yum install readline-devel

编译

make 

make install

可能出现的错误

编译PHP5.5 make 时出现错误

make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

解决办法:
这是由于内存小于1G所导致.Disable fileinfo support 禁用 fileinfo

在./configure加上选项:

--disable-fileinfo



配置环境变量

添加 PHP 命令到环境变量

vim /etc/profile

在末尾加入

PATH=$PATH:/usr/local/php/bin

export PATH

要使改动立即生效执行

. /etc/profile 或 source /etc/profile

查看环境变量

echo $PATH

查看php版本

php -v

PHP 5.5.13 (cli) (built: Jun 20 2014 11:11:26) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies

配置启动php-fpm

cd /usr/local/php/etc

cp php-fpm.conf.default php-fpm.conf

启动php-fpm

sudo /usr/local/php/sbin/php-fpm

配置nginx

修改nginx的配置文件(/etc/nginx/conf.d/default.conf)

location / {

root web根目录;//在服务器中的目录

index index.html index.htm index.php;

}

location ~ \.php$ {

root html;

fastcgi_pass 127.0.0.1:9000; //这个iP和端口对应php-fpm设置的端口

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME web根目录$fastcgi_script_name;

include fastcgi_params;

}

检查nginx


[root@server nginx]# ./sbin/nginx -t //检测配置文件是否正常


nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok  


nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful  


则 已经配置正确






重启nginx

/etc/init.d/nginx restart




在web根目录下创建index.php

<?php echo phpinfo(); ?>

在浏览器中输入http://ip/index.php查看成功即可。

//注:根据自己的配置修改web根目录即可,如我的为/usr/share/nginx/html。

如果启动php-fpm出现错误: can not get uid for www,修改php-fpm.conf中user为nginx group为nginx



标签:enable,centos,nginx,fpm,--,usr,php
From: https://blog.51cto.com/u_16218512/7005679

相关文章

  • php优化递归算法优化
    2023年8月7日13:59:31因为最近开发自己的一些常用系统,所以为了自由度较高一点,经常分类都是无限层级,所以递归用的比较多,但是发现当分类大于三层,数据1万以上递归就会很慢,所以一直在寻求优化算法,使用使用chagpt优化的算法,基本无法使用,后续想到用php原生函数来使用,结果性能飙升数据......
  • linux 如何创建php文件
    首先,需要先安装PHP。在Linux中,你可以通过使用命令行工具来安装PHP。具体方法如下: sudoapt-getupdatesudoapt-getinstallphp以上命令会自动安装PHP并将其设置为默认选项。一旦你安装好了PHP,你就可以开始创建PHP文件了。在Linux中,你可以使用任何文本编辑器来创建PHP文件......
  • No input file specified. thinkphp 高版本正则重写问题
    Noinputfilespecified.问题描述:使用TP框架做项目时,在启用REWRITE的伪静态功能的时候,首页可以访问,但是访问其它页面的时候,就提示:“Noinputfilespecified.”原因在于使用的PHP5.6是fast_cgi模式,而在某些情况下,不能正确识别path_info所造成的错误默认的.htaccess里面的规则:......
  • MySQL插入1000万条数据,用PHP如何做才能保证性能的最优
    插入大量数据时,确保性能最优是很重要的。下面是几种在PHP中快速向MySQL插入大量数据的优化方案:使用多行插入:最简单的方法是使用多行插入语句,将多条记录一次性插入到数据库。这比逐条插入要快得多,因为减少了连接和查询的开销。$values = [];for ($i = 0; $i < 1000000......
  • php实战手册(2)
    目录变量变量定义<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>phpdemo</title></head><body> <?php$x=11;?> <p> phphello,world ......
  • CTFer成长记录——CTF之Web专题·攻防世界-Web_php_include
    一、题目链接https://adworld.xctf.org.cn/challenges/list?rwNmOdr=1691398818171二、解法步骤  本题依旧是文件包含,但是这题不同,while(strstr($page,"php://")){$page=str_replace("php://","",$page);}  这条语句过滤掉了以往的php://filter/read=convert.......
  • CTFer成长记录——CTF之Web专题·攻防世界-php_rce
    一、题目链接https://adworld.xctf.org.cn/challenges/list?rwNmOdr=1691398818171二、解法步骤  RCE意思是(RemoteCodeExecution),远程代码执行漏洞。这里题目涉及到thinkphp5的框架,那么就可能有对应的漏洞。  ThinkPHP5漏洞Payload:  Thinkphp5.0.221、http://192.1......
  • CTFer成长记录——CTF之Web专题·攻防世界-Web_php_unserialize
    一、题目链接https://adworld.xctf.org.cn/challenges/list二、解法步骤  本题考察的是反序列化,反序列化的题都需要审计php代码,步骤也比较固定。<?phpif(isset($_GET['var'])){$var=base64_decode($_GET['var']);if(preg_match('/[oc]:\d+:/i',$var))......
  • php 无限级分类,超级简单的无限级分类,支持输出树状图
    返回一维数组//无限级分类 function GetTree($arr, $pid = 0, $step = 0){    static $tree;    foreach ($arr as $key => $val) {        if ($val['pid'] == $pid) {            $name = isset($val['title']) ? $......
  • php多维数组自定义排序 uasort()
    对数组进行排序PHP有一些用来排序数组的函数,这个文档会把它们列出来。主要区别有:有些函数基于array的键来排序,而其他的基于值来排序的:$array['key']='value';。排序之后键和值之间的关联关系是否能够保持,是指排序之后数组的键可能会被重置为数字型的(0,1,2...)。排......