Debian 8下部署LNP

2019-07-03丨运维丨暂无评论 丨1247 次阅读
cp -r /etc/apt/sources.list /etc/apt/sources.list.bak;echo "deb http://archive.debian.org/debian/ jessie main contrib non-free" > /etc/apt/sources.list;cat /etc/apt/sources.list;apt-get update;

apt-get install nginx -y
安装完成后,Nginx会自动运行。

service nginx status
查看Nginx版本

nginx -v

安装PHP

apt-get install php-fpm php-mysql php-common php-gd php-json php-cli php-curl php-mbstring

配置Nginx

nano /etc/nginx/nginx.conf
第一行user nginx; 将nginx替换为www-data

在这个文件中为找到worker_processes,为它指定一个值,这个值就是服务器CPU的数量。使用下面的命令查看服务器CPU的数量:

lscpu
我的服务器只有一个CPU,所以我将worker_processes的值设为1。

worker_processes 1;
修改/etc/nginx/conf.d/default.conf文件

vi /etc/nginx/conf.d/default.conf
删除原内容,将下面的内容添加到文件中。

server {
listen 80;
server_name debian.local;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;

location / {
try_files $uri $uri/ =404;
}

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;

location = /50x.html {
root /var/www/html;
}

location ~ .php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
其中,root /var/www/html; 表示网站的根目录,server_name debian.local 表示Server FQDN. 保存文件并退出文本编辑器。 重启Nginx:

service nginx restart
测试nginx的配置

输入下面的命令以查看nginx的配置中有没有语法错误:

nginx -t
如果没有语法错误,那么命令输出结果如下:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful
测试PHP

在网站的根目录下面创建一个testphp.php文件。

vi /var/www/html/testphp.php
在文件中添加如下内容

标签:

热门文章

最新回复

标签

发表新评论