doudang2817
doudang2817
2013-06-03 15:09

使用Git部署时PHP应用程序中断,如果通过sftp部署,则工作正常

已采纳

I have a simple PHP app that I developed locally in MAMP. I did use a few Composer packages. It works perfectly on my local machine. When I deploy the website using Beanstalk App (not AWS Beanstalk, I'm referring to Beanstalk the Git hosting and deployment service) it throws an error once the first class name is referenced in the code.

Fatal error: Class 'User' not found in /srv/www/example.com/public_html/utilities/authenticate.php on line 8

This class is specific to an ActiveRecord Model class for accessing the database. In the code it looks like this:

$user_row = User::find_by_email($theuser);

Very simple and works in my local development environment. ActiveRecord is autoloaded by Composer.

I then tried deploying the app via sftp to my Centos VPS and to my surprise the error went away and the app works as expected. My best guess was that Beanstalk was somehow corrupting the app during deployment. So to test that theory, I setup a bare Git repo on the server and used a post-receive hook to checkout the repo into the public Apache folder. This resulted in the same error I experienced with Beanstalk. It seems the problem is associated with git deployment. I checked that the files had the standard 644 permissions and that folders are set to 755. Apache owns the public folder so ownership isn't the problem either. I'm truly at a loss for why this is occurring. Any wisdom on the matter is greatly appreciated.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • duanjing2013 duanjing2013 8年前

    I've managed to fix the issue. It was a misconfiguration of ActiveRecord on my part. My "User" model class resided in a file named "user.php." That is an incorrect naming convention when using ActiveRecord. Since the class name begins with an uppercase letter so too must the file name. By renaming the file to "User.php" ActiveRecord was able to locate the class correctly. The odd part is that the incorrect naming was not a problem when the documents were placed on the server via sftp. I must assume that there are complexities to the CentOS file system that I don't fully understand. I am aware that unlike CentOS, OS X doesn't have a case sensitive file system and that is the reason why this error never occurred in development.

    点赞 评论 复制链接分享
  • doupinyan0186 doupinyan0186 8年前

    Try to check your .gitignore file. Even better if you paste it's content here. Are you sure you don't need to run composer install on the server after deployment?

    点赞 评论 复制链接分享

相关推荐