Home PHP Framework ThinkPHP Things to note when deploying thinkphp5.1 on Baidu Cloud Host

Things to note when deploying thinkphp5.1 on Baidu Cloud Host

Jun 13, 2020 pm 02:37 PM
thinkphp5.1

下面由TP5教程栏目给大家介绍在百度云主机上部署thinkphp5.1的注意事项,希望对需要的朋友有所帮助!

Things to note when deploying thinkphp5.1 on Baidu Cloud Host

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';
Copy after login

改为

 // 应用目录
define('APP_PATH', __DIR__.'/application/');
// 加载框架引导文件
require './thinkphp/start.php';
Copy after login

由于这里涉及到修改框架结构,本着尽量少改动的想法,我没有选择这种做法

第二,在webroot目录下新建index.php文件,增加一句代码即可

<?php
require &#39;./public/index.php&#39;;
Copy after login

这样就实现了通过新添加引导文件引导到我们正确的入口文件的目的,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;
    }
 }
Copy after login

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;
    }
Copy after login

或者第三种办法,bcloud_nginx_user.conf种添加代码如下

location / {
root /home/bae/app/public;
index index.php index.html index.htm;
}
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What Are the Key Considerations for Using ThinkPHP in a Serverless Architecture? What Are the Key Considerations for Using ThinkPHP in a Serverless Architecture? Mar 18, 2025 pm 04:54 PM

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

What Are the Advanced Features of ThinkPHP's Dependency Injection Container? What Are the Advanced Features of ThinkPHP's Dependency Injection Container? Mar 18, 2025 pm 04:50 PM

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

What Are the Key Features of ThinkPHP's Built-in Testing Framework? What Are the Key Features of ThinkPHP's Built-in Testing Framework? Mar 18, 2025 pm 05:01 PM

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.

How to Implement Service Discovery and Load Balancing in ThinkPHP Microservices? How to Implement Service Discovery and Load Balancing in ThinkPHP Microservices? Mar 18, 2025 pm 04:51 PM

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

What Are the Best Ways to Handle File Uploads and Cloud Storage in ThinkPHP? What Are the Best Ways to Handle File Uploads and Cloud Storage in ThinkPHP? Mar 17, 2025 pm 02:28 PM

The article discusses best practices for handling file uploads and integrating cloud storage in ThinkPHP, focusing on security, efficiency, and scalability.

How to Build a Distributed Task Queue System with ThinkPHP and RabbitMQ? How to Build a Distributed Task Queue System with ThinkPHP and RabbitMQ? Mar 18, 2025 pm 04:45 PM

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

How to Use ThinkPHP for Building Real-Time Collaboration Tools? How to Use ThinkPHP for Building Real-Time Collaboration Tools? Mar 18, 2025 pm 04:49 PM

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

How to Use ThinkPHP for Building Real-Time Stock Market Data Feeds? How to Use ThinkPHP for Building Real-Time Stock Market Data Feeds? Mar 18, 2025 pm 04:57 PM

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

See all articles