1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 在CentOS/RHEL6.2/5.8 Fedora17/16上安装Nginx/PHP-FPM环境

在CentOS/RHEL6.2/5.8 Fedora17/16上安装Nginx/PHP-FPM环境

时间:2022-08-01 04:33:48

相关推荐

在CentOS/RHEL6.2/5.8 Fedora17/16上安装Nginx/PHP-FPM环境

php教程|php手册

在,CentOS,RHEL6.2,5.8,Fedora17,上,安装,Nginx,PHP-FPM,环境,什么,是,PHP

php教程-php手册

什么是PHP-FPM

PHP-FPM是一个PHP FastCGI管理器,是只用于PHP的,

PHP-FPM其实是PHP源代码的一个补丁,旨在将FastCGI进程管理整合进PHP包中。必须将它patch到你的PHP源代码中,在编译安装PHP后才可以使用。

现在我们可以在最新的PHP 5.3.2的源码树里下载得到直接整合了PHP-FPM的分支,据说下个版本会融合进PHP的主分支去。相对Spawn-FCGI,PHP-FPM在CPU和内存方面的控制都更胜一筹,而且前者很容易崩溃,必须用crontab进行监控,而PHP-FPM则没有这种烦恼。

PHP5.3.3已经集成php-fpm了,不再是第三方的包了。PHP-FPM提供了更好的PHP进程管理方式,可以有效控制内存和进程、可以平滑重载PHP配置,比spawn-fcgi具有更多有点,所以被PHP官方收录了。在./configure的时候带 –enable-fpm参数即可开启PHP-FPM。

以上摘自:什么是CGI、FastCGI、PHP-CGI、PHP-FPM、Spawn-FCGI?

什么是Nginx

Nginx (“engine x”) 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。

在Fedora17/16/15/14,CentOS6.2/6.1/6/5.8及Red Hat(RHEL)6.2/6.1/6/5.8上安装配置Nginx/PHP-FPM

让我们开始行动起来吧

脚本源码自学,vscode 安卓手机版,ubuntu使用proxy,tomcat可以放html,商家爬虫软件,php 分段上传,seo优化前期怎么做,判断网站语言,p2p平台html模板lzw

STEP1.切换到root用户

[plain]

su –

## OR ##

sudo -i

dnf打怪源码,vscode更改背景图片,打包ubuntu镜像,tomcat 的所有版本,educoder爬虫答案,php好的书籍,简单seo百度推广引流lzw

STEP2.安装必要的软件源

2-1. Fedora 17/16/15/14 下安装Remi源

[plain]

## Remi Dependency on Fedora 17, 16, 15

rpm -Uvh /free/fedora/rpmfusion-free-release-stable.noarch.rpm

rpm -Uvh /nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm

易语言文件粉碎专家源码,前端网页VSCode,ubuntu下安装pycharm,tomcat jvm设置,sqlite 查询最大,网页设计结构,php对数据库增删改查,IIS服务器实例资源,woocommerce插件,手机前端框架排行,简单的爬虫程序,php 输出html,seo深度,源码springboot,js 文本域换行符和html换行标签的相互替换,个人博客网站程序有哪些,php实现网页伪静态,简单前台模板代码,企业站后台模板下载,页面滚动加载动画,社区管理系统app代码,程序侠 杨他他lzw

## Fedora 17 ##

rpm -Uvh /remi-release-17.rpm

## Fedora 16 ##

rpm -Uvh /remi-release-16.rpm

## Fedora 15 ##

rpm -Uvh /remi-release-15.rpm

## Fedora 14 ##

rpm -Uvh /remi-release-14.rpm

2-1. CentOS 6.2/6.1/6/5.8 及 Red Hat (RHEL) 6.2/6.1//6/5.8下安装Remi源

[plain]

## Remi Dependency on CentOS 6 and Red Hat (RHEL) 6 ##

rpm -Uvh /pub/epel/6/i386/epel-release-6-7.noarch.rpm

## CentOS 6 and Red Hat (RHEL) 6 ##

rpm -Uvh /enterprise/remi-release-6.rpm

## Remi Dependency on CentOS 5 and Red Hat (RHEL) 5 ##

rpm -Uvh /pub/epel/5/i386/epel-release-5-4.noarch.rpm

## CentOS 5 and Red Hat (RHEL) 5 ##

rpm -Uvh /enterprise/remi-release-5.rpm

2-2. CentOS 6.2/6.1/6/5.8 及 Red Hat (RHEL) 6.2/6.1/6/5.8 下还要配置Nginx 源

创建/etc/yum.repos.d/nginx.repo文件并写入以下内容

CentOS

[plain]

[nginx]

name=nginx repo

baseurl=/packages/centos/$releasever/$basearch/

gpgcheck=0

enabled=1

RedHat(RHEL)

[plain]

[nginx]

name=nginx repo

baseurl=/packages/rhel/$releasever/$basearch/

gpgcheck=0

enabled=1

STEP3.安装Nginx,PHP5.4.4&PHP-FPM

3-1. Fedora 17/16/15/14下

[plain]

yum –enablerepo=remi install nginx php php-fpm php-common

