Linux环境Nginx安装与调试以及PHP安装

本文详细介绍了在64位CentOS 6.8上安装和配置Nginx 1.17.7及PHP 5.6.40的步骤,包括编译安装Nginx、解决编译错误、配置nginx.conf以支持PHP、安装PHP、配置php-fpm,以及安装和使用Redis扩展。此外,还涵盖了Nginx和PHP的调试技巧,如使用strace、pstack、gdb等工具进行问题排查。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

linux版本:64位CentOS 6.8

Nginx版本:nginx1.17.7

php版本:php5.6.40

说明:本博不定时更新为新版本

 

1.编译安装Nginx

官网:http://wiki.nginx.org/Install

下载:http://nginx.org/en/download.html

 

安装GCC

安装nginx需要gcc,如果因为需要安装grpc那么需要gcc4.8,可以先安装gcc

# wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repo
# yum install -y devtoolset-2-gcc devtoolset-2-binutils
# yum install -y devtoolset-2-gcc-c++ devtoolset-2-gcc-gfortran
# scl enable devtoolset-2 bash
# source /opt/rh/devtoolset-2/enable
# gcc --version

如果不按照grpc可以忽略这个,直接安装yum 安装gcc即可

# yum -y install gcc-c++

 

安装lrzsz 下载上传文件

# yum -y install lrzsz

安装nginx

# wget http://nginx.org/download/nginx-1.17.7.tar.gz

# tar -zvxf nginx-1.17.7.tar.gz

# cd ./nginx-1.17.7

# ./configure --prefix=/usr/local/nginx

# make && make install

 

安装Nginx时报错

错误提示:./configure: error: the HTTP rewrite module requires the PCRE library.

安装pcre-devel解决问题
# yum -y install pcre-devel


错误提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.

解决办法:

# yum -y install openssl openssl-devel


或者一并安装

# yum -y install pcre-devel openssl openssl-devel

 

错误提示:./configure: error: the HTTP gzip module requires the zlib library.

# yum install -y zlib-devel

启动nginx

# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

 

安装成功查看nginx进程

# ps aux | grep nginx

 

测试页面,直接输入服务器ip

其实nginx默认的web工作目录在/usr/local/nginx/html

可以修改nginx的配置文件nginx.conf改变到其他路径

 

防火墙配置

注意如果你希望在本地机器例如xp访问虚拟机的网页,如果是centos6需要修改防火墙启动80端口

# cd /etc/sysconfig

修改iptables文件,或者直接用vim编辑

# vim /etc/sysconfig/iptables

添加下面一行,打开防火墙80端口:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

重启防火墙
# /etc/init.d/iptables restart

查看CentOS防火墙信息:/etc/init.d/iptables status

关闭CentOS防火墙服务:/etc/init.d/iptables stop

 

如果没有防火墙文件

需要

# iptables -P OUTPUT ACCEPT
# service iptables save
# service iptables restart

然后重写iptables文件

其实完整的防火墙文件是这样的

 

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
#-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

 

停止nginx

查询nginx主进程号
#ps -ef | grep nginx

从容停止Nginx:
kill -QUIT 主进程号
快速停止Nginx:
kill -TERM 主进程号
强制停止Nginx:
pkill -9 nginx

 

开启目录自动显示

 

nginx的配置文件nginx.conf在

# cd /usr/local/nginx/conf

有时候需要开启目录自动显示功能

 

http {
    include       mime.types;
    default_type  application/octet-stream;
	#自动显示目录
	autoindex on;

 

重启nginx

# /usr/local/nginx/sbin/nginx -s reload

 

获取安装信息

如果需要重新安装nginx,需要知道之前的安装信息

# /usr/local/nginx/sbin/nginx -V

 

2.安装php

www.php.net找下载最新的版本

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

下载解压

# wget  https://www.php.net/distributions/php-5.6.40.tar.gz

# tar zxvf php-5.6.40.tar.gz

# cd php-5.6.40

 

配置

#./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-inl
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值