下面由TP5教程栏目给大家介绍在百度云主机上部署thinkphp5.1的注意事项,希望对需要的朋友有所帮助!
thinkphp5.1部署在百度云主机的注意事项
网站建好了,找了一圈好点的云主机部署,首先看的是openshift,虽然有免费的支持,但是限制很多,且部署相当麻烦。正好看到最近百度云主机做活动,于是搞了一个bch玩一玩。但是也遇到很多坑,加上百度云主机对应的支持文档写的简单随意,也是遇到不少麻烦,整理出来,供参考。
1、程序文件上传位置
需要把你的程序根目录文件下的文件和文件夹上传到云主机对应的/webroot目录下,/webroot下此时已经有一些系统自动生成的文件,没关系,直接把你的文件内容(注意不是你的程序文件的根目录这一个文件夹,而是根目录下的所有内容)上传到这里就可以了。
2、首页无法进入的问题
无法进入自己的首页,主要因为从是thinkphp5开始,入口页面index.php被放在了public目录下了,所以,nginx这时候找不到入口文件,所以进步了主页。这时候有两种处理办法:
第一,是将你的入口文件从public下copy到webroot下面,这里需要注意修改你入口文件中的配置,比如:
// 定义应用目录 define('APP_PATH', __DIR__ . '/../application/'); require __DIR__ . '/../thinkphp/start.php';
改为
// 应用目录 define('APP_PATH', __DIR__.'/application/'); // 加载框架引导文件 require './thinkphp/start.php';
由于这里涉及到修改框架结构,本着尽量少改动的想法,我没有选择这种做法
第二,在webroot目录下新建index.php文件,增加一句代码即可
<?php require './public/index.php';
这样就实现了通过新添加引导文件引导到我们正确的入口文件的目的,OK,这个时候你再试下,程序正常进入首页
3、只有首页能进入,其他页面404无法找到文件
主要是因为在thinkphp中做了url的重写PATHINFO,隐藏了入口文件,所以你在你的apache服务器中是没有感知,http://localhost/index.php 与 http://localhost 是一样的效果,但是在云虚拟机中,用的是nginx,这个时候,你的入口文件就隐藏不了了,如果要隐藏,就会报错404无法找到文件。要么你在处理时候注意加上入口文件,要么做url重写。
在webroot下新建bcloud_nginx_user.conf文件,代码如下:
location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; break; } }
4、可能你会遇到静态文件js/css/images等文件找不到,缺少样式等问题
这个时候你可以看看加载web时候,静态网页的地址是否正确,三种办法处理,一是在你的php的template.conf文件中做replace配置修改,把相应的文件做好别名;一种是重定向,在webroot下添加文件bcloud_nginx_user.conf,添加代码
location ~ ^/(images|javascript|js|css|flash|media|static)/ { root /home/bae/app/htdocs; #过期30天,静态文件不怎么更新,过期可以设大一点,如果频繁更新,则可以设置得小一点。 expires 30d; }
或者第三种办法,bcloud_nginx_user.conf种添加代码如下
location / { root /home/bae/app/public; index index.php index.html index.htm; }
The above is the detailed content of Things to note when deploying thinkphp5.1 on Baidu Cloud Host. For more information, please follow other related articles on the PHP Chinese website!

The article discusses ThinkPHP's built-in testing framework, highlighting its key features like unit and integration testing, and how it enhances application reliability through early bug detection and improved code quality.

Article discusses using ThinkPHP for real-time stock market data feeds, focusing on setup, data accuracy, optimization, and security measures.

The article discusses key considerations for using ThinkPHP in serverless architectures, focusing on performance optimization, stateless design, and security. It highlights benefits like cost efficiency and scalability, but also addresses challenges

The article discusses implementing service discovery and load balancing in ThinkPHP microservices, focusing on setup, best practices, integration methods, and recommended tools.[159 characters]

ThinkPHP's IoC container offers advanced features like lazy loading, contextual binding, and method injection for efficient dependency management in PHP apps.Character count: 159

The article discusses using ThinkPHP to build real-time collaboration tools, focusing on setup, WebSocket integration, and security best practices.

ThinkPHP benefits SaaS apps with its lightweight design, MVC architecture, and extensibility. It enhances scalability, speeds development, and improves security through various features.

The article outlines building a distributed task queue system using ThinkPHP and RabbitMQ, focusing on installation, configuration, task management, and scalability. Key issues include ensuring high availability, avoiding common pitfalls like imprope


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6
Visual web development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.