AWS完全指引手册第06节-安装PHP

2014-05-24 21:21:51

[开发运维 | Dev Ops] , , , , ,

有yum源安装php是很方便的,通过yum安装各个php的组件。然后是设置php-fpm,这个是一个php的进程管理器,安装完成后,将它连接到Nginx,进行一系列的设置。注意,如果使用SSL的话,在php里面也是 要设置的。

 

 

 

 

通过yum安装php.

sudo yum install php-fpm php-cli php-mysql php-mcrypt php-mbstring php-gd php-tidy php-xml php-xmlrpc

 

然后需要配置nginx文件,让它将以.php结尾的文件交给php-fpm进行处理,个人推荐nginx和php-fpm通过socket 来连接,这样据闻会比较快。

 

 

1. 设置nginx  文件

由于这段代码的复用度很高,基本上每一个虚拟站点都要添加一句,所以个人推荐把它弄成一个引用(include 那一句),另外这个高亮是针对wordpress的设定

server {
        listen          89.32.145.87:80;
        server_name     note.masterchan.me;

        root    /var/www/html/masterchan/note;

        location / {
                index index.php;

                if (!-e $request_filename){
                        rewrite ^(.*)$ /index.php last;

                }
        }

        include         default.d/charset.conf;
        include         default.d/error.conf;
        include         default.d/php.conf;
}

 

然后另外在引用的位置,一般是 /etc/nginx/default.d/php.conf

        location ~ \.php$ {
                add_header      Cache-Control   no-cache;


                fastcgi_pass    unix:/var/run/php-fpm/php-fcgi.sock;
                fastcgi_index   index.php;
                fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;
                include                 fastcgi_params;
        }

在高亮处替代你的sock文件位置

 

 

如果是使用SSL,需要在这里开启SSL

        location ~ \.php$ {
                add_header      Cache-Control   no-cache;


                fastcgi_pass    unix:/var/run/php-fpm/php-fcgi.sock;
                fastcgi_index   index.php;
                fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;
                fastcgi_param   HTTPS                   on;
                include                 fastcgi_params;
        }

 

 

 

2.    设置php-fpm

打开/etc/php-fpm.d/www.conf   这里要将监听的对象改成 socket

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php-fcgi.sock
listen.owner    =       root
listen.owner    =       root

其余各种优化设定请参照 本站的另外一篇文章  减少php-fpm的内存消耗

 

这里就不再赘述了 sudo service php-fpm start
然后转到 /var/run/php-fpm目录下面,你能够看到 php-fcgi.sock 就说明成功了

然后打开网站看看能不能看到 php

 

 

 3. 设置php Session

一般情况下是在   /var/lib/php文件夹中,创建一个名为 session的文件夹,并且确保nginx这个用户有权限读取。

 

 

这篇博文发表在 开发运维 | Dev Ops 目录下,标签为 , , , , ,
如需引用,请使用链接:https://note.mc256.dev/?p=372

This article published in 开发运维 | Dev Ops with tags , , , , , .
Cite this page using this link:https://note.mc256.dev/?p=372

您的邮箱地址不会被公开,评论使用Gravatar头像。
Your email address will not be published. This blog is using Gravatar.

正在提交评论... Submitting ...
正在为您准备评论控件 Loading Comment Plugin
Copyright © 2013-2024 mc256. All Rights Reserved.
Powered by WordPress on top of a dual-stack k3s Cluster using JuiceFS.
Wordpress Theme Designed By mc256.
Encrypted By Let's Encrypt.  Hosted On Linode + OVH + AWS.
DNS Provided By Hostker.
Status Page by CloudFlare Worker.