ubantu/debian上安装nginx+mysql+php

2018-05-12  本文已影响0人  信仰与初衷
最近因需要帮助朋友搭建一个网站,所以就重新玩了下debian下的lnmp搭建方式。
1. debian8 默认软件仓库只提供php5,对于需要使用php7的情况,需要添加扩展源进行安装。
vim /etc/apt/sources.list
deb http://packages.dotdeb.org jessie all
deb-src http://packages.dotdeb.org jessie all
wget https://www.dotdeb.org/dotdeb.gpg
apt-key add dotdeb.gpg
apt-get update
2. 安装php7
apt-cache search php
apt-get install php7.0-fpm php7.0-mysql php7.0-common php7.0-gd php7.0-json php7.0-cli php7.0-curl
3. 安装nginx
apt-get install nginx
nginx -v
4. 安装mysql
apt-get install -y mysql-server mysql-client

他会提示你输入密码

ps -ef |grep mysql 
5. 配置
sudo vi /etc/php/7.0/fpm/php.ini

找到如下一行

;cgi.fix_pathinfo=1

去掉前面的分号,并将1改为0

cgi.fix_pathinfo=0

保存文件后重启php7.0-fpm

-配置nginx

sudo vi /etc/nginx/sites-available/yourdomain.conf

server {
    listen 80;
    server_name yourdoman.com www.yourdomain.com;
    root /var/www/html;
    index index.php index.html index.htm index.nginx-debian.html;

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

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;

    location = /50x.html {
        root /var/www/html;
    }

    location ~ \.php$ {
          try_files $uri =404;
          #此次可以配置socket和tcp端口2种方式
          fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          include fastcgi_params;
    }
}
chown www-data:www-data -R html
systecmctl reload nginx
测试
vim /var/www/html/index.php

<?php
        echo phpinfo();

输入网址查看

上一篇下一篇

猜你喜欢

热点阅读