thinkphp5+nginx的linux环境搭建
php7已经出来许久,一直没有体验,是因为原来的项目是5.4和5.6的,不敢轻易升级,后期新项目再打算使用php7,本文所安装的php为5.6
安装环境&工具
阿里云:centos7.3
ssh:putty
sftp:winscp
注意事项:
1、阿里云的ECS服务器默认yum源都是阿里镜像的,所以如果下载速度非常慢,请更换至国内的源
2、默认情况下阿里云的selinux是关闭的,执行命令/usr/sbin/sestatus -v查看
3、默认情况下,yum中的php包版本是5.4.16,并且不自带nginx(最新阿里云centos7.3的yum自带了1.10.2),所以需要去第三方加载
执行2行代码即可
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpmrpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安装php
第三方加载完成之后,执行yum search php则可以看到新添加的版本包,按照需要自行添所需的包即可。
yum install php56w php56w-opcache php56w-fpm php56w-common php56w-devel php56w-gd php56w-mbstring php56w-mcrypt php56w-mysqlnd php56w-pdo php56w-pecl-imagick php56w-xml php56w-pecl-memcache php56w-pecl-xdebug php-redis php56w-pecl-memcached.x86_64
等待安装完成之后输入指令php -v查看是否安装成功
[root@iZwz97oclpnqnt538u8jk8Z ~]# php -vPHP 5.6.30 (cli) (built: Jan 19 2017 22:31:39)Copyright (c) 1997-2016 The PHP GroupZend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologieswith Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologieswith Xdebug v2.5.3, Copyright (c) 2002-2017, by Derick Rethans
安装nginx
由于阿里云centos7.3的yum自带了1.10.2,但也不是最新版,所以还是选择了第三方的nginx1w包(1.12.0)
执行命令
yum install nginx1w[root@iZwz97oclpnqnt538u8jk8Z ~]# nginx -vnginx version: nginx/1.12.0
运行服务器
[root@iZwz97oclpnqnt538u8jk8Z ~]# service nginx start
Redirecting to /bin/systemctl start nginx.service
[root@iZwz97oclpnqnt538u8jk8Z ~]# service php-fpm start
Redirecting to /bin/systemctl start php-fpm.service
[root@iZwz97oclpnqnt538u8jk8Z ~]# service nginx startRedirecting to /bin/systemctl start nginx.service[root@iZwz97oclpnqnt538u8jk8Z ~]# service php-fpm startRedirecting to /bin/systemctl start php-fpm.service
输入服务器地址,如下图

