• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Ubuntu下安装Nginx、PHP

php 搞代码 4年前 (2022-01-23) 24次浏览 已收录 0个评论

安装nginx

sudo apt-get install nginx

测试nginx

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

则表示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<i style="color:transparent">@本文来源gaodai$ma#com搞$代*码6网</i><b>搞代gaodaima码</b>.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.

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教程有兴趣的朋友有所帮助。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Ubuntu下安装Nginx、PHP

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址