在 Debian 8 下,通过 APT 安装最新版本 Nginx 1.13 及 PHP7

0、准备工作

以下操作均在 Debian8 x64 root 环境下操作。

apt-get update && apt-get install vim wget curl apt-transport-https lsb-release ca-certificates -y

1、安装 Nginx

wget http://nginx.org/keys/nginx_signing.key && apt-key add nginx_signing.key && rm nginx_signing.key && echo "deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx" >> /etc/apt/sources.list.d/nginx.list && echo "deb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx  " >> /etc/apt/sources.list.d/nginx.list && echo "deb http://httpredir.debian.org/debian/ jessie-backports main contrib non-free" >> /etc/apt/sources.list.d/backports.list && echo "deb-src http://httpredir.debian.org/debian/ jessie-backports main contrib non-free" >> /etc/apt/sources.list.d/backports.list && apt-get update && apt-get install -t jessie-backports openssl -y && apt-get install -y nginx

2、安装 PHP7

wget https://www.dotdeb.org/dotdeb.gpg && apt-key add dotdeb.gpg && rm dotdeb.gpg && echo "deb http://packages.dotdeb.org $(lsb_release -sc) all" >> /etc/apt/sources.list.d/php.list && echo "deb-src http://packages.dotdeb.org $(lsb_release -sc) all" >> /etc/apt/sources.list.d/php.list && apt-get update && apt-get install php7.0-fpm php7.0-mysql php7.0-curl php7.0-gd php7.0-mbstring php7.0-mcrypt php7.0-xml php7.0-xmlrpc php7.0-zip -y && sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php/7.0/fpm/php.ini

3、配置 Nginx 及 PHP7

更新 PHP7 监听用户为 nginx

vim /etc/php/7.0/fpm/pool.d/www.conf

i 进入编辑,找到

listen.owner = www-data
listen.group = www-data
;listen.mode = 0660

更改为

listen.owner = nginx
listen.group = nginx
listen.mode = 0660

Esc 键退出编辑,按 :wq 保存退出,重启 php-fpm

service php7.0-fpm restart

编辑 Nginx 配置文件,在 server { 后加上

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

重启 Nnginx 即可

service nginx restart

安装 Mysql

使用 Percona Server 代替原生的 MySQL

wget https://repo.percona.com/apt/percona-release_0.1-4.$(lsb_release -sc)_all.deb && dpkg -i percona-release_0.1-4.$(lsb_release -sc)_all.deb && apt-get update && apt-get install percona-server-server-5.7 -y

然后进行安全设置

mysql_secure_installation  
root@demo:~# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 

VALIDATE PASSWORD PLUGIN can be used to test passwords  
and improve security. It checks the strength of password  
and allows the users to set only those passwords which are  
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No:y 请输入 y 进行初始安全设置

There are three levels of password validation policy:

LOW    Length >= 8  
MEDIUM Length >= 8, numeric, mixed case, and special characters  
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 最强大的密码当然要输入 2

Using existing password for root.

Estimated strength of the password: 100  
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n 如果之前设置了强密码,则不需要重新更改 root 密码,反之则按 y 回车后输入两次重置

By default, a MySQL installation has an anonymous user,  
allowing anyone to log into MySQL without having to have  
a user account created for them. This is intended only for  
testing, and to make the installation go a bit smoother.  
You should remove them before moving into a production  
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y 移除匿名用户,没啥鸟用就直接移除吧

Normally, root should only be allowed to connect from  
'localhost'. This ensures that someone cannot guess at  
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y 关闭 root 远程登录,不需要进行远程登录的话就关了吧  
Success.

By default, MySQL comes with a database named 'test' that  
anyone can access. This is also intended only for testing,  
and should be removed before moving into a production  
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) :y 移除 test 数据库

Reloading the privilege tables will ensure that all changes  
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y 重置数据库权限  

因为我现在的需求只需要 PHP 及 Nginx,所以就没写关于 Mysql、FTP 或其他的东西。


  2017-05-25     Debian8, Nginx, PHP     返回顶部