Ubuntu16 php7 nginx配置

#更新
sudo apt-get update

# 安裝php 和nginx
sudo apt-get install php
sudo apt-get install nginx

#php 版本查看
root@iZrj9a7wyzv7b431m860gxZ:~# php -v
PHP 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.22-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies


#nginx 版本查看
root@iZrj9a7wyzv7b431m860gxZ:~# nginx -v
nginx version: nginx/1.10.3 (Ubuntu)

#配置nginx 解開php配置註釋
sudo vim /etc/nginx/sites-available/default
#改爲以下

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.php index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;

        #       # With php7.0-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php7.0-fpm:
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }


#啓動
php7.0-fpm start
ngnix 

#編輯首頁
vi /var/www/html/index.php 
<?php
phpinfo();

訪問瀏覽器器便可
# 安裝php模塊 (參考https://www.howtoforge.com/tutorial/installing-nginx-with-php7-fpm-and-mysql-on-ubuntu-16.04-lts-lemp/
)

#查詢可用模塊
apt-cache search php7.0
#安裝模塊
apt-get -y install php7.0-mysql php7.0-curl php7.0-gd php7.0-intl php-pear php-imagick php7.0-imap php7.0-mcrypt php-memcache  php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy php7.0-xmlrpc php7.0-xsl php7.0-mbstring
# 修改後從新加載配置
service php7.0-fpm reload
service nginx reload

 

nginx 301配置php

server {
        listen 80;
        server_name xxx.me;
        return 301 $scheme://www.xxx.me$request_uri;
}
相關文章
相關標籤/搜索