在CentOs 5.1中使用rpm安装NGINX+php+mysql(二)

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
云数据库 RDS MySQL Serverless,价值2615元额度,1个月
简介:

    以下兵分两路来说明:一是直接利用php-cgi的FastCGI运行方式;二是利用Lighttpd的spawn-fcgi来控制进程的运行方法。

先说说利用php-cgi的FASTCGI运行方式:
7、创建php-cgi启动脚本,
[root@nginx-freetds ~]# vi /etc/init.d/phpcgi
#!/bin/sh
#
# php-cgi - this script starts and stops the php-cgi daemin
#
# chkconfig: - 85 15
# description: Fast CGI php
# processname: php-cgi
# config: /etc/php.ini
# pidfile: /var/run/php-cgi.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

phpcgi="/usr/bin/php-cgi"
prog=$(basename ${phpcgi})

FCGIPORT="8888"
FCGIADDR="127.0.0.1"
FCGIUSER="apache"
FCGIGROUP="apache"
PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=1000
export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS

[ -e /etc/sysconfig/php-cgi ] && . /etc/sysconfig/php-cgi

lockfile=/var/lock/subsys/php-cgi

start() {
echo -n $"Starting $prog: "
/usr/bin/spawn-fcgi -a $FCGIADDR  -p $FCGIPORT -C $PHP_FCGI_CHILDREN -u $FCGIUSER -g $FCGIGROUP -P /var/run/php-cgi.pid -f "${phpcgi}" >> /
dev/null 2>&1
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}

stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}

restart() {
stop
start
}

force_reload() {
restart
}

fdr_status() {
status $prog
}

case "$1" in
start|stop|restart)
$1
;;
status)
fdr_status
;;
condrestart|try-restart)
[ ! -f $lockfile ] || restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"
exit 2
esac

然后,开机自动运行:
[root@nginx-freetds ~]#/sbin/chmod +x /etc/init.d/phpcgi
[root@nginx-freetds ~]#/sbin/chkconfig --add phpcgi
[root@nginx-freetds ~]#/sbin/chkconfig --level 35 phpcgi on
[root@nginx-freetds ~]#/sbin/chkconfig --level 35 nginx on

但从网上说会遇到两个问题,这里摘录一位的解决方案。(我没有遇到。也没有机会测试下面的解决方式是否正确)
[root@nginx-freetds ~]# cat /var/log/audit/audit.log| audit2allow -M local
[root@nginx-freetds ~]#/usr/sbin/semodule -i local.pp

下面说说利用Lighttpd的spawn-fcgi来控制进程的运行的方法:
8、开启nginx及利用Lighttpd的spawn-fcgi来控制进程的运行
[root@nginx-freetds ~]# spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u nginx -g nginx -f /usr/bin/php-cgi
spawn-fcgi.c.187: child spawned successfully: PID: 2513

参数含义如下

-f <fcgiapp> 指定调用FastCGI的进程的执行程序位置,根据系统上所装的PHP的情况具体设置 
-a <addr> 绑定到地址addr 
-p <port> 绑定到端口port 
-s <path> 绑定到unix socket的路径path 
-C <childs> 指定产生的FastCGI的进程数,默认为5(仅用于PHP) 
-P <path> 指定产生的进程的PID文件路径 
-u和-g FastCGI使用什么身份(-u 用户 -g 用户组)运行,Ubuntu下可以使用www-data,其他的根据情况配置,如nobody、apache等


因为,安装rpm 安装nginx时。会创建nginx用户和组。

[root@nginx-freetds ~]# service nginx start
Starting nginx: [  OK  ]

9、在IE栏里输入 [url]http://124.207.102.22/index.htm[/url] 这时NGINX已在正常运行。如下图:


在/usr/share/nginx/html下面新建index.php
<?php
phpinfo();
?>
       
在IE栏里输入 [url]http://124.207.102.22/index.php[/url] 这时NGINX已在正常运行。如下图:


