服务器之家:专注于服务器技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服务器之家 - 服务器系统 - Centos - Centos6.4 编译安装 nginx php的方法

Centos6.4 编译安装 nginx php的方法

2021-12-30 17:08CentOS教程网 Centos

这篇文章主要介绍了Centos6.4 编译安装 nginx php的方法,需要的朋友可以参考下

一. 准备依赖库

安装make:

?
1
yum -y install gcc automake autoconf libtool make

安装g++:

?
1
yum install gcc gcc-c++

二. 编译安装pcre

pcre 是一个正则表达式的库,编译nginx需要依赖该库实现url rewrite

下载源码

?
1
2
3
cd /usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.bz2
tar jxvf pcre-8.33.tar.bz2

编译安装

?
1
2
3
4
cd pcre-8.33
./configure
make
make install

三. 编译安装zlib库

zlib 是gzip实现

下载源码

?
1
2
3
cd /usr/local/src
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz

编译安装

?
1
2
3
4
cd zlib-1.2.8
./configure
make
make install

四. 安装openssl

检查是否安装了ssl

?
1
2
3
# rpm -qa|grep openssl
openssl-devel-1.0.1e-16.el6_5.14.x86_64
openssl-1.0.1e-16.el6_5.14.x86_64

如果没有安装

下载源码

?
1
2
3
cd /usr/local/src
wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
tar -zxvf openssl-1.0.1c.tar.gz

编译安装

?
1
2
3
./configure
make
make install

五. 编译安装nginx

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
cd /usr/local/src
wget http://nginx.org/download/nginx-1.2.8.tar.gz
tar -zxvf nginx-1.2.8.tar.gz
cd nginx-1.2.8
 
 ./configure --sbin-path=/usr/local/nginx/nginx \
 --conf-path=/usr/local/nginx/nginx.conf \
 --pid-path=/usr/local/nginx/nginx.pid \
 --with-http_ssl_module \
 --with-pcre=/usr/local/src/pcre-8.33 \
 --with-zlib=/usr/local/src/zlib-1.2.8 \
 --with-openssl=/usr/local/src/openssl-1.0.1c
 make
 make install

安装成功完毕后验证是否安装成功

?
1
2
/usr/local/nginx/nginx
netstat -alptn|grep 80

六. 编译安装php

新版本的php中已经集成了php-fpm

1. 准备工作

?
1
2
3
4
5
yum -y install libmcrypt-devel mhash-devel libxslt-devel\
 libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel\
 zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel\
 ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel\
 krb5 krb5-devel libidn libidn-devel openssl openssl-devel

2. 源码编译安装libmcrypt

?
1
2
3
4
5
6
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz
tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make
make install

3. 下载源码

?
1
2
wget http://cn2.php.net/distributions/php-5.4.7.tar.gz
tar zvxf php-5.4.7.tar.gz

4. 编译安装cd php-5.4.7

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
./configure --prefix=/usr/local/php      \
   --enable-fpm         \
   --enable-mbstring        \
   --enable-sockets        \
   --enable-sysvsem        \
   --enable-sysvshm        \
   --enable-pcntl         \
   --enable-mbregex        \
   --enable-zip         \
   --enable-inline-optimization     \
   --disable-pdo         \
   --disable-debug        \
   --disable-rpath        \
   --with-mcrypt         \
   --with-zlib         \
   --with-bz2          \
   --with-mhash         \
   --with-curl         \
   --with-mysql         \
   --with-gd          \
   --with-pcre-regex        \
   --with-libdir=lib64

如果报如下错误

?
1
configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no

修改 /etc/ld.so.conf 文件

?
1
2
3
4
5
6
7
8
9
vi /etc/ld.so.conf.d/local.conf
#添加2行
/usr/local/lib64 //64系统
/usr/local/src/libmcrypt-2.5.7/lib/.libs
 
#执行以下命令
chmod gu+x /etc/ld.so.conf.d/local.conf
#执行以下命令使生效
ldconfig -v

再次执行命令

成功后编译安装

七. 配置启动

1. 配置php-fpm

?
1
2
3
cd /usr/local/php
cp /etc/php-fpm.conf.default /etc/php-fpm.conf
vi /etc/php-fpm.conf

修改
user = llong
group = llong

2. 修改nginx 支持 php-fpm

打开 nginx.conf

其中server段增加如下配置,注意标红内容配置,否则会出现No input file specified.错误

?
1
2
3
4
5
6
7
8
9
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

3. 测试是否配置成功

在/usr/local/nginx/html下创建index.php文件,输入如下内容

?
1
2
3
<?
echo phpinfo();
?>

启动php-fpm和nginx

?
1
2
/usr/local/php/sbin/php-fpm (手动打补丁的启动方式/usr/local/php/sbin/php-fpm start)
 /usr/local/nginx/nginx

延伸 · 阅读

精彩推荐
  • CentosCentos7运用/dev/shm进行网站优化

    Centos7运用/dev/shm进行网站优化

    这篇文章主要介绍了LINUX中Centos7运用/dev/shm进行网站优化相关知识点,对此有兴趣的朋友参考学习下。...

    彬菌9912022-03-02
  • CentosCentos 7开启网卡自动获取IP的详细方法

    Centos 7开启网卡自动获取IP的详细方法

    本篇文章主要介绍了Centos 7开启网卡自动获取IP的详细方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧...

    凌锋8972021-12-29
  • Centoscentos 安装与操作方法

    centos 安装与操作方法

    这篇文章主要介绍了centos 安装与操作方法,需要的朋友可以参考下...

    centos之家5272019-07-11
  • CentosCentOS下Uptime命令详解

    CentOS下Uptime命令详解

    在Linux下,我们可以使用uptime命令,而且此命令不必使用root权限。uptime命令在系统中已经默认安装了。今天小编为大家带来的是CentOS下Uptime命令详解;希望...

    CentOS之家11482019-06-19
  • CentosCentOS6.5下Redis安装与配置详细步骤

    CentOS6.5下Redis安装与配置详细步骤

    本篇文章主要介绍了CentOS6.5下Redis安装与配置详细步骤,详细介绍redis单机单实例安装与配置,服务及开机自启动。有兴趣的可以了解一下。...

    飞流11452021-12-24
  • Centoscentos不小心删除/root目录该如何解决?

    centos不小心删除/root目录该如何解决?

    一些朋友最近在问小编centos不小心删除/root目录该如何解决?今天小编就为大家分享centos不小心删除/root目录解决办法;希望对大家会有帮助,有需要的朋友...

    脚本之家8022019-05-29
  • CentosCentOS 6.6实现永久修改DNS地址的方法

    CentOS 6.6实现永久修改DNS地址的方法

    这篇文章主要介绍了CentOS 6.6实现永久修改DNS地址的方法,涉及针对CentOS配置文件的相关设置技巧,具有一定参考借鉴价值,需要的朋友可以参考下 ...

    Linux社区4472020-08-21
  • CentosCentOS7设置日期和时间方法以及基本概念介绍

    CentOS7设置日期和时间方法以及基本概念介绍

    这篇文章主要介绍了CentOS7设置日期和时间方法以及基本概念介绍,本文讲解使用CentOS7中的新命令timedatectl设置日期时间方法,需要的朋友可以参考下 ...

    CentOS之家6522019-09-19