3-1. CentOS 6.2/5.8 及 Red Hat (RHEL) 6.2/5.8下

[plain]

yum –enablerepo=remi,remi-test install nginx php php-fpm php-common

STEP4.安装PHP5.4.4模块扩展

APC (php-pecl-apc) – APC缓存优化中间件

CLI (php-cli) – PHP命令行插件

PEAR (php-pear) – PHP官方扩展

PDO (php-pdo) – 数据库PDO扩展

MySQL (php-mysql) –MYSQL驱动

PostgreSQL (php-pgsql) – PostgreSQL驱动

MongoDB (php-pecl-mongo) – PHP MongoDB驱动

SQLite (php-sqlite) – SQLite V2引擎及驱动

Memcache (php-pecl-memcache) – Memcache 驱动

Memcached (php-pecl-memcached) – Memcached 驱动

GD (php-gd) – GD图片类库扩展

XML (php-xml) –XML扩展

MBString (php-mbstring) –多字节字符串处理扩展

MCrypt (php-mcrypt) – MCrypt类库扩展

4-1. Fedora 17/16/15/14下使用命令:

[plain]

yum –enablerepo=remi install php-pecl-apc php-cli php-pear php-pdo php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

4-1. CentOS 6.2/5.8 and Red Hat (RHEL) 6.2/5.8下使用命令:

[plain]

yum –enablerepo=remi,remi-test install php-pecl-apc php-cli php-pear php-pdo php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

STEP5.停止httpd(Apache)服务器,启动Nginx HTTP服务及PHP-FPM

5-1. 停止httpd

[plain]

/etc/init.d/httpd stop

## OR ##

service httpd stop

5-2. 启动Nginx

[plain]

/etc/init.d/nginx start

## OR ##

service nginx start

5-3. 启动PHP_FPM

[plain]

/etc/init.d/php-fpm start

## OR ##

service php-fpm start

【译者注】

到这一步,再按照步骤9配置一下防火墙开放80端口,打开浏览器输入http://localhost就可以看到nginx默认页面。

STEP6.设置Nginx&PHP-FPM开机自启动(同时禁止Httpd自启动)

6-1. 禁止Httpd自启动

[plain]

chkconfig httpd off

5-2 设置Nginx&PHP-FPM开机自启动

[html]

chkconfig –add nginx

chkconfig –levels 235 nginx on

chkconfig –add php-fpm

chkconfig –levels 235 php-fpm on

STEP7. 配置Nginx&PHP-FPM

7-1. 创建网站目录

在这里我使用testsite.local作为站点目录,在实际应用用我们常常使用对应域名作为站点目录,如

[plain] view plaincopy

##创建public_html目录及logs日志目录

mkdir -p /srv/www/testsite.local/public_html

mkdir /srv/www/testsite.local/logs

##将以上目录的所有者修改为nginx

chown -R nginx:nginx /srv/www/testsite.local

配置一下日志目录

[plain]

mkdir -p /srv/www/testsite.local/public_html

mkdir -p /var/log/nginx/testsite.local

chown -R nginx:nginx /srv/www/testsite.local

chown -R nginx:nginx /var/log/nginx

7-2. 创建并配置nginx虚拟主机目录

[plain]

mkdir /etc/nginx/sites-available

mkdir /etc/nginx/sites-enabled

打开 /etc/nginx/nginx.conf 文件,在include /etc/nginx/conf.d/*.conf”行后(在http block内)加入以下代码

[plain]

include /etc/nginx/sites-enabled/*;

7-3. 为站点testsite.local配置nginx虚拟主机

在/etc/nginx/sites-available/目录下添加testsite.local文件,其内容如下。

[plain]

server {

server_name testsite.local;

access_log /srv/www/testsite.local/logs/access.log;

error_log /srv/www/testsite.local/logs/error.log;

root /srv/www/testsite.local/public_html;

location / {

index index.html index.htm index.php;

}

location ~ \.php$ {

include /etc/nginx/fastcgi_params;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /srv/www/testsite.local/public_html$fastcgi_script_name;

}

}

将testsite.local链接到/etc/nginx/sites-enabled下

[plain]

cd /etc/nginx/sites-enabled/

ln -s /etc/nginx/sites-available/testsite.local

service nginx restart

把testsite.local这个”域名”加到/etc/hosts中

修改/etc/hosts文件

[plain]

cd /etc/nginx/sites-enabled/

127.0.0.1localhost.localdomain localhost testsite.local

STEP8. 测试

在/srv/www/testsite.local/public_html/下创建index.php文件,其内容如下

[plain]

cd /etc/nginx/sites-enabled/

<?php

phpinfo();

?>

打开你的浏览器,访问http://testsite.local/

STEP9. 防火墙iptables配置

为Nginx Web Server开放80端口,修改/etc/sysconfig/iptables文件,加入如下内容

[plain]

cd /etc/nginx/sites-enabled/

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

重启iptables防火墙

[plain]

cd /etc/nginx/sites-enabled/

service iptables restart

## OR ##

/etc/init.d/iptables restart

作者:uuleaf

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。