先更新源
apt-get update
安裝 MySQL5.7 運行命令:
apt-get -y install mysql-server mysql-client
安裝期間要求設置MySQL的root用戶密碼 :
New password for the MySQL “root” user: <– yourrootsqlpassword
Repeat password for the MySQL “root” user: <– yourrootsqlpassword
myql命令
service mysqld stop
service mysql restart
增加操作用戶
GRANT ALL ON *.* TO test@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
安裝 Nginx
如果你已經安裝了Apache2的話,那麼使用這些命令先刪除再安裝nginx:
service apache2 stop
update-rc.d -f apache2 remove
apt-get remove apache2
Ubuntu16.04有Nginx安裝包,我們可以安裝。
apt-get -y install nginx
啓動ngninx:
service nginx start
輸入您的Web服務器的IP地址或主機名到瀏覽器(例如120.132.114.131),你應該
Ubuntu16.04的默認nginx的文檔根目錄爲/var/www/html
安裝 PHP 7
apt-get -y install php7.0-fpm
配置 nginx
打開配置文件 /etc/nginx/nginx.conf:
vi /etc/nginx/nginx.conf
配置很容易理解 (你可以點擊官方教程: http://wiki.nginx.org/NginxFullExample或:http://wiki.nginx.org/NginxFullExample2)
首先(這是可選)調整keepalive_timeout到一個合理的值:
[...]
keepalive_timeout 2;
[...]
虛擬主機服務器{}容器定義。默認的虛擬主機是在/etc/nginx/sites-available/default 文件中定義- 修改它,如下所示:
vi /etc/nginx/sites-available/default
[...]
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using 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;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
[...]
server_name _; 使這是一個默認虛擬主機(當然,你可以同時喜歡這裏www.example.com指定主機名)。
根目錄 /var/www/html;意味着文檔根目錄/var/www/html.
PHP重要組成部分位置 ~ \.php$ {} stanza. 取消註釋它來啓用它。
現在保存文件並重新加載nginx:
service nginx reload
下一步打開 /etc/php/7.0/fpm/php.ini…
vi /etc/php/7.0/fpm/php.ini
設置 cgi.fix_pathinfo=0:
[...]
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting
; of zero causes PHP to behave as before. Default is 1. You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=0
[...]
重新加載 PHP-FPM:
service php7.0-fpm reload
建立探針文件/var/www/html:
vi /var/www/html/info.php
<?php
phpinfo();
?>
瀏覽器訪問 (e.g. 120.132.114.131/info.php):
讓 MySQL 獲得 PHP 7支持
先搜索一下PHP支持的模塊:
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 php-gettext
APCu是隨PHP7 PHP Opcache模塊的擴展,它增加了一些兼容性功能的支持APC緩存(例如WordPress的插件緩存)軟件。
APCu可以安裝如下:
apt-get -y install php-apcu
重新加載 PHP-FPM:
service php7.0-fpm reload
刷新 120.132.114.131/info.php 瀏覽器看看模塊安裝情況:
讓 PHP-FPM 使用 TCP 連接
默認情況下PHP-FPM監聽 /var/run/php/php7.0-fpm.sock. 另外,也可以使 PHP-FPM 試用 TCP 連接,打開文件 /etc/php/7.0/fpm/pool.d/www.conf…
vi /etc/php/7.0/fpm/pool.d/www.conf
修改如下:
[...]
;listen = /var/run/php5-fpm.sock
listen = 127.0.0.1:9000
[...]
這將使PHP-FPM端口9000偵聽的IP127.0.0.1(本地主機)。請確保您使用的端口,是不是在你的系統上使用。
然後重新加載 PHP-FPM:
php7.0-fpm reload
接下來通過你的nginx的配置和所有的虛擬主機,並更改fastcgi_pass UNIX行:/var/run/php/php7.0-fpm.sock; tofastcgi_pass127.0.0.1:9000;,如下:
vi /etc/nginx/sites-available/default
[...]
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;
}
[...]
最後,重新加載nginx:
service nginx reload