安装thinkphp
获取ThinkPHP的方式很多,官方网站(http://thinkphp.cn)提供了稳定版本或者带扩展完整版本的下载。
这里我们选择使用Composer安装,因为后期开发也会用到Composer管理php包
安装Composer
参考Composer国内镜像
这里采用全局安装的方式,分别执行5条指令
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"php composer-setup.phpphp -r "unlink('composer-setup.php');"sudo mv composer.phar /usr/local/bin/composercomposer config -g repo.packagist composer https://packagist.phpcomposer.com[root@iZwz97oclpnqnt538u8jk8Z ~]# composer --versionDo not run Composer as root/super user! See https://getcomposer.org/root for detailsComposer version 1.4.2 2017-05-17 08:17:52
提示:不要忘了经常执行 composer selfupdate 以保持 Composer 一直是最新版本哦!
安装thinkphp
命令行下面,切换到你的web根目录下面(一般是/var/www/)并执行下面的命令:
composer create-project topthink/think tp5 --prefer-dist[root@iZwz97oclpnqnt538u8jk8Z www]# cd tp5[root@iZwz97oclpnqnt538u8jk8Z tp5]# lsapplication composer.json extend public runtime thinkphpbuild.php composer.lock LICENSE.txt README.md think vendor
配置nginx.conf
见/etc/nginx/nginx.conf
详细配置内容参考nginx官方文档
这里仅在默认配置基础上修改适配thinkphp,线上环境需自行修改。
# For more information on configuration, see:# * Official English Documentation: http://nginx.org/en/docs/# * Official Russian Documentation: http://nginx.org/ru/docs/user nginx;worker_processes 1;error_log /var/log/nginx/error.log;#error_log /var/log/nginx/error.log notice;#error_log /var/log/nginx/error.log info;pid /run/nginx.pid;# Load dynamic module files from the /etc/nginx/conf.modules.d/ directory.# See http://nginx.org/en/docs/ngx_core_module.html#include# for more information.include /etc/nginx/conf.modules.d/*.conf;events {worker_connections 1024;}http {include /etc/nginx/mime.types;default_type application/octet-stream;log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log /var/log/nginx/access.log main;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;# Load modular configuration files from the /etc/nginx/conf.d directory.# See http://nginx.org/en/docs/ngx_core_module.html#include# for more information.include /etc/nginx/conf.d/*.conf;index index.html index.htm;server {listen 80;server_name localhost;root /var/www/tp5/public;#charset koi8-r;#access_log /var/log/nginx/host.access.log main;location / {index index.htm index.html index.php;#使其支持Thinkphp的rewrite模式if (!-e $request_filename) {rewrite ^(.*)$ /index.php?s=$1 last;break;}}location ~ .+\.php($|/) {fastcgi_index index.php;#使其支持thinkphp的pathinfo模式fastcgi_split_path_info ^(.+\.php)(.*)$;include fastcgi_params;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_param SCRIPT_NAME $fastcgi_script_name;fastcgi_param PATH_INFO $fastcgi_path_info;fastcgi_pass 127.0.0.1:9001;}include fastcgi.conf;# redirect server error pages to the static page /40x.html#error_page 404 /404.html;location = /40x.html {}# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {}}}
配置php-fpm
见'/etc/php-fpm.d/www.conf',为了保证高并发,线上根据具体情况具体配置,默认配置文件已经附带说明。
需要注意的是,默认php-fpm的启动用户和用户组都是apache,可以更换成nginx
运行thinkphp
重启nginx
[root@iZwz97oclpnqnt538u8jk8Z tp5]# service nginx reloadRedirecting to /bin/systemctl reload nginx.service
此时我们终于可以访问thinkphp了,由于正确配置了nginx路由,三种模式下均可访问

http://localhost/index/indexhttp://localhost/index.php/index/indexhttp://localhost/index.php?s=/index/index
提示:如果runtime文件夹无法写日志,类似这样的情况,不出意外就是文件夹权限问题,执行命令chown runtime apache:apache赋予权限即可(用户名和用户组要和php-fpm配置中的一致)
最后运行phpinfo()检测配置是否符合预期,根据需要修改。
注意事项
1、启动服务的时候,如果无法启动,2种可能,1个是配置文件有问题,可以采用nginx -t或者php-fpm -t检测,2个是端口冲突
2、一些类似denied的提示和奇怪的问题,优先考虑权限问题,赋予文件夹相应权限。
3、php-mysql默认情况下为了保证安全,所有字段都转化成了string类型,未来已经被抛弃了,而新的php-mysqlnd,在PHP5.4之后的版本mysqlnd被作为默认配置选项,则会自动转换成相关的类型。
4、如未开启opcache,手动在php.ini中去掉opcache.so的注释。
5、$HTTP_RAW_POST_DATA is *NOT* populated.不推荐使用,php.ini中关闭 always_populate_raw_post_data = -1
论制作镜像的重要性
thinkphp5+nginx的linux环境搭建的更多相关文章
- Cacti监控服务器配置教程(基于CentOS+Nginx+MySQL+PHP环境搭建)
Cacti监控服务器配置教程(基于CentOS+Nginx+MySQL+PHP环境搭建) 具体案例:局域网内有两台主机,一台Linux.一台Windows,现在需要配置一台Cacti监控服务器对这两台 ...
- HHvm Apache 2.4 Nginx建站环境搭建方法安装运行WordPress博客
HHvm Apache 2.4 Nginx建站环境搭建方法安装运行WordPress博客 VPS主机 2014年06月02日 17:20 评论» 文章目录 Debian上安装 Ce ...
- Linux环境搭建-在虚拟机中安装Centos7.0
最近在空闲时间学习Linux环境中各种服务的安装与配置,都属于入门级别的,这里把所有的学习过程记录下来,和大家一起分享. 我的电脑系统是win7,所以我需要在win7上安装一个虚拟机-VMware,然 ...
- 【菜鸟学习Linux】-第三章- Linux环境搭建-使用VMware9安装Ubuntu 12.04系统
上一步,我们安装了VMware9虚拟机,现在我们就是用它来安装Ubuntu12.04系统,至于Ubuntu是什么,我就不废话了,大家google一下,比我讲的清楚,好了,开始干活! Ubuntu官网下 ...
- Windows及Linux环境搭建Redis集群
一.Windows环境搭建Redis集群 参考资料:Windows 环境搭建Redis集群 二.Linux环境搭建Redis集群 参考资料:Redis Cluster的搭建与部署,实现redis的分布 ...
- Linux(一)-- Linux环境搭建
Linux环境搭建 一.虚拟机安装 1.下载地址 https://my.vmware.com/web/vmware/info/slug/desktop_end_user_computing/vmwar ...
- Linux(一)—— Linux环境搭建
Linux环境搭建 一.虚拟机安装 1.下载地址 https://my.vmware.com/web/vmware/info/slug/desktop_end_user_computing/vmwar ...
- Linux环境搭建及基础操作
一.Linux环境搭建 1.安装虚拟机软件(VMWare,Parallel) 虚拟机的作用:将本来不是适合当前操作系统的分区虚拟化成适合当前操作系统的分区格式 2.新建虚拟机: 类似买了一台新的电脑, ...
- 【转】Linux环境搭建FTP服务器与Python实现FTP客户端的交互介绍
Linux环境搭建FTP服务器与Python实现FTP客户端的交互介绍 FTP 是File Transfer Protocol(文件传输协议)的英文简称,它基于传输层协议TCP建立,用于Interne ...
随机推荐
- 重装ubuntu
重装前 需要备份软件.配置文件等,重装系统时,最好不要重新给/home分区,也不要格式化,要不你需要备份很多东西,重装后也需要做很多设置.也就是说/home不格式化,整个重装系统都是很快的.最多花10 ...
- org.slf4j.impl.SimpleLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext
查看日志信息: SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/app/a ...
- strerror线程安全分析
导读 strerror是否线程安全了? 1 errno是否线程安全? 1 附1:strerror源码 2 附2:__strerror_r源码 2 strerror是否线程安全了? 答案是NO,但它有个 ...
- 在iOS中使用百度地图
就如同在百度地图的文档中所说的一样,这么来.但是,有一个小疏忽. 到添加完所需要的framework之后,一定要记得把你的(Class-Prefix)AppDelegate的后缀改成mm. 估计百度的 ...
- [Lua快速了解一下]Lua的Table
Lua中的Table其实就是一个Key Value的structure haoel = {name=, handsome=True} -table的CRUD操作 haoel.website=" ...
- Solr: a custom Search RequestHandler
As you know, I've been playing with Solr lately, trying to see how feasible it would be to customize ...
- C和C++中的异常处理
1.简介 许多的编程新手对异常处理视而不见,程序里很少考虑异常情况.一部分人甚至根本就不考虑,以为程序总是能以正确的途径运行.譬如我们有的程序设计者调用fopen打开一个文件后,立马就开始进行读写操作 ...
- 关于typedef的用法总结(装)
不管实在C还是C++代码中,typedef这个词都不少见,当然出现频率较高的还是在C代码中.typedef与#define有些相似,但更多的是不同,特别是在一些复杂的用法上,就完全不同了,看了网上一些 ...
- C++视频教程学习笔记
1. 命名空间 用于解决命名冲突的问题 里面可以放函数.变量.结构体.类 可以嵌套 必须定义在全局作用域下 是开放的,可以随时往原先的命名空间中追加内容,而不是覆盖 实现命名空间下的函数和调用时,需要 ...
- CH的电影推荐
1.推荐电影 张艺谋:一个都不能少 2.下载站点 TL95