debian 卸载php5,debian jessie上面安装nginx/php5

debian jessie上面默认安装php5会自动安装apache2,这一点有点讨厌啊,想用nginx还要想点办法,下面就是解决方案。

安装ngnix

debian jessie默认自带的ngnix有点老了(1.6.2),最好使用dotdeb提供的最新版本(不建议安装nginx官网的源,不支持systemd,无法通过service启停nginx服务,自然也无法享受systemd的其他好处)。首先添加dotdeb源的签名(注意wget的参数是大写的字母O):

wget -qO - wget https://www.dotdeb.org/dotdeb.gpg | apt-key add -

1

wget-qO-wgethttps://www.dotdeb.org/dotdeb.gpg | apt-key add -

然后在/etc/apt/sources.list.d目录下增加一个文件dotdeb.list,内容如下:

deb-src http://mirrors.teraren.com/dotdeb/ jessie all

1

deb-srchttp://mirrors.teraren.com/dotdeb/ jessie all

执行:

aptitude update;aptitude install nginx

1

aptitudeupdate;aptitudeinstallnginx

ps一下可以看出,安装成功后nginx已经跑起来了。

安装php

如果已经装过apache2的话,首先彻底删除:

aptitude purge apache2

1

aptitudepurgeapache2

然后安装php5相关组件:

apt-get install php5-fpm php5-common php5-sqlite php5-gd php5-mysql php-pear php5-imap php5-mcrypt php5-curl

1

apt-getinstallphp5-fpmphp5-commonphp5-sqlitephp5-gdphp5-mysqlphp-pearphp5-imapphp5-mcryptphp5-curl

配置nginx和php

nginx的主要配置文件/etc/nginx/sites-enabled/mysite的内容如下:

##

# Default server configuration

#

server {

listen 80 default_server;

listen [::]:80 default_server ipv6only=on;

root /var/www/html;

index index.php index.html index.htm index.nginx-debian.html;

server_name softlab.sdut.edu.cn;

location / {

# First attempt to serve request as file, then

# as directory, then index.php, then fall back to displaying a 404.

try_files $uri $uri/ /index.php =404;

}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

location ~ \.php$ {

include snippets/fastcgi-php.conf;

# With php5-fpm:

fastcgi_pass unix:/var/run/php5-fpm.sock;

}

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

##

# Default server configuration

#

server{

listen80default_server;

listen[::]:80default_serveripv6only=on;

root/var/www/html;

indexindex.phpindex.htmlindex.htmindex.nginx-debian.html;

server_namesoftlab.sdut.edu.cn;

location/{

# First attempt to serve request as file, then

# as directory, then index.php, then fall back to displaying a 404.

try_files$uri$uri//index.php=404;

}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

location~\.php${

includesnippets/fastcgi-php.conf;

# With php5-fpm:

fastcgi_passunix:/var/run/php5-fpm.sock;

}

}

php的主要配置文件/etc/php5/fpm/php-fpm.conf文件参见附件php-fpm.conf(去掉txt文件扩展名),/etc/php5/fpm/php.ini文件参见附件php.ini

that’s all!

然后:

systemd restart nginx.service

systemd restart php5-fpm.service

1

2

systemdrestartnginx.service

systemdrestartphp5-fpm.service

如果没有报错,就算是成功了。

排错

如果在执行systemd的时候出错,可以通过systemd status service_name -l查看具体信息以方便排错。

最容易犯的错误是php5-fpm.conf中的php5-fpm.sock路径和nginx配置文件定义的不一样,结果造成php请求无法发送到php5-fpm,因此要仔细检查。

d4c39bd54dfbfe627dbd9fe226767b2c.png

0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值