簡單在 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