Symlinked MAMP Folder Causing 403 Forbidden - php

I have a folder in my root MAMP directory, "site". I have that symlinked to a folder in ~/Documents/Dropbox/site, so whatever happens in "site" gets transferred to Dropbox.
However, when I do this, I get a 403 forbidden error when trying to view localhost/site- is this a problem because I'm using PHP and I should fix php.ini, or is this an httpd.conf problem?
In httpd.conf, I have AllowOverride set to None.
Thanks for any answers in advance.

There's also the FollowSymlinks option in Apache, which is generally disabled by default. You can enable it by doing
Options +FollowSymlinks

This is a bit hacky, but I had this problem before and while the solution didn't necessarily make a whole lot of sense, it worked for me:
sudo su <username> to assume the user (eg, if your webserver is running as nobody, use nobody
If #1 is a user whose shell is something similar to /sbin/nologin, temporarily use usermod to change their shell to something you can use, like /bin/bash, before sudoing as them
Symlink as the user instead of root or whatever user this was done as previously
Reset any changes made in #2
Since symlinks are by default 0777, any normal process has read access provided that the destination directory is also of sufficient permissions (0644 would be fine) - for some reason Apache gave me problems with that to. Once I created the link as the user in question, it worked like a charm. HTH!
Edit: also, this almost goes without saying, but I'm assuming you verified the link yourself via a terminal to make sure that the link is correct, right?

Related

Laravel can't go to projects url when move it on live server

Maybe some one know the solution for my problem.
In localhost all works fine.
I bought vps server, install Ubuntu, and LAMP stack in it.
And now copy all files from localhost to live server, threw ftp.
I write ip/public in web browser and I see my projects mine path running well, but if I wanna go to url like ip/public/login it throws 404 error. (Now working only public address)
.htaccess in public folder is good.
Now I find If I write ip/public/index.php/login it works well, but I need that it work like in localhost
Try making a symbolic link to your public folder and using that as the URL of your project. For example, I have a project called inspections in my /var/www/html folder. If I try to access http://url/inspections I get an error:
403 Forbidden: You don't have permission to access /inspections/ on this server.
However, after calling this command:
ln -s /var/www/html/inspections/public /var/www/html/insp
And navigating to http://url/insp the page displays properly and everything works fine.
Another thing to keep in mind is that app/storage need to have write access (at least) in order for Laravel to work properly. I usually just do:
sudo chmod 777 -R app/storage
To activate all privileges and go from there. Hope that helps!
Also did you check if mod_rewrite is enabled on this server?
Maybe Overwrite is not defined for this folder?
Try:
<?php in_array('mod_rewrite', apache_get_modules()); ?>
Or this:
<?php die("Enabled: ". strpos(shell_exec('/usr/local/apache/bin/apachectl -l'), 'mod_rewrite') !== false); ?>
And check if Allowoverride is enabled in your virtual host file.
The location of the file depends on the operating system and structure.
It should look a little like this:
Options Indexes FollowSymLinks
AllowOverride All
Require all granted

Getting Cakephp to work on a Debian server, but I'm having a missing controller error at the root

I've been trying to get a cakePHP app to run on a Debian Server. It works find on localhost, using WAMP. At first I had issues with the rewrite not working. So I attempted to fix that by changing the owner of some of the folders to www-data, from root, as I read in other places on the internet that that would help. I changed the root of the cakephp app to www-data, and everything under that to www-data (recursively). But this still did not fix it.
So I went to instructions for if you can't get url rewriting working, by doing the following...
So I found some other instructions that said to get rid of the ./htaccess, /app/.htaccess and /app/webroot/.htaccess files, which I did.
And I uncommented the following lines in my cakephp folder:
Configure::write('App.baseUrl', env('SCRIPT_NAME'));
Configure::write('App.fullBaseUrl', env('SCRIPT_NAME'));
Configure::write('App.imageBaseUrl', 'img/');
Configure::write('App.cssBaseUrl', 'css/');
Configure::write('App.jsBaseUrl', 'js/');
Now I'm getting this error:
Missing Controller
Error: CakeController could not be found.
Error: Create the class CakeController below in file: app/Controller/CakeController.php
<?php
class CakeController extends AppController {
}
Notice: If you want to customize this error message, create app/View/Errors/missing_controller.ctp
Stack Trace
APP/webroot/index.php line 108 → Dispatcher->dispatch(CakeRequest, CakeResponse)
ROOT/index.php line 41 → require(string)
I think I have to change the App.baseUrl or the App.fullBaseUrl, to something else, but I am not sure to what.
The root of the application is in / <root>/home/webdev/webroot/Cake, and the public domain is located in / <root>/home/webdev/webroot. I think that info may be relevant to solving the problem.
Any help would be much appreciated. Thankyou
You seem to be lacking basic knowledge of setting up the server which leads me to think that you might have mixed up lots of different "workarounds" in your way of trying to make it work, such that it might be too difficult to fix it now through this.
If you have root access to the debian server I assume you're talking about a VPS you own. Then you most probably can reset it to a fresh install and start over.
So first things first:
You're developing on windows and will be serving your app on unix (linux). Beware windows is case insensitive and unix is not, if you don't follow conventions you'll definitely end up with this issue at some point (i.e. webroot/Cake or webroot/cake are the same thing to windows but different on unix).
By default you can't have Apache serve files from from user home folders (/home/user/...) but from /var/www. If you want it the first way you need to set it up properly, which would mean to know how to create an apache site config file and/or messing with apache's main config file. I would leave that for later if I were you.
The folder/files in any folder that Apache must serve need to be accessible/readable by www-data user or group. Exception is the application's tmp folder that need to also be writable by the same user or group. If you put them on /var/www/app you can chown www-data:www-data /var/www/app -Rwhich will save you lots of time in your way to make things work at first.
By default Apache doesn't come with rewrite enabled. You need to a2enable rewrite && service apache2 restart. You will also need to check the directive AllowOverride" in /etc/apache2/sites-available/000-default.conf under directory /var/www/ to make sure it is set to AllowOverride All. If not amend and restart apache.
If you apply the above you should be able to properly access your app under http://server_name/app and follow on from there.

User apache can't access files it owns

Ok, I am having issues with a script I am trying to run. I am trying to move file A from /mount/images/sync to /mount/images/logos. Both of these folders are owned by apache:root. However, when I try to move them, it won't create the subdirectories of /mount/images/logos.
When I check to see who I'm logged in as when running the script, it IS apache.
Not sure where to look to figure out what is going on. Any help would be great, and please, ask me any questions so I can give you the information you need. Not sure where to start.
EDIT EDIT EDIT
I should mention that mount/images/logos is a symbolic link pointing back to another folder, and the source folder is a mount point.
Mount Information:
mount "//192.168.1.10/design1" /home/opmasan/design1 -o ip=192.168.1.10,username=***,password=***,uid=48
You have to add...
Options +FollowSymlinks
... to the section for /mount/images in your Apache configuration.
Check the Options Directive documentation for more info.
Try to switch selinux to permissive mode.

problem installing CakePHP on Linux

I have downloaded the CakePHP from it's site then I copied the files in srv/www/htdocs
renamed the folder to first_app
Here is the output(error and warnings that shows me):
Release Notes for CakePHP 2.0.0-dev.
Fatal error: Class 'Debugger' not found in /srv/www/htdocs/first_app/cake/libs/view/pages/home.ctp on line 26
also the tutorial tells me that I must have this:
Apache server with mod_rewrite
I didn't know how to find it and install it?
is that causing this problem?
I want to know how to add "another" root without having problem
I used this and no result:
<Directory /srv/www/htdocs/first_app/app/webroot>
Options None
AllowOverride All
Order deny,allow
Deny from all
</Directory>
also I changed the /etc/apache2/server-default.conf
I changed allow override None to Allow override All
in the part of this:
<Directory "/srv/www/htdocs">
chmod -R 0777 /srv/www/htdocs/first_app/app/tmp/
This makes the tmp dir writable for everybody (on your machine) so also for the web server. If you want to limit access, first try this, then browse to your CakePHP install, and then check in the cache dir which files have been created and what's the owner and group of those files.
The tmp dir contains more than just the cache dir, it also contains sessions and logs. Anything outside of /srv/www/htdocs/first_app/app/tmp/ does not need to be writable for the server, anything inside that folder should be writable.
The default CakePHP install comes with .htaccess files. You do need those files. They redirect every request to localhost/first_app (or any other dir your is installed in) into the webroot, so you don't have to do that yourself. You need to have AllowOverride All in your apache config. See here for instruction on how to enable that.
Please Go through these links
http://www.youtube.com/watch?v=9stiBWz71Ts
http://ubuntu-linux-apache-mysql-php.blogspot.com/2008/12/how-to-install-cakephp-on-linux-ubuntu.html
http://groups.google.com/group/cake-php/browse_thread/thread/3ba763933544ece
It may help you.
same problem on mac. on mac, i just right clicked on the directory it was concerned about and changed the permissions so that everyone could read/write, and clicked apply to enclosed files/folders.
I used to use linux but i'm not sure exactly how to do this, but hopefully this will get you on the right track? i assume that the command you posted changes the permissions of that folder, but maybe you need to change the permissions of the files and folders inside.

How can I fix the Permission error when I call session_start()?

when I uploaded the script to the server I got this error
Warning: Unknown: open(/tmp/sess_58f54ee6a828f04116c2ed97664497b2, O_RDWR) failed: Permission denied (13) in Unknown on line 0
Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0
The error appeared when I call session_start(), although I set the permission of /tmp folder to 777.
Change session path where you can write data or contact server administrator about /tmp problem
http://php.net/manual/en/function.session-save-path.php
you will need to change your session.save_path php.ini directive
You can do that using session_save_path
If you have SSH access, here is how to correct the permission and ownership
sudo chown -R NAME_OF_USER /tmp
Replace NAME_OF_USER by the user under which runs php. You can find it by simply putting these lines in a php file:
$processUser = posix_getpwuid(posix_geteuid());
print $processUser['name'];
exit;
Check that you're not running into diskspace issues. If all the permissions are correct (and 777 ought to do it for you), then you might still get this error (for some versions of PHP and Apache) if there isn't enough space to write to the disk.
I had this problem in the following situation:
I filled some session vars with PHP
While the session was still active, I changed from PHP 5.4 to 5.3 on my host.
Reloading the page gave the error, described above.
Reset the PHP version to 5.4 again.
Used session_unset(); and session_destroy(); to clean the current session.
Changed the PHP version back to 5.3.
Now it works again.
Conclusion: For an irrelevant reason I had to change my PHP version, and while switching with sessions alive, the sessions get corrupted.
I realize that this is an old post, however I just ran into this problem, and found an easy solution.
For me, the issue was happening with one of my websites deployed locally. I hadn't tried accessing the websites using other browsers, but it was happening every time I tried to access this site via Chrome. I decided to go into the Chrome developer tools, under the application tab -- and clicking "Clear Storage". Voila -- everything is working like magic again.
Hope this helps someone else!
Additionally, you may want to use ini_set('session.save_path', '/dir/here'); assuming you have access to this function. The other ways suggested are valid.
I've just had exactly the same problem with one of my PHP scripts and I was like what did I break 'cos it worked perfectly the day before and I'm running it from my own local Puppy Linux machine so it's not even a host or anything.
The only thing I'd been doing before that was trying to get Java to work in the web browser, so some how I'd managed to get Java to work but broke PHP - oops!
Anyway I did remember that whilst trying to get Java to work I had deleted the contents of the /tmp folder to wipe anything out that may be causing a problem (it actually turned out with Java I was using the old plugin oij with the new Firefox)
To solve this problem I opened up Rox File Manager, went to the / folder and right clicked on the tmp folder -> Mount Point 'tmp' and clicked properties.
I noticed the permissions were set as Owner - Read, Write, Exec, but Group and World were only set at Read and Exec and not Write. I put a tick in Write for both Group and World and now PHP works fine again.
I don't know at what point the permissions for tmp must have changed but for PHP to use them it must be set to have Write permissions.
Add following line
ini_set('session.save_path', getcwd() . '/tmp');
before
session_start();
if you are using Apache web server, the quick fix is to go to your command line and type:
open /etc/apache2/
then from the window opened, open the file called httpd.conf and search for User or Group change these 2 lines to:
User _www
Group _www
This is because you want your server to have permission to your systems directories, especially you want to change the User or you can leave your Group to either staff or admin.
I had the same problem of permission, but on /var/lib/php/session/.
To fix it, I deleted the file and restarted php-fpm.
rm -rf /var/lib/php/session/sess_p930fh0ejjkeeiaes3l4395q96
sudo service php5.6-fpm restart
Now all works well.
For me the problem seems to be a WHM bug!
I have a bunch of add on domains and all work fine but with a subdomain it brings this error.
Strange thing but if I use the full URL with the main domain it works fine:
main-domain.com/my.subdomain.com
If I use the subdomain directly it brings "Permission denied (13)":
my.subdomain.com
The thing is all addon domains root is:
/home/xx/
But for my subdomain, don't know why, the root is: (I shouldn't have access to that dir)
/
So it´s really trying to reach: /tmp instead of /home/xx/tmp
Which also exists but don't have the right permissions
To clarify this are examples of the whole path:
/home/my-account/public_html
/home/my-account/tmp
/tmp
The workaround I used was:
session_save_path('/home/my-account/tmp');
session_start();
Using PHP 5.6 I had already used session_save_path() to point to a directory within the domain's structure. It worked fine until I upgraded to PHP 7.0, at which time I received the noted error. At PHP.net I found several comments that indicated assigning a direct path didn't always work, so I used their suggestion.
session_save_path(realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/../session'));
worked perfectly. Remember to change /../session to the relative location of your actual session directory.
If :
session.gc_probability > 0
session files are created by different user(s) (e.g. root and apache).
session files are all stored in the same place (e.g. /var/lib/php/session)
Then you'll see this error when e.g. the Apache PHP process attempts to run garbage collection on the session files.
Fixes :
Reconfigure PHP so gc_probability is 0, and have a cron job removing the old/stale file(s).
Have each different user save their session files in separate place(s) (session_save_path() etc).
I initially had this issue due to nginx owning the /tmp location and php-fpm was running under 'apache' user and group due to the www.conf. I swapped out the user/group in that file and then it worked ok. You may want to check <?php echo exec('whoami'); ?> to verify.
In my case the problem was SELINUX not allowing this.
A helpful command to get suggestions on how to fix this:
sealert -a /var/log/audit/audit.log
If you want to rule out SELINUX, try disabling it for a moment. If that fixes the issue then that is the problem.

Categories