ubuntu升级php7.0

php -v 查看自己的的php版本,5.5.9 ,我都不知道为什么我会用这么老的php版本 /(ㄒoㄒ)/~~

添加新源

1
sudo add-apt-repository ppa:ondrej/php

更新源

1
sudo apt-get update

php与nginx搭配下的配置方法

1.安装php7

1
sudo apt-get install php7.0-fpm

2.安装mysql模块

1
sudo apt-get install php7.0-mysql

3.更新nginx下php的配置 不同版本的php的路径 PHP 5 PHP 7 —- —- /var/run/php5-fpm.sock /var/run/php/php7.0-fpm.sock 4.用nano打开默认的nginx配置

1
sudo nano /etc/nginx/sites-enabled/default

location ~ \.php$ {}找到 fastcgi_pass unix:/var/run/php5-fpm.sock;将这里的路径更改为php的路径unix:/var/run/php/php7.0-fpm.sock

/etc/nginx/sites-enabled/default 目录下的详细配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /var/www/html;
index index.php index.html index.htm;

server_name server_domain_name_or_IP;

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

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

5.测试是否成功 php -v 6.新建info.php放在根目录

报错

1
Module php5 is enabled - cannot proceed due to conflicts. It needs to be disabled first!

首先停止 php5 module:

1
sudo a2dismod php5

开启 php7 module:

1
a2enmod php7.0

最后重启一下apache服务器

1
sudo service apache2 restart