I'm on Ubuntu and I'm using the FuelPHP Upload Class, to handle my uploads. Here is my configuration:
$config = array(
'path' =>"path/to/upload/folder",
'auto_rename' => true,
'randomize' => true,
'ext_whitelist' => array('webm', 'ogg', 'mp4'),
'create_path' => true,
'path_chmod' => 0777,
'file_chmod' => 0777,
);
Which I give directly to 'Upload' class 'process' static method like this:
Upload::process($config);
I've set 'file_chmod' to '0777' but when I check the file permission of the uploaded file I don't get a 0777 instead I get a 0644. How can I fix this?
The problem was related to the web server user (www-data in my case) not having ownership of the upload directory. Hence the FuelPHP Upload::process() method could not automatically change the file permission to 0777. I fixed it using:
sudo chown www-data my/upload/folder
Hope this would help someone else.
just my 2ct. If you chmod a file, then 0666 would be enough in most cases. because 0777 adds 'execute' permission. But on photos, text files files (everything except executables) you don't need 0777.
So in your setup, as I see it - 0666 will be more than enough.
Have a nice day!
Related
I am trying to create a sub-domain using Route53 with aws-php-sdk.
but I am getting this error again and again:
[2017-06-16 12:17:00] local.ERROR: Aws\Exception\CredentialsException: Error retrieving credentials from the instance profile metadata server.
(cURL error 7: Failed to connect to 169.254.169.254 port 80: No route to host (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)) in /var/www/html/test/vendor/aws/aws-sdk-php/src/Credentials/InstanceProfileProvider.php:79
I am using aws-sdk-php version: 3.29
"aws/aws-sdk-php": "^3.29"
Here is my written code
use Aws\Route53\Route53Client;
$client = Route53Client::factory(array(
'region' => 'us-east-1',
'version' => '2013-04-01',
'credentials ' => array('key'=>'AWS_KEY',
'secret'=>'AWS_SECRET_KEY')
));
$result = $client->changeResourceRecordSets(array(
// HostedZoneId is required
'HostedZoneId' => 'ROUTER_53_HOSTED_ZONE_ID',
// ChangeBatch is required
'ChangeBatch' => array(
// Changes is required
'Changes' => array(
array(
// Action is required
'Action' => 'CREATE',
// ResourceRecordSet is required
'ResourceRecordSet' => array(
// Name is required
'Name' => 'test2.xyz.co.in.',
// Type is required
'Type' => 'A',
'TTL' => 600,
"AliasTarget"=> array(
"HostedZoneId"=> "LOAD_BALANCER_ZONE_ID",
"DNSName"=> "LOAD_BALANCER_DOMAIN_NAME",
"EvaluateTargetHealth"=> false
),
),
),
),
),
));
Help will be appreciable. Thanks in advance.
This question is very old but I want to drop an answer in case someone has a similar issue.
The AWS PHP SDK needs credentials to communicate with AWS. the credentials are known as access key ID and secret access key.
As highlighted in AWS documentation
If you do not provide credentials to a client object at the time of its instantiation, the SDK will attempt to find credentials in your environment.
According to your logs it seems that the SDK is still pulling credentials from your environment which are stored in ~/.aws/credentials, and not using the provided keys.
Either make sure you have the access key and the secret key in your environment variable.
$ less ~/.aws/credentials
[default]
aws_access_key_id = key
aws_secret_access_key = secret
Or
Clear the configuration cache to force using the explicit credentials declared in the instantiation of your client. in case they were cached.
php artisan config:cache
Also refer to this documentation on how to properly setup a client.
https://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/credentials.html
If you use
php artisan config:cache
make sure you don't use env() helper for accessing env variables from anywhere except the config files (config/*). Avoid using env() helper in your blade templates. This is because, calling env() helper after the above command is run, will return null.
Instead use a config file for accessing env values. If a separate config file under the config folder is not available for that vendor package / service, The config/services.php is a good place to point to env values.
Thephp artisan config:cache command will speed up your app as the the env variables are cached and so is recommended in a production environment.
Refer Laravel Configuration Caching for more details.
I'm using Rails 4 and Paperclip.
Beacuse I need to upload files on FTP server i'm using this great gem:
https://github.com/xing/paperclip-storage-ftp
Everything works perfect in local, but in FTP I can't rename files using this code:
def rename_myfile
if self.rename.present?
path = self.myfile.path
FileUtils.move(myfile.path, File.join(File.dirname(myfile.path), self.rename))
self.myfile_file_name = self.rename
end
end
I got an error:
No such file or directory # sys_fail2 - (/myfiles/19/original/myfileOriginalName.jpg, /myfiles/19/original/myfileRenamedName.jpg)
How to enter in ftp with FileUtils.move???
Create and Delete are working very well!
https://github.com/xing/paperclip-storage-ftp/issues/28
You have to build the full path to the file not just the file's dirname and name. change your FileUtils.move line to this:
orig_full_path = Rails.root.join "public", myfile.path # assuming they're saved in your public directory
new_full_path = Rails.root.join "public", File.dirname(myfile.path), self.rename
FileUtils.move orig_full_path, new_full_path
The idea here is to get the absolute path to your files. Before you were just giving FileUtils this path: /myfiles/19/original/myfileOriginalName.jpg which means it will look for the file in a folder /myfiles in the root of your file system. But they're actually in your Rails folder. So you should use Rails.root.join to get the true absolute path: /Users/me/my_rails_project/public/myfiles/19/original/myfileOriginalName.jpg.
I am trying to use pdf generator in my rails 2.3app. It is working fine
in my local machine and pdf is generating. In my production server (nginix) it is not working and shows the error:
"wkhtmltopdf RuntimeError (Location of wkhtmltopdf unknown)"
In the config/initializers/wicked_pdf.rb.example file I have mentioned the path to the binary exe file as:
WickedPdf.config = {
:wkhtmltopdf => '/opt/wkhtmltopdf-amd64',
:layout => 'pdf.html'
:header => {:html => {:template=> 'layouts/pdf_header.html'}}
}
And in the opt folder there is wkhtmltopdf-amd64 binary exe file.
:wkhtmltopdf => '/opt/wkhtmltopdf-amd64',
This is your system opt folder, check whether this folder has permission to execute the binary.
Alternatively change the location of wkhtmltopdf into your rails application by extracting it to /path/to/rails_app/bin
and then change your initializer to :wkhtmltopdf => Rails.root.join('bin', 'wkhtmltopdf-amd64').to_s
can we replace the path with installed gem at gemset?
At terminal just check 'which wkhtmltopdf' is installed in our app gemset path.Then replace the path your wkhtmltopdf initializer with that.
I'm running Ubuntu 10.04 with Rails 3.2.2.
I just installed and configured sendmail. When mail is sent through terminal it worked perfectly.
But when i try to call it through Rails, no success.
Although it doesn't really looks like it's failing though. I get no errors, and see this in my console:
#<Mail::Message:40338240, Multipart: false, Headers: <From: alert#email.com>, <To: chris#email.com>, <Subject: Hi chris, a testmail too you!>, <Mime-Version: 1.0>, <Content-Type: text/html>, <importance: High>, <X-Priority: 1>>
I am in development have the following settings in my development.rb:
config.action_mailer.delivery_method = :sendmail
config.action_mailer.sendmail_settings = {
:location => '/usr/sbin/sendmail',
:arguments => '-i -t'
}
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
I have setup an actionmailer, with the corresponding alert_mail.html.erb:
class UserMailer < ActionMailer::Base
default from: "alert#email.com"
def alert_mail(site)
#site = site
#user = site.user
#url = "http://example.com/login"
mail(:to => #user.email_address, :subject => "Hi chris, a testmail too you!", :importance => "High", 'X-Priority' => '1')
end
end
And this is what I call:
UserMailer.alert_mail(site)
Could it be something with permissions?
Things i've tried
- Tried running in production mode
- chmod'd the sendmail executables to 777
- Tried removing the priority settings
- Running it with rails server instead of nginx
I hope someone can help me, thanks in advance!
(email.com is just a replacement, i use a valid domain)
EDIT:
sadiqxs answer does indeed solve the problem when I try to execute the mail function through rails console. But it still doesn't work when it is supposed to, through my browser. Strange thing is, this seems to be happening in nginx only. When I stop nginx, and start rails server, then it works. But when I when nginx is the server, it doesnt send any mail.
I think you need to call
UserMailer.alert_mail(site).deliver
sadiqxs solution is the part of the answer to my question. It fixes the problem that I was calling the function wrong. But it was still not sending email for me. After a while i manage to get it working.
One of the things I found out is that there was actually another mail log which I did oversee:
/var/log/mail.log.1
It showed me the following error:
sendmail[4453]: NOQUEUE: SYSERR(nobody): can not chdir(/var/spool/mqueue-client/): Permission denied
I used ls -ld /var/spool/mqueue-client/ to see that the directory is restricted by the smmsp group:
drwxrws--- 2 smmsp smmsp 4096 2013-01-12 17:51 /var/spool/mqueue-client/
So I added the nobody user (from the error SYSERR(nobody)) to the smmsp group:
usermod -a -G smmsp nobody
I tested again, and it doesn't work yet. After checking the log I got the same error. To be sure I rebooted my server and now the error message changed a little bit:
NOQUEUE: SYSERR(nobody): can not write to queue directory /var/spool/mqueue-client/ (RunAsGid=65534, required=115): Permission denied
After searching and trying useless stuff for a while i decide to change the primary group of nobody to 115 (smmsp) the /etc/psswd file and saw the following settings:
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
to
nobody:x:65534:115:nobody:/nonexistent:/bin/sh
This solved my problem and it's sending mails now. I understand that this is not the best solution, but I don't really know how else I would give nobody access, since it's requiring the specific GID. I hope someone else here does.
in rails 3 sendmail_settings, there is a option :location which represent the location of the sendmail executable (Defaults to /usr/sbin/sendmail). In my ubuntu OS machine, there is no such file under /usr/sbin, how can I get /usr/sbin/sendmail executable then?
If you want to override options for the :sendmail delivery method then you can use sendmail_settings. You can override these setting in your environment file.
config.action_mailer.sendmail_settings = {
:location => '/usr/sbin/sendmail',
:arguments => '-i -t'
}
sudo apt-get install sendmail-bin. You should have done a search using a package manager. It's ubuntu.. Also it looks like gzipped executables can be found all over the web.