thinkphp部署到服务器(thinkPHP)

thinkphp怎么部署(thinkphp5部署)

前端vue与后端Thinkphp在服务器的部署

vue在服务端部署时,我们都知道通过npmrunbuild指令打包好的dist文件,通过http指定是可以直接浏览的,Thinkphp通肢局如过域名指向index.php文件才可以浏览。要使前端正常调用后端数据,有两种方法:1、前端跨域调用后端数据,2、前端打包文件部署在后端的服务器文件夹下(同域)。

web服务器:apache

一、跨域

在服务器配置站点:

在路径/home/www/??下创建test项目文件夹,用来放项目文件。??

找到httpd-vhosts.conf文件配置站点??

前端站点:??

????ServerName?test.test.com??

????DocumentRoot?"/home/www/test/dist"????

????DirectoryIndex?index.html??

后端站点:??

????ServerName?test.testphp.com??

????DocumentRoot?"/home/www/test/php"????

????DirectoryIndex?index.php??

将前端打包历启好的dist文件放在/home/www/test/文件夹下,运行可浏览,当路径改变时,刷新会出现404错误。此时dist文件下创建一个.htaccess文件,当路径不存在时,路径指向能解决此问题。

??RewriteEngine?On??

??RewriteBase?/??

??RewriteRule?^index\.html$?-?[L]??

??RewriteCond?%{REQUEST_FILENAME}?!-f??

??RewriteCond?%{REQUEST_FILENAME}?!-d??

??RewriteRule?.?/index.html?[L]??

在/home/www/test文件夹下创建项目根目录php文件夹,将thinkphp文件放在php下。TP5的入口文件在public文件下,在这将public下的入口文件index.php挪到php文件夹下(个人习惯将入口文件放在项目根目录),后端绑定Index模块。

前端调用后端接口,存在跨域,跨域解决方法有好几种,在这我将在后端php做配置,解决跨域问题,在公用控制器设置跨域配置:

class?Common?extends?Controller??

{??

????public?$param;??

????//?设置跨域访问??

????public?function?_initialize()??

????{??

????????parent::_initialize();??

????????isset($_SERVER['HTTP_ORIGIN'])???header('Access-Control-Allow-Origin:?'.$_SERVER['HTTP_ORIGIN'])?:?'腊凯';??

????????header('Access-Control-Allow-Credentials:?true');??

????????header('Access-Control-Allow-Methods:?GET,?POST,?PUT,?DELETE,?OPTIONS');??

????????header("Access-Control-Allow-Headers:?Origin,?X-Requested-With,?Content-Type,?Accept,?authKey,?sessionId");??

$param?=??Request::instance()-param();??

$this-param?=?$param;??

????}??

}??

前端调用登录接口:this.axios.post('',{user:'',password:''})。

(可在webpack.base.conf.js文件下可定义接口:)

二、同域

后端配置同上,公共配置器中的header配置注释。将前端的dist文件下的所有文件(包含.htaccess),放在php文件夹下。将后端index控制器的index方法的路径重定向php下的index.html文件:

namespace?app\index\controller;??

use?think\Controller;??

class?Index?extends?Controller??

{??

????public?function?index()?{??

$this-redirect('/index.html');??

????}??

}??

前端调用登录接口:this.axios.post('/index.php/base/login',{user:'',password:''})

转自:

thinkphp怎么部署到ubuntu

1、开启服务

部分必需使用服务没有默认开启,必需开启后才能正常使用Thinkphpsae引擎,使网站正常工作。必需服务:MySql服务,用于mysql数据库存储数据、Strorage服务,用于存储上传文件销肆、Memcache服务,用于存储Thinkphp缓存、KVDB,用于存储键值数据。根据网站需要开启相关服务,以上为常见的sae服务。

2、缓存清除

如果开启了调试输出trace,然后关闭了,但是网页还是显示trace信息,需要把网站的缓存数据删除后生效,点击Memcache服务,Memcache状态下选择清空即可,如果没有在sae上部署则是直接删除相关缓存文件。

3、原生sae服务

由于sae提供原生服务不能与其他环境兼容,为使网站移植性更好,应该尽量少直接使用原耐斗码生服务,可以选择使用Thinkphp中相应的方法来实现。sae禁止本地IO,所有直接操作本地IO的函数都失效,需要使用sae其他服务来实现,这点一定要注意。

4、代码上传

可以直接上传代码包到sae上,可以使用svn来上传代码

5、屏蔽index.php

在代码根目录下的config.yaml中加入以下代码即可

handle:

-rewrite:if(!is_dir()!is_file()path~"^(.*)$")goto"index.php/$1"呵呵以后毕竟是电脑的时代,可以自己看一下php语言编程一类的知识昌哪,以后总会有用的,我天天晚上去后盾人看视频,我觉得不错的。

如何在lnmp上部署Thinkphp

ThinkPHP的四种URL模式:0(普通迅亩模式);1(PATHINFO模式);2(REWRITE模式);3(兼容模式)

nginx需要PATHINFO模式,但需要更改nginx配置文件让其支持PATHINFO模式。

系统环境:

系统:CentOS-6.4-x86_64

web服务器:nginx1.2.7

PHP版本:PHP5.3.17

数据库版本:MySQL5.5.28

一、安装LNMP1.0一键安装包:

按照以上版本安装环境

二、修改配置文件

1.修改php配置文件php.ini,将其中cgi.fix_pathinfo=0,值改为1

重启php-fpm

2.ssh里执行:

cat拍昌樱/usr/local/nginx/conf/pathinfo.conf'EOF'

set$real_script_name$fastcgi_script_name;

if($fastcgi_script_name~"(.+?\.php)(/.*)"){

set$real_script_name$1;

set$path_info$2;

}

