using the tmp folder on a apache - apache

I just pushed my website from my local development environment to my remote server and I've run into some problems. Specifically with the use of the /tmp folder. As a test I ran this
echo "the start";
$tmp = sys_get_temp_dir();
echo $tmp . "<br/>";
echo "the end."
The result is only:
"the start"
After that the script seems to die. But it gives me no error. (Can I do something in the apache config to show me errors??)
Anyway I first checked php.ini to see where the tmp directory is. No explicit folder is stated, so apache should be using the system default.
I then when to this file in /var/www/ to check the permissions. The permissions here are 777 so I don't think should have any trouble writing to the tmp folder.
And yet my problems persist. Any ideas??

Related

Laravel 403 error when displaying images from storage folder

I am unable to access files saved to the storage folder. I'm able to upload, files, save files. If I run for example the size method it gets the file size of the uploaded image but when it comes to displaying the file, I get a 403 error. I used the laravel artisan command to create the symlink, I've tried manually creating the symlink. I've checked to verify that follow symlinks is in my apache config, I can cd into it from shell the permissions are 777 (I had it 755 but in trying to figure it what is wrong I changed it to 777) ownership of the symlink and files inside are all the same user and group as every other file in the public directory.
I'm super tired so maybe I'm just missing something obvious, but I can't for the life of me figure out what is wrong. The file clearly exists, its visibility set to "public". Is there any reason why I'd be able to write the directory but not display images saved there?
Edit 1:
web
app
bootstrap
config
database
error
node_modules
public
resources
routes
stats
storage
temp
vendor
Is the basic structure, with a symlink inside public pointing at storage/app/public
the filesystems for my storage folder config is:
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
I haven't really edited anything from the basic laravel install at this point. I did read someone else having a similar problem, said their issue is they weren't allow to access direcotires outside of their document root. So they just had all uploads go to their public folder instead of using the storage folder. I do have my document root set to my public folder. Could that be a problem? (I can edit my apache file if needed)
Ok - got some sleep and this morning looked over everything and realized that when logged in as the site owner, everything looks fine, however when logged in as root it shows the link as broken. Basically artisan creates an absolute link, which /storage/app/public is fine as the site owner because its a jailkitted account whose "root" directory is the web folder. However it was actually creating a symlink to the system root, of which the normally account doesn't have access to so it was returning a 403
Basically I just made the as a relative link instead of an absolute one by removing the broken symlink laravel created and while in the public directory entering:
ln -s ../storage/app/public storage
I had the same issue, after a lot of debugging i managed to identify the actual problem that caused 403 error.
Solution is simple, in
Config/Filesystem.php
where you define your public_path and storage path, you must have same/identical public_path name and storage_path end directory name.
Example:
Incorrect:
public_path('brands') => storage_path('storage/app/public/brandimages');
This will generate 403 error, "since public_path('brands')" is not same as "storage_path('../../../brandsimage')".
Correct:
public_path('brands') => storage_path('storage/app/public/brands');
Now the public_path('brands') and "storage_path('../../../brands')" are same, therefore, correct symlinks will generated,thus solving 403 error.
Generate symlinks with following artisan command
php artisan storage:link
if relative links need to be generated, than use following command
php artisan storage:link --relative
My hosting is a clud server, and my site path is /httpdocs
The solution worked for me, was:
from folder /httpdocs/public, execute ln -s ../storage/app/public storage
then everything works fine.

Perl not allowed to write files

I'm using Ubuntu 12.04 and Apache2. My perl script is on /usr/lib/cgi-bin and i'm trying to write a file(open ">") to /var/www/my_custom_dir but i get:
Permission denied
If i try to write to the script's directory or any other the error is the same. The permissions seem right. Everything is 755, root owner. I tried to change "my_custom_dir" owner to www-data(apache user), but does not make any difference.
open ( UPLOADFILE, ">$filepath" ) or die "$!"; binmode UPLOADFILE;
while ( <$file> ) { print UPLOADFILE $_; } close($file); close UPLOADFILE; }
It "die" on the the first line. The error on log is "Permission denied at /usr/lib/cgi-bin/script.cgi"
Even if you are starting your cgi-bin in root it is not working ?
Maybe one of directory on your path does not have the right permission applied. A directory has to be +x in order to be openable.
Try to check all the directory that to cgi will have to go through, or lunch the cgi as apache user with "my_custom_dir" in www-data.
First of all, setting root as owner of cgi-bin is not a good idea.
As you can see, 5=4+0+1, so it gives no write permission to non-owners, only read and execute.
What is the way you changed the owner? Try to do it recursevly (chmod -R)
Also always check if $filepath is correct:
open ( UPLOADFILE, ">$filepath" ) or die "Cannot open $filepath: $!";

