Ubuntu下安装Nginx、PHP

php中文网
发布: 2016-08-08 09:19:53
原创
1214人浏览过

安装nginx

sudo apt-get install nginx

测试nginx

打开浏览器,输入http://127.0.0.1,如果出现

Welcome to nginx

立即学习PHP免费学习笔记(深入)”;

则表示nginx安装成功。

安装配置PHP

安装 PHP for Processing

sudo apt-get install php5-fpm php5-mysql

Since Nginx does not contain native PHP processing like some other web servers, we will need to install php5-fpm, which stands for “fastCGI process manager”. We will tell Nginx to pass PHP requests to this software for processing.We can install this module and will also grab an additional helper package that will allow PHP to communicate with our database backend. The installation will pull in the necessary PHP core files. Do this by typing:

配置 PHP Processor

sudo gedit /etc/php5/fpm/php.ini

<code><font color="red">cgi.fix_pathinfo=0</font></code>
登录后复制

This is an extremely insecure setting because it tells PHP to attempt to execute the closest file it can find if a PHP file does not match exactly. This basically would allow users to craft PHP requests in a way that would allow them to execute scripts that they shouldn’t be allowed to execute.

 v1.6.2蝉知商城专业版
v1.6.2蝉知商城专业版

蝉知商城以插件的形式发布,需要安装zend guard loader扩展。 安装好zend后可以在后台--平台--扩展内安装,或根据php版本选择下面的下载地址,下载后本地安装。 一、功能列表 1.集成工单系统 2.新增订单自定义接口功能 3.优化新订单跟订单留言的提醒功能 4.新增FAQ功能 5.全面兼容蝉知5.3.3 二、功能展示 订单自定义接口功

 v1.6.2蝉知商城专业版 169
查看详情  v1.6.2蝉知商城专业版

We will change both of these conditions by uncommenting the line and setting it to “0” like this:

Save and close the file when you are finished.

重启 PHP processor
sudo service php5-fpm restart

让nginx使用PHP Processor

<code>sudo gedit /etc/nginx/sites-available/default</code>
登录后复制

按下面修改配置文件

<code>
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6

    root /usr/share/nginx/html;
    index <font color="red">index.php</font> index.html index.htm;

    server_name <font color="red">server_domain_name_or_IP</font>;

    location / {
        try_files $uri $uri/ =404;
    }

    <font color="red">error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }</font>
}
</code>
登录后复制

使对php的配置立即生效

sudo service nginx restart

建立测试页

sudo gedit /usr/share/nginx/html/info.php
内容为:

<code><span><?php</span>
    phpinfo();
<span>?></span></code>
登录后复制

访问http://127.0.0.1/info.php
如果出现
这里写图片描述
则表示配置成功

参考资料

https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04

版权声明:本文为博主原创文章,未经博主允许不得转载。

以上就介绍了Ubuntu下安装Nginx、PHP,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相关标签:
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号