php项目怎么部署到服务器(php如何部署)

慈云数据 2023-04-02 网络资讯 420 15

本篇文章给大家谈谈php项目怎么部署到服务器,以及php如何部署对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

使用php开发的项目必须部署在才能正常运行

使用PHP开发的项目必须部署在Web服务器上才能正常运行。PHP是一种服务器端脚本语言,用于开发动态网站和Web应用程序。PHP脚本必须在Web服务器上运行,才能被解释和执行。因此,使用PHP开发的项目必须部署在Web服务器上才能正常运行。在部署PHP项目时,需要将PHP脚本文件和相关的资源文件上传到Web服务器上,并配置好Web服务器的环境和参数,以确保PHP脚本能够被正确解释和执行。常用的Web服务器包括Apache、Nginx等,可以根据具体需求选择合适的Web服务器进行部署。需要注意的是,部署PHP项目时需要考虑安全性和性能等因素,以确保项目的稳定性和可靠性。

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

vue在服务端部署时,我们都知道通过npm run build 指令打包好的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: ''})

转自:

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 ;

        # 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;

}

服务器上怎么安装php程序

你好,如果你的服务器是Windows系统,那么你需要远程到你的服务器,进行启动IIS(asp环境),如果你需要php环境,你可以从xp.cn(小皮)或者bt.cn(宝塔)安装面板

如果你的服务器是Linux,建议使用宝塔

打开终端,不同Linux系统的输入指令不同:

Centos安装脚本

终端输入:yum install -y wget wget -O install.sh sh install.sh

Ubuntu/Deepin安装脚本

终端输入:wget -O install.sh sudo bash install.sh

Debian安装脚本

终端输入:wget -O install.sh bash install.sh

Fedora安装脚本

终端输入wget -O install.sh bash install.sh

输入后进行安装就可以了

关于php项目怎么部署到服务器和php如何部署的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

免责声明
1、本网站属于非赢利性网站,转载的文章遵循原作者的版权声明。
2、本网站转载文章仅为传播更多信息之目的,凡在本网站出现的信息,均仅供参考。本网站将尽力确保所
提供信息的准确性及可靠性,但不保证信息的正确性和完整性,且不对因信息的不正确或遗漏导致的任何
损失或损害承担责任。
3、任何透过本网站网页而链接及得到的资讯、产品及服务,本网站概不负责,亦不负任何法律责任。
4、本网站所刊发、转载的文章,其版权均归原作者所有,如其他媒体、网站或个人从本网下载使用,请在
转载有关文章时务必尊重该文章的著作权,保留本网注明的“稿件来源”,并自负版权等法律责任。

评论列表

p项目怎么部署到服务器和php如何部署的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
2023-04-02 13:16:37 回复
_param PATH_INFO $path_info;                         try_files $fastcgi_script_name
2023-04-02 13:17:25 回复
ndex.html index.htm index.php default.html default.htm default.php;                 root /data/wwwroot/defaul
2023-04-02 21:43:10 回复
  fastcgi_param SCRIPT_FILENAME$document_root$fastcgi_script_name;               
2023-04-02 14:17:44 回复
_SERVER['HTTP_ORIGIN']) : '';           header('Access-Control-Allow-Credentials: true');           header('Access-Contr
2023-04-02 12:25:22 回复
UEST_FILENAME} !-d     RewriteRule . /index.html [L]  在/home/www/test文件夹下创建项目根目录php文件夹,将thinkphp文件放在php下。TP5的入口文件在public文件下,在这将public
2023-04-02 19:20:35 回复
              try_files $uri $uri/ /index.php?$query_string;         }         # PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI协议默认配置.         # Fastcgi服务器和
2023-04-02 12:51:05 回复
class Index extends Controller   {       public function index() {   $this-redirect('/index.html');       }   }   前端调用登录接口: this.axios.
2023-04-02 20:38:27 回复
ept, authKey, sessionId");   $param =  Request::instance()-param();   $this-param = $param;       }   }   前端
2023-04-02 20:06:06 回复
r_name quanma.meyat.com;                 index index.html index.htm index.php default.html default
2023-04-02 14:25:02 回复
dex.php index.html index.htm;                 # 影藏入口文件                 if (-f $request_filename/
2023-04-02 12:55:22 回复
 Index extends Controller   {       public function index() {   $this-redirect('/index.html');       }   }   前端调用登录接口: thi
2023-04-02 15:37:01 回复
cument_root$fastcgi_script_name;                 # 引入fastcgi的配置文件                 include fastcgi_params;                 fastcgi_split_path_i
2023-04-02 14:10:41 回复
name/index.html){                                 rewrite (.*) $1/index.html break;                         }                        
2023-04-02 23:05:01 回复
location ~ .*\.(js|css)?$             {                     expires 12h;             }             
2023-04-02 23:25:13 回复

发表评论:

微信扫一扫加客服

微信扫一扫加客服

微信扫一扫加客服

微信扫一扫加客服