apt安装php7.1,ubuntu lnmp 环境配置 php7.1

本文详细记录了一名新手在手动配置LNMP环境过程中遇到的挑战,包括编译安装Nginx和PHP,以及安装和配置MongoDB扩展。在PHP卸载、目录清理、错误排查等方面遇到了问题,通过解决权限不足、配置文件错误等难题,最终成功完成安装。文章强调了解决问题时查看日志的重要性,并提供了完整配置步骤和注意事项。
摘要由CSDN通过智能技术生成

折腾了有两天晚上,由于之前服务器配置的时候用的 wdlinux或阿里市场提供的一键安装包。没想到手动配置这么多坑!新手直接伤不起。记录一下完整的历程

开始采用的编译安装。

1 下载nginx,编译安装

2 下载php 编译安装

编译安装后卸载的时候,发现 php目录下 没有 make uninstall 。所以很多目录要手动删除。比较蛋疼

所以尽量采用apt-get 安装

#更新apt-get源

apt-get update

#更新现有软件

apt-get upgrade

安装php

#安装add-apt-repository命令依赖

apt-get install software-properties-common

#添加php源

add-apt-repository ppa:ondrej/php

#更新apt数据,载入php源数据

apt-get update

#安装php-fpm

apt-get install php7.1-fpm

#安装pear

##安装pear依赖

apt-get install php7.1-xml

##安装pear

apt-get install php-pear

#安装mongodb扩展

##安装phpize,包含在php-dev中

apt-get install php7.1-dev

##安装openssl

apt-get install -y autoconf g++ make openssl libssl-dev libcurl4-openssl-dev

##安装mongodb扩展

pecl install mongodb

##在php.ini中添加:extension=mongodb.so

vi /etc/php/7.1/fpm/php.ini

vi /etc/php/7.1/cli/php.ini

##重启php-fpm

service php7.1-fpm restart

安装nginx

cd /root

#下载key

wget http://nginx.org/keys/nginx_signing.key

#添加key

apt-key add nginx_signing.key

#添加源,vi打开sources列表

vi /etc/apt/sources.list

#在文件末位添加如下两行:

deb http://nginx.org/packages/ubuntu/ trusty nginx

deb-src http://nginx.org/packages/ubuntu/ trusty nginx

#更新apt数据,载入nginx源数据

apt-get update

#安装nginx(安装的版本号至少为1.10+,注意检查)

apt-get install nginx

#修改nginx配置文件

##修改/etc/nginx/conf.d/default.conf

vi /etc/nginx/conf.d/default.conf

###修改"location /"位置

root /www;

index index.html index.htm index.php;

###取消"location ~ \.php"的注释,如下三行对应修改

root /www;

fastcgi_pass unix:/run/php/php7.1-fpm.sock;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

##修改/etc/nginx/nginx.conf

vi /etc/nginx/nginx.conf

##重启加载配置

service nginx restart

安装完成,配置nginx及项目路径

修改nginx:默认配置文件在  /etc/nginx/conf.d/default.conf

server {

listen 80;

server_name localhost;

#charset koi8-r;

#access_log /var/log/nginx/log/host.access.log main;

location / {

root /web/test;

index index.html index.htm index.php;

}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root /usr/share/nginx/html;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

# proxy_pass http://127.0.0.1;

#}

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

#

location ~ \.php$ {

root /web/test;

fastcgi_pass unix:/run/php/php7.1-fpm.sock;

fastcgi_index index.php;

fastcgi_intercept_errors on;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

#location ~ /\.ht {

# deny all;

#}

}

这个地方有几个坑

1.由于php7.x以后默认通 socket 方式与nginx通讯,而不是默认的监听127.0.0.1:9000

fastcgi_pass unix:/run/php/php7.1-fpm.sock;

2. 没有使用变量 $document_root ,写错路径报错

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

3.重启后发现nginx继续报错,查看log,提示php7.1-fpm权限不足

这个地方浪费时间比较多,最终原因就是 用户组错误

修改php-fpm: /etc/php/7.1/fpm/pool.d/www.conf

; Set permissions for unix socket, if one is used. In Linux, read/write

; permissions must be set in order to allow connections from a web server. Many

; BSD-derived systems allow connections regardless of permissions.

; Default Values: user and group are set as the running user

; mode is set to 0660

listen.owner = nginx

listen.group = nginx

listen.mode = 0660

重启ok,看到phpinfo信息,终于弄完了。

有问题多看一下log,按照log去解决问题。

参考网址:http://www.cnblogs.com/sanmu083/p/5922689.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值