设为首页收藏本站

LUPA开源社区

 找回密码
 注册
文章 帖子 博客
LUPA开源社区 首页 业界资讯 技术文摘 查看内容

在Fedora 16上安装Nginx(带PHP-FPM)+PHP5和MySQL支持

2012-2-23 10:40| 发布者: 红黑魂| 查看: 10696| 评论: 0|来自: IMCN

摘要: Nginx是一个免费,开源,高性能的HTTP服务器。Nginx是其稳定性,功能集丰富,简单配置,资源消耗低。本教程演示如何在Fedora16上安装PHP5+Nginx(PHP-FPM)+MySQL的服务器。但是我不发出任何保证,它一定会正常工作 ...

此外,以避免类似以下错误

[13-Nov-2011 22:13:16] PHP Warning: phpinfo(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘Europe/Berlin’ for ‘CET/1.0/no DST’ instead in /usr/share/nginx/html/info.php on line 2

… /var/log/php-fpm/www-error.log 中,当你调用一个PHP脚本在您的浏览器,你应该在/etc/php.ini文件中设置date.timezone:

[...]
[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = “Europe/Berlin”
[...]

你可以找到正确的时区为您的系统,运行命令:

cat /etc/sysconfig/clock

[root@server1 ~]# cat /etc/sysconfig/clock
ZONE=”Europe/Berlin”
[root@server1 ~]#

下一步创建系统启动或者PHP-FPM并启动它:

systemctl enable php-fpm.service
systemctl start php-fpm.service

PHP-FPM是一个守护进程运行FastCGI服务器的端口9000。
5、nginx设置
输入命令:
vi /etc/nginx/nginx.conf

配置是很容易理解。
你可以再以下网址了解更多配置信息:

http://wiki.codemongers.com/NginxFullExample

http://wiki.codemongers.com/NginxFullExample2

按照以下配置设置值:

[...]
worker_processes 4;
[...]
keepalive_timeout 2;
[...]

虚拟主机是指在服务器{}容器。默认的虚拟主机是指在该文件 /etc/nginx/conf.d/default.conf -让我们作如下修改:

[...]
server {
listen 80;
server_name _;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}

error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
location ~ /\.ht {
deny all;
}
}
[...]

保存和重启服务:
systemctl reload nginx.service

现在你可以建立一个探针文件进行测试

6、建立 PHP-FPM 使用一个 Unix Socket
vi /etc/php-fpm.d/www.conf

[...]
;listen = 127.0.0.1:9000
listen = /tmp/php5-fpm.sock
[...]

重启PHP-FPM

systemctl restart php-fpm.service

配置文件:
vi /etc/nginx/conf.d/default.conf

配置内容如下:

[...]
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
[...]

重启Nginx:
systemctl reload nginx.service

文章参考:

本文采用CC协议发布,转载请注明: 转载自IMCN


酷毙
1

雷人

鲜花

鸡蛋

漂亮

刚表态过的朋友 (1 人)

  • 快毕业了,没工作经验,
    找份工作好难啊?
    赶紧去人才芯片公司磨练吧!!

最新评论

关于LUPA|人才芯片工程|人才招聘|LUPA认证|LUPA教育|LUPA开源社区 ( 浙B2-20090187 浙公网安备 33010602006705号   

返回顶部