用Maven部署PHP站点(这不难)。 [英] Deploying PHP site with Maven (It can't be this hard.)

查看:81
本文介绍了用Maven部署PHP站点(这不难)。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,对我来说很清楚,我对这里使用的工具只有部分了解。在我看来,我正在尝试做一些非常简单的事情。我有一个包含基于php的站点的项目,我的设想是,我应该能够以这样的方式设计我的项目,即可以发出一个 mvn something something命令(除其他事项外)进行部署(从字面上看:移动到正确的目录)所需的php脚本到Web目录。是的,我假设我正在托管我的应用的实际计算机上发出此mvn命令。 (是不是很奇怪?)

So it's pretty clear to me that I just have a partial understanding of the tools at work here. In my mind I'm trying to do something pretty simple. I have a project that includes a php-based site, and my assumption is that I should be able to design my project in such a way that I can issue a single "mvn something something" command that (among other things) would deploy (literally: move to correct directory) the required php scripts to a web directory. Yes, I am assuming that I'm issuing this mvn command on the actual machine that will host my app. (Is that weird?)

我假设我对这个问题的思考就像我在使用ant一样(将这些废话从A点移到另一个点B,蚂蚁 ...),正在寻找可以帮助我的人。该文档(以及关于stackoverflow的类似搜索)尚未使我找到解决方案。 (我尝试过!)

I'm assuming that I'm thinking about this too much like if I were using ant ("move this crap from point A to point B please, ant"...) and am looking for someone to help straighten me out. The documentation (and similar searches on stackoverflow) haven't led me to a solution yet. (I tried!)

到目前为止,我了解.php页面应该位于my-app / src / main / php / webapp / whatever.php下...

So far I understand that .php pages should go under my-app/src/main/php/webapp/whatever.php ... that's fine, check that off the list.

my-app 
    |-- pom.xml 
    `-- src 
        |-- main 
        |    `-- php 
        |       |-- lib 
        |       |   `-- org 
        |       |       `-- sample  
        |       |           `-- app.php
        |       `-- webapp
        |           `-- index.php
        |`-- test 
        |   `-- php 
        |       `-- org 
        |           `-- sample 
        |               `-- apptest.php
        `-- site
            |-- site.xml
            `-- apt
                `-- index.apt

php-maven dot org / tags / 2.0.2 / php-web-10min.html

我遇到的一个合理建议是Maven会假设您想在部署php应用程序之前先打包它,大概是phar文件。可以,我目前不使用phar,但是如果需要这项工作,那么我就可以了。 (如果我已经从git存储库中提取了代码,那么我已经准备好了正确的.php文件,它们只需要移至正确的位置-并不是我的php已编译,所以我有些困惑,因为为何我关心此步骤,或者是否真的有必要。)

A fair suggestion I encountered was that Maven will assume that you want to package your php app prior to deploying it, presumably as a phar file. I'm ok with this, I don't currently use phar, but if it's required to make this work, then I'm up for it. (If I have pulled code from a git repo, I already have the right .php files ready to go, they just need to go to the right place-- it's not like my php is compiled, so I'm a bit confused as to why I care about this step, or if it would really be necessary.)

sitepoint dot com / maven-and-php /

在最后一个想法的基础上,显然可以使用Maven将phar文件的内容提取到特定目录。链接中的示例看起来像是一次性命令行指令(它需要多个-D参数,并且似乎不会作为诸如部署之类的普通目标的一部分执行?)
这与我的设想差不多,但显然不是正确或常规答案。 (再次,我可能会以使用蚂蚁的方式来考虑这一点。)

Building on that last idea, apparently it is possible to use Maven to extract the contents of a phar file to a particular directory. The example in the link looks like somewhat of a one-off command line instruction (it requires multiple -D parameters and doesn't appear that it would be executed as part of a more mundane goal like "deploy"?) This is sort of along the lines of what I envision, but apparently not the "right" or "conventional" answer. (Again, I'm probably thinking of this much in the way that one would use ant.)

php-maven dot org / tags / 2.0.2 / tut-tools-phar.html

文档中最有前途的部分提供了有关如何部署 phar包,但在这种情况下,看起来像部署的意思是将项目包上传到某个地方,以便其他人可以找到并使用它 ..这并不是我真正想要的。
下一节部署站点(mvn site-deploy)可能就是我想要的?-我假设我们正在指定一个发送带有以下描述的内置 php站点的位置:

The most promising section from the documentation gives some information on how to "deploy" a phar package, but in this instance it looks like "deploy" is meaning "upload the project package somewhere so that others are able to find and use it".. which isn't really what I'm after. The next section "Deploy the site" (mvn site-deploy) might be what I am after?-- I assume we are specifying a place to send the "built" php site with this description:

php-maven dot org / tags / 2.0.2 / tut-lifecycle-deploy.html

<project>
  ...
  <distributionManagement>
    ...
    <site>
      <id>project-site.mydomain.org</id>
      <name>My releases</name>
      <url>ftp://ftp dot mydomain.org/documentation</url>
    </site>
    ...
  </distributionManagement>
  ...
</project>

但是,这似乎有点奇怪,我们需要使用ftp / sftp来发送文件到大概的远程服务器。毕竟,我假设我们正在托管我的应用的实际服务器上运行 mvn做事。 (我们是否默认假设我们总是在不会托管Web应用程序的机器上进行构建/部署?)
我当然可以通过在主机上设置ftp / sftp访问来解决此问题。命令它访问自身...将文件移到自身...这听起来有点愚蠢。
此外,我假设这是部署 / target / site中的文件-但这有点隐含(类似于Maven中的其他功能!)

However this seems a bit weird that we would need to use ftp/sftp to "send" the files to a presumably remote server. After all, I'm assuming we are running "mvn do-the-thing" on the actual server that is hosting my app. (Are we defaulting to assume that we are always building/deploying on a machine that will not host a web app?) I could of course work around this by setting up ftp/sftp access on the host... in order for it to access itself... to move the files to itself... which all sounds a little silly. Furthermore, I'm assuming this is "deploying" the files from /target/site -- but that's a little implicit (much like other things in Maven!)

伙计,我在这里到底想念什么?没那么难。我是否错过了手册第2页上的内容?我一生都在撒谎吗?一开始,Maven真的会造成混乱吗?非常感谢您的帮助。

Folks, what exactly am I missing here? It can't be this hard. Did I miss something on page 2 of the manual? Is my entire life a lie? Is maven just really confusing at first? Help is much appreciated.

出于我的价值,我尝试将其部署到Windows / IIS / PHP主机,回想起来,我对此感到有些遗憾。

For what it's worth I am attempting to deploy to a Windows/IIS/PHP host, which in retrospect I somewhat regret.

谢谢!

推荐答案

蛋糕块:

<build>
    <extensions>
        <!-- Enabling the use of Wagon file -->
        <extension>
            <groupId>org.apache.maven.wagon</groupId>
            <artifactId>wagon-file</artifactId>
            <version>1.0-beta-6</version>
        </extension>
    </extensions>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <skip>true</skip>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>wagon-maven-plugin</artifactId>
            <version>1.0-beta-3</version>
            <executions>
                <execution>
                    <id>upload-jar-to-folder</id>
                    <phase>deploy</phase>
                    <goals>
                        <goal>upload</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <fromDir>${project.build.directory}/classes/public</fromDir>
                <includes>**/*</includes>
                <url>file:/home/lukasz/www</url>
                <toDir>Main</toDir>
            </configuration>
        </plugin>
    </plugins>

</build>

这会将我的项目(包括php文件)部署到httpd服务器。

This will deploy my project (including php file) to httpd server.

mvn deploy

当然,我通过系统使用wagon-file插件来完成此任务。但是其他选项也可用(例如,scp,ftp,http)。

Ofcourse, I used wagon-file plugin to do this via system. But other options are available (ie. scp, ftp, http).

这篇关于用Maven部署PHP站点(这不难)。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