nfsnobody User Privileges

I have setup an NFS file share between two CentOS 6, 64 machines. On the server the folder being shared was originally owned by the root user. On the client it turned up as being owned by nfsnobody. When I tried to write to the folder from the client I got a permissions error. So I changed the folder ownership on the server to nfsnobody and chmod'd it to 777. However, still no joy - I continue to get a permissions error. Clearly, there is more to this. I would be much obliged to any Linux gurus out there (I personally wouldn't merit being called anything more than a newbie) who might be able to help fix this issue.
Edit - I should have mentioned that trying to write to the shared folder from the client actually manages to create a file entry. However, the file size is 0 and the permissions error is reported.
The issue here is to do with the entry in /etc/exports. It should read
folder ip(rw,**all_squash**,sync,no_subtree_check)
I had missed the all_squash bit. That apart, make sure that the folder on the server is owned by nfsnobody. On my setup both my client and server nfsnobodies ended up with a user id if 65534. However, it is well worth checking this (/etc/groups) or else... .
Here are a couple of useful references
How to setup an NFS SErver
NFS on CentOS
For the benefit of anyone looking to setup an NFS server I give below what worked for me on my CentOS 6 64bit machines.
SERVER
yum install nfs-utils nfs-utils-lib - install NFS
rpm -q nfs-utils - check the install
/etc/init.d/rpcbind start
chkconfig --levels 235 nfs on
/etc/init.d/nfs start
chkconfig --level 35 rpcbind on
With this done you should create the folder you want to share
mkdir folder
chown 65534:65534 folder
chmod 755 folder
Now define the folder to be shared/exported. Use your favorite text editor (vi or whatever) to
open/create /etc/exports
folder clientIP (rw,all_squash,sync,no_subtree_check)
Client
Install, check, bind and start as above
mount -t nfs serverIP:folder clientFolderLocation
If all goes well you should now be able to write a little script on your client
<?php
$file = $_SERVER['DOCUMENT_ROOT']."/../nfsfolder/test.txt";
file_put_contents($file,'Hello world of NFS!');
?>
browse to it and find that test.txt now exists on the server with the content "Hello world of NFS". In the example I have placed my mounted drive one level before document_root.

codeigniter project migration from iis to apache2

I have migrated my project from Windows IIS to Mint Apache2.
Unfortunately I am getting an error:
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfil the request.
I have changed permissions on the files to 755. Normally if there is a CI error (connecting to db etc) it throws an error.
I have opened my index.php with VI, and I have noticed ^M on the end of each line in EACH FILE. This doesn't show in Aptana though.
I have spent last half a year writing this app and I'm not very excited about this.
Does anybody have any experience with this?
Thank you.
If you have access to the shell on your server and it's running Linux/Unix, try this:
for i in `find . -type f` ; do dos2unix $i $i; done
The for i in `find . -type f` ; part finds all FILES within the current directory.
Then, do dos2unix $i $i; done runs dos2unix which will convert all your ^M's to the Unix standard which is just \r.
If you want to test it out on a single file, make a copy of a file and replace find . with find filename.ext
Try adding this to your php.ini.
display_errors = On
This should show a proper error instead of just throwing a 500. From therein it should be relatively simple to debug.

PSCP copy files from godaddy to my windows machine

I want to take backup of my website which is hosted on godaddy.
I used pscp command from my windows dos and try to download whole public_html folder.
my command is :
pscp -r user#host:public_html/ d:\sites\;
Files are downloading properly and folders also. But the issue is public_html and other subfolders has two folder like "./" and "../". Due to these two folders my copy is getting failed and I am getting
"security violation: remote host attempted to write to " a '.' or '..' path!"error.
Hope any one can help for this.
Note : I have only ssh access and have to download it from ssh commands itself.
Appending a star to the source should fix it, e.g.
pscp -r user#host:public_html/* d:\sites\;
Also you can do same thing by not adding '/' at the end of your source path.
For eg.
pscp -r user#host:public_html d:\sites
Above command will create public_html directory if not exists at your destination (i.e. d:\sites).
Simply we can say using above command we can make a as it is clone of public_html at d:\sites.
One important thing: You need to define the port number over here "-P 22".
pscp -r -P 22 user#host:public_html/* D:\sites
In my case, it works when I use port number 22 with the above script.