簡單在 Ubuntu(適和虛擬機器) 配置 Nginx 和 php71

來源:互聯網
上載者:User
簡單在 Ubuntu 配置 nginx 和 php71

因為本人主要在使用 mac ,剛買了一個螢幕,所有在虛擬機器下裝一個 ubuntu 系統用於使用。

參考:
Ubuntu中LNMP環境的搭建
Ubuntu 安裝 lnmp Laravel 入坑 day-1
各個環境下安裝php7.1 先將 apt-get 換成阿里雲的源 先備份,cp /etc/apt/source.list /etc/apt/source.list.copy

sudo vim /etc/apt/source.list,將內容替換為

# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricteddeb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-propertiesdeb http://mirrors.aliyun.com/ubuntu/ xenial main restricteddeb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-propertiesdeb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricteddeb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-propertiesdeb http://mirrors.aliyun.com/ubuntu/ xenial universedeb http://mirrors.aliyun.com/ubuntu/ xenial-updates universedeb http://mirrors.aliyun.com/ubuntu/ xenial multiversedeb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiversedeb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-propertiesdeb http://archive.canonical.com/ubuntu xenial partnerdeb-src http://archive.canonical.com/ubuntu xenial partnerdeb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricteddeb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-propertiesdeb http://mirrors.aliyun.com/ubuntu/ xenial-security universedeb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse

更新一下源sudo apt-get update 安裝 nginx 和 配置 apt-get install nginx 配置支援 php
修改index的一行修改為:index index.html index.php index.htm index.nginx-debian.html;

去掉下面部分的注釋用於支援 php 指令碼:

  location ~ \.php$ {  include fastcgi.conf; #需放在第一行,否則會出錯  fastcgi_pass unix:/run/php/php7.0-fpm.sock;  fastcgi_index index.php;  fastcgi_intercept_errors on;  include fastcgi_params;}
重啟 nginx /etc/init.d/nginx restart 或者 systemctl restart nginx

在 /var/www/html建立一個 test.php

<?php phpinfo();

配置 wordpress 的偽靜態

location / {if (-f $request_filename/index.html){    rewrite (.*) $1/index.html break;}if (-f $request_filename/index.php){    rewrite (.*) $1/index.php;}if (!-f $request_filename){    rewrite (.*) /index.php;}}

配置 Nginx 檔案索引配置

location / {  #開啟瀏覽目錄功能  autoindex on;  #關閉詳細檔案大小統計,讓檔案大小顯示MB,GB單位,預設為b  autoindex_exact_size off;  #開啟以伺服器本地時區顯示檔案修改日期  autoindex_localtime on;}
安裝 php71

安裝

sudo add-apt-repository ppa:ondrej/phpsudo apt-get updatesudo apt-get install php7.1//如果需要fpm的話sudo apt-get install php7.
安裝拓展(類似下面)
sudo apt-get install php7.1-mbstring 安裝 composer

安裝並切換中國源

sudo apt-get install composercomposer config -g repo.packagist composer https://packagist.phpcomposer.com

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.