dspows0637 2013-12-24 05:05
浏览 153

使用Maven部署PHP站点(这不是很难。)

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?)

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!)

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

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/

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

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>

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!)

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.

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

Thanks!

  • 写回答

2条回答 默认 最新

  • duanmo5724 2013-12-24 08:13
    关注

    Look at PHP web project - 5 minutes starter guide.

    You can generate sample php project:

    mvn archetype:generate \
    -DarchetypeGroupId=org.phpmaven \
    -DarchetypeArtifactId=php5-web-archetype \
    -DarchetypeVersion=2.0.2 \
    -DgroupId=org.sample \
    -DartifactId=my-app \
    -Dversion=0.0.1-SNAPSHOT
    

    Goal mvn site:deploy is for generating project home site (documentation)

    Deploys the generated site using wagon supported protocols to the site URL specified in the section of the POM.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动