fastcgi_paramSCRIPT_FILENAME$document_root$real_script_name;

fastcgi_paramSCRIPT_NAME$real_script_name;

fastcgi_paramPATH_INFO$path_info;

EOF

再将虚拟主机配置文件里的location~.*\.(php|php5)?$替换为:location~.*\.php

再在includefcgi.conf;下面添加一行includepathinfo.conf;

重启nginx

完整的虚拟主机配置文件如下:

server

{

listen80;

server_name;

indexindex.htmlindex.htmindex.php;

root/home/wwwroot/lnmp;

location~.*\.php

{

try_files$uri=404;

fastcgi_passunix:/tmp/php-cgi.sock;

fastcgi_indexindex.php;

includefcgi.conf;

includepathinfo.conf;

}

location/status{

stub_statuson;

access_logoff;

}

location~.*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires30d;

}

location~.*\.(js|css)?$

{

expires12h;

}

access_log/袭丛home/wwwlogs/lnmp.loglnmp;

}

将ThinkPHP的URL模式设置成PATHINFO。

ThinkPHP就可以在nginx中运行了。

PHP 将 ThinkPHP 项目部署阿里云服务器(图文解说)

在准备将ThinkPHP项目部署至阿里云服务器前,请确保您已安装宝塔,并参考相关教程完成此步骤。

步骤2:选取任意FTP工具,推荐使用XFTP6,用于传输文件。

步骤3:启动FTP工具。

步骤4:链接至您的阿里云服务器。

步骤5:将您的项目文件拖放至新建站点内。

步骤6:将本地项目文件复制至服务器,可能需要等待一段时间。复制完成后,在宝塔文件管理器中检查文件是否已成功上传。

步骤7:进入项目文件夹,以ThinkPHP5.0框架为例,启动文件位于public目录下。需要进行如下设置:

步骤8:关闭服务器的防跨站攻击功能,否则可能会出现错误。

步骤9:设置运行目录为public,保存配置。

步骤10:测试部署是否成功。通过访问服务器地址加上项目名,检查是否可以正常访问。

Thinkphp5项目在nginx服务器部署

1,切换到nginx的配置目录,找到nginx.conf文件

    cd /usr/local/nginx/conf

   vim nginx.conf

2,如果是单项目部署的话,只需要在nginx.conf文件里面加上以下

server{

        listen 80;

        #域名,本地测试可以使用127.0.0.1或localhost

        server_name www.zhangc.cn;

        # php项目根目录

        root/home/data-www/blog;

        location/{

                #定义首页索引文件的名称

                index index.php index.html index.htm;

               #影藏入口文件

               if(-f$request_filename/index.html){

                            rewrite(.*)$1/index.html break;

                }

                if(-f$request_filename/index.php){

                            rewrite(.*)$1/index.php;

                }

                if(!-f$request_filename){

                            rewrite(.*)/index.php;

                }

                try_files$uri$uri//index.php?$query_string;

        }

        # PHP脚本请求全部转发到 FastCGI处理.使用FastCGI协议默认配置.

        # Fastcgi服务器和程序(PHP)沟通的协议

        .location~.*\.php${

                #设置监听端口

                fastcgi_pass 127.0.0.1:9000;

                #设置nginx的默认首页文件

                fastcgi_index index.php;

                #设置脚本文件请求的路径

                fastcgi_param SCRIPT_FILENAME$document_root$fastcgi_script_name;

                #引入fastcgi的配置文件

                include fastcgi_params;

               fastcgi_split_path_info ^(.+?\.php)(/.*)$;

                set$path_info$fastcgi_path_info;

                fastcgi_param PATH_INFO$path_info;

                try_files$fastcgi_script_name=404;

        }

}

3,如果多项目部署,就需要配置vhost

第一步:编辑nginx.conf文件,在最后加上   include  vhost/*.conf;

第二步:进入vhost文件夹,创建  域名.conf  文件,如创建一个:quanma.meyat.com.conf

第三步:编辑quanma.meyat.com.conf文件,内容如下:

        server

        {

                listen 80;

                server_name quanma.meyat.com;

         index index.html index.htm index.php default.html default.htm default.php;

                root/data/wwwroot/default/quanma/public/;

                #error_page 404/404.html;

                location/{

                        index index.html index.php;

                        if(-f$request_filename/index.html){

                                rewrite(.*)$1/index.html break;

                        }

                        if(-f$request_filename/index.php){

                                rewrite(.*)$1/index.php;

                        }

                        if(!-f$request_filename){

                                rewrite(.*)/index.php;

                        }

                        try_files$uri$uri//index.php?$query_string;

                }

                location~ [^/]\.php(/|$)

                {

                        # comment try_files$uri=404; to enable pathinfo

                        #try_files$uri=404;

                        fastcgi_pass 127.0.0.1:9000;

                        fastcgi_index index.php;

                        include fastcgi_params;

                        fastcgi_param SCRIPT_FILENAME$document_root$fastcgi_script_name;

                        fastcgi_split_path_info ^(.+?\.php)(/.*)$;

                        set$path_info$fastcgi_path_info;

                        fastcgi_param PATH_INFO$path_info;

                        try_files$fastcgi_script_name=404;

                        #include fastcgi.conf;

                        #include pathinfo.conf;

            }

            location~.*\.(gif|jpg|jpeg|png|bmp|swf)$

            {

                    expires 30d;

            }

            location~.*\.(js|css)?$

            {

                    expires 12h;

            }

            # Disallow access to.ht,.svn,.bzr,.git,.hg,.cvs directories

            location~/\.(ht|svn|bzr|git|hg|cvs){

                    deny all;

            }

            #access_log/date/nginx/bmp.com.conf/access.log main;

}

阅读剩余
THE END