10、那如何实现php的运行呢。在第7或第8步骤中,已开启了PHP的进程:
[root@nginx-freetds ~]# ps -aux |grep php
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ
nginx     2513  0.0  1.9  17720  4964 ?        Ss   20:45   0:00 /usr/bin/php-cgi
nginx     2514  0.0  0.6  17720  1656 ?        S    20:45   0:00 /usr/bin/php-cgi
nginx     2515  0.0  0.6  17720  1656 ?        S    20:45   0:00 /usr/bin/php-cgi
nginx     2516  0.0  0.6  17720  1656 ?        S    20:45   0:00 /usr/bin/php-cgi
nginx     2517  0.0  0.6  17720  1656 ?        S    20:45   0:00 /usr/bin/php-cgi
nginx     2518  0.0  0.6  17720  1656 ?        S    20:45   0:00 /usr/bin/php-cgi
root      2542  0.0  0.2   3892   676 pts/0    R+   20:48   0:00 grep php

可以看到,有五个进程正在运行。

     默认情况下。NGINX是可以开启静态页面,但如何开启PHP。还是要在/etc/nginx/nginx.php设置的。
    各位可以参考我的配置前后的截图(呵呵,研究下,有些参数是可以改变的。要举一返三吧):

修改前:


修改后:

保存更改。

然后service nginx restart便可了。

11、配置虚拟主机
在APACHE上配置虚拟主机。想来各位都有一定的体验。那如何在NGINX中实现呢?

[root@nginx-freetds html]# vi /etc/nginx/nginx.conf
参考下图(开启https的样例也在内)。最后几行:
  server 
      {
        listen       8000;    ####监听端口
        server_name  124.207.102.22  alias  another.alias;####域名
        root   /usr/share/nginx/html;                     ####路径
        index  index.php index.html index.htm;    ####index

        location ~ \.php$
        {
             include   fastcgi.conf;
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index  index.php;
         }



想多加虚机吗。呵呵,多来几个吧(日志选项请自位参考CONF文件自行研究)。

基本上完成了。有些功能还需要参考官方文档深入研究学习下

接下来,研究下rpm安装的情况下实现php连ms sql server.(tar包的已成功且在用啦)



 本文转自 rickyfang 51CTO博客,原文链接:http://blog.51cto.com/rickyfang/125841,如需转载请自行联系原作者





相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
1天前
|
应用服务中间件 nginx Docker
docker安装nginx
`docker search`找镜像,`pull`下载,后台 `-d` 运行容器,命名 `--name`,映射端口 `-p`。本机测试,确保服务器安全组开放端口,公网通过`http://ip:port`访问。用`docker stop id`停止容器。[查看详情](https://blog.csdn.net/javayoungcoolboy/article/details/134976510)
|
2天前
|
应用服务中间件 网络安全 nginx
nginx(1.13.7)首次安装出现:【make: *** 没有规则可以创建“default”需要的目标“build” 问题】解决措施
nginx(1.13.7)首次安装出现:【make: *** 没有规则可以创建“default”需要的目标“build” 问题】解决措施
|
2天前
|
关系型数据库 MySQL Linux
在Centos7中:通过Docker安装MySQL5.7(保姆级)
在Centos7中:通过Docker安装MySQL5.7(保姆级)
|
2天前
|
关系型数据库 MySQL Shell
在Centos7中利用Shell脚本:实现MySQL的数据备份
在Centos7中利用Shell脚本:实现MySQL的数据备份
|
2天前
|
SQL 关系型数据库 MySQL
这篇文章带你了解:如何一次性将Centos中Mysql的数据快速导出!!!
这篇文章带你了解:如何一次性将Centos中Mysql的数据快速导出!!!
|
4天前
|
安全 关系型数据库 MySQL
CentOS 7系统加固详细方案SSH FTP MYSQL加固
CentOS 7系统加固详细方案SSH FTP MYSQL加固
|
4天前
|
关系型数据库 MySQL Linux
Linux CentOs7 安装Mysql(5.7和8.0版本)密码修改 超详细教程
Linux CentOs7 安装Mysql(5.7和8.0版本)密码修改 超详细教程
|
4天前
|
Ubuntu 应用服务中间件 nginx
ubuntu编译安装nginx及安装nginx_upstream_check_module模块
以上是编译安装Nginx和安装 `nginx_upstream_check_module`模块的基本步骤。根据你的需求和环境,你可能需要进一步配置Nginx以满足特定的要求。
18 3
|
8天前
|
应用服务中间件 PHP nginx
php如何实现检测nginx配置的正确性
请确保在执行此操作时,PHP有足够的权限来执行Nginx命令和访问Nginx配置文件。另外,将上述代码嵌入到您的应用程序中时,要注意安全性,以防止潜在的命令注入攻击。
49 3