问题描述
在windows7下开发时,没有问题,图片可以上传,在 centos passenger下部署后,目录已经设为666,报错,清各位朋友帮忙诊断。错误信息如下:Errno::EACCES (Permission denied - /home/ftp/site001/wwwroot/public/images/item_logos): /rubyee/lib/ruby/1.8/fileutils.rb:243:in `mkdir' /rubyee/lib/ruby/1.8/fileutils.rb:243:in `fu_mkdir' /rubyee/lib/ruby/1.8/fileutils.rb:217:in `mkdir_p' /rubyee/lib/ruby/1.8/fileutils.rb:215:in `reverse_each' /rubyee/lib/ruby/1.8/fileutils.rb:215:in `mkdir_p' /rubyee/lib/ruby/1.8/fileutils.rb:201:in `each' /rubyee/lib/ruby/1.8/fileutils.rb:201:in `mkdir_p' app/models/item.rb:36:in `create_everything'代码如下: after_create :create_everything .... def create_everything # Logos Folder logos_path = "#{RAILS_ROOT}/public/images/item_logos/#{self.id}" FileUtils.mkdir_p(logos_path) if !File.exist?(logos_path) # # Images Folder images_path = "#{RAILS_ROOT}/public/images/item_images/#{self.id}" FileUtils.mkdir_p(images_path) if !File.exist?(images_path) # Files Folder files_path = "#{RAILS_ROOT}/public/files/item_files/#{self.id}" FileUtils.mkdir_p(files_path) if !File.exist?(files_path) end 问题补充:使用了 qichunren 提供的方法,但仍然错误,信息如下:Errno::EACCES (Permission denied - /home/ftp/androidzzz_androidzzz/wwwroot/public/images/item_logos): /rubyee/lib/ruby/1.8/fileutils.rb:243:in `mkdir' /rubyee/lib/ruby/1.8/fileutils.rb:243:in `fu_mkdir' /rubyee/lib/ruby/1.8/fileutils.rb:217:in `mkdir_p' /rubyee/lib/ruby/1.8/fileutils.rb:215:in `reverse_each' /rubyee/lib/ruby/1.8/fileutils.rb:215:in `mkdir_p' /rubyee/lib/ruby/1.8/fileutils.rb:201:in `each' /rubyee/lib/ruby/1.8/fileutils.rb:201:in `mkdir_p' app/models/item.rb:36:in `create_everything' app/controllers/items_controller.rb:128:in `create' passenger (2.2.14) lib/phusion_passenger/rack/request_handler.rb:92:in `process_request' passenger (2.2.14) lib/phusion_passenger/abstract_request_handler.rb:207:in `main_loop' passenger (2.2.14) lib/phusion_passenger/railz/application_spawner.rb:441:in `start_request_handler' passenger (2.2.14) lib/phusion_passenger/railz/application_spawner.rb:381:in `handle_spawn_application' passenger (2.2.14) lib/phusion_passenger/utils.rb:252:in `safe_fork' passenger (2.2.14) lib/phusion_passenger/railz/application_spawner.rb:377:in `handle_spawn_application' passenger (2.2.14) lib/phusion_passenger/abstract_server.rb:352:in `__send__' passenger (2.2.14) lib/phusion_passenger/abstract_server.rb:352:in `main_loop' passenger (2.2.14) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously' passenger (2.2.14) lib/phusion_passenger/abstract_server.rb:163:in `start' passenger (2.2.14) lib/phusion_passenger/railz/application_spawner.rb:222:in `start' passenger (2.2.14) lib/phusion_passenger/spawn_manager.rb:262:in `spawn_rails_application' passenger (2.2.14) lib/phusion_passenger/abstract_server_collection.rb:126:in `lookup_or_add' passenger (2.2.14) lib/phusion_passenger/spawn_manager.rb:256:in `spawn_rails_application' passenger (2.2.14) lib/phusion_passenger/abstract_server_collection.rb:80:in `synchronize' passenger (2.2.14) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize' passenger (2.2.14) lib/phusion_passenger/spawn_manager.rb:255:in `spawn_rails_application' passenger (2.2.14) lib/phusion_passenger/spawn_manager.rb:154:in `spawn_application' passenger (2.2.14) lib/phusion_passenger/spawn_manager.rb:287:in `handle_spawn_application' passenger (2.2.14) lib/phusion_passenger/abstract_server.rb:352:in `__send__' passenger (2.2.14) lib/phusion_passenger/abstract_server.rb:352:in `main_loop' passenger (2.2.14) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
解决方案
你是将哪个目录设置成666的,你有可能是其中的子目录没有设置成那样。设置的时候用 -R选项吧chmod -R 666 public/images
解决方案二:
777是表示任何用户 都可以读删。那你使用770吧
解决方案三:
再不行看看selinux是不是打开了
解决方案四:
很明显还是权限的问题引起的,你执行一下chmod -R 777 /home/ftp/androidzzz_androidzzz/wwwroot/public/images/item_logos
解决方案五:
sudo chown -R nobody 网站目录/public/images我昨天遇到这个问题用上面弄好了