Change document root via .htaccess issue - php

When I echo out the document root I get this: /etc/httpd/htdocs
however I get the error, when I try to run my website:
No such file or directory in
/vhost/vhost14/i/n/d/domainname.co.uk/www/testme.php
on this line of code
require_once($_SERVER['DOCUMENT_ROOT']."/_cmsscripts/_init.php");
if I replace the $_SERVER with /vhost/vhost14/i/n/d/domainname.co.uk/www/ it all works, but I've got loads of pages and don't really want to have to go around and change the whole site. First time I've had this issue and not sure how to get around it.

Probably the document root is not where your current website in vhost is configured to or follow_symlinks is not enabled.
Anyway, in order to find things below the current file, you may use:
require_once(dirname($_SERVER['PHP_SELF'])."/_cmsscripts/_init.php");
Obviously, the document root can not be changed by .htaccess for security reasons

Related

Change Website from Plain HTML to Wordpress

I have a static html website that I need to convert to Wordpress. I was able to successfully load wordpress on my hosting and configured a theme. However, the front end still displays the original html page. I need the whole website to be converted to wordpress, but I can't figure out where to add the htaccess and index.php files as I read from a blog. Someone help out.
Thanks
Sam
1) you're kind of asking for the whole of how the internet operates. I'm not saying that to be confrontational, just know that you'll likely be downvoted for such an impossible question.
2) more to the point, your server is looking for a directory index. In general, most servers look for index.html, index.htm, index.php, and then others, but in that order. If it encounters index.html in your directory then it stops and says that is the file to load.
3) you can get around this by changing the name of your file.
"index.html" -> "index_OLD.html" (or any name not index.html)
4) you can also change the way your server processes the index order using the DirectoryIndex directive in your HTAccess file. Ask your hosting provider about how to do this and if it's supported (although, I don't recommend you do this, it's just an available option).
5) your wordpress install should be in the root directory. That is to say, your .htaccess and index.php files should live in the same directory that your current index.html file lives in. Once the html file has a different name, the server will locate the php file and use it to server up as the directory index.
6) good luck friend!

WAMP: Index.php executes/runs immediately when selecting the directory it is in

I had a little, slightly annoying problem that was an easy fix but I didn't understand why it took place.
I have a several folders in ../wamp/www/- and in one of them I had a file, that I had created, named index.php. When I clicked on the other directories I could browse through the normal list where I saw all the files, but when I opened the folder where the file Index.php was it executed immediately and I never saw what was in the folder. Instead I had to manually change the url to open other files in that directory.
I deleted index.php and half expected it to run some other .php-file in that directory, but didn't.
I'm aware of that there is a index.php-file in the www-directory (the comments in French though), which clearly is part of the WAMP system I downloaded, but having seen tutorials where people use index.php I'd have expected someone to mention this potential problem.
This is not a problem!
This is how web servers work.
To be specific there is a setting in the Apache config that tells Apache the names of files that it should run Automatically if no actual file is specified in the URL
Specifically this line in httpd.conf
DirectoryIndex index.php index.php3 index.html index.htm
It is normal that a web server will run any of these files if it sees them when only the directory is specified on a URL.
And before you consider changing it, dont. Almost everything you will come accross EXPECTS this to be the case.

PIP framework, Not found error

My PIP PHP framework was doing fine, then I messed something up: I don't know what it is. Basically for every controller except my default, I get a 404 not found error. If I change the default to a different page, the new page will work fine, but no others will. I can't seem to find any information in the logs.
I'm wondering if there is a good way to trace the route apache is using to find the new page. Or if there are any logs I can check. My local log.txt within the framework shows nothing. Apache log shows nothing. PHP log shows nothing.
I thought it may have something to do with the base_url, but no matter how I change it, my controllers are still not found.
$config['base_url'] = ''; // Base URL including trailing slash (e.g. http://localhost/)
Is there any way to see the absolute path that apache/ my browser is trying to take when I load localhost/controller? Something that would show me file://Applications/MAMP/htdocs/path/to/controller, even if the page doesn't load? Is there somewhere in the config/sys file that I can show that info?
Not sure why it was downgraded. I thought I gave all the information I had about the problem and just looking for how to troubleshoot a 404 not found when my default_controller loads.
Weird! I downloaded a new copy of PIP, copied all the files from my old copy to my new copy, and then now it works. It must have been some directory thing with Apache.
if you have apache running, set the base url to
$config['base_url'] = 'http://localhost/';
// remember the forward slash at the end.
if that still does not do it, go to your MVC framework folder, and replace the index.php and the system folder and all its content, you can take a back up if you want of this folder before you do so,
The there are two files that will mess with the routing
index.php
pip.php
so if your config base url is set as the example above and the controllers are still not found it is one of these two files that have been modified.
// note, you might also want to check the .htaccess file for mod_rewrite which needs to be enabled.

Trying to Include Files outside of Document Root (Plesk 10)

Okay, I've tried everything, this is by far the best place it seems, I want to make Document Root here httpdocs/[folder]/html and I have php include files that I want to go above the root (require '../[folder]/file.php'] but not be able to access further than /var/www/vhosts/example.com/httpdocs. I know I'm being limited by open_basedir because the value is still httpdocs/[folder]/html in phpinfo() but for the life of me I can't change that local value!
This is what I've tried so far:
I've seen this - How to include file outside document root? - and created a 'vhost.conf' that is stil sitting in the conf directory, reconfigured the file, restarted apache...nothing. It's a good post but it seems a little out of date.
I edited php.ini itself to open_basedir = '/var/www/vhosts/example.com/httpdocs, uploaded it back up to where it was, reconfigured, restarted - nothing
I pulled out 'httpd.conf' edited it by adding the same lines from the other conf file,(vhost.conf), put it back in - nothing, I then tried to do what godaddy says here - http://help.godaddy.com/article/1616 and added the line php_admin_value open_basedir none' to 'httpd.conf - with no luck either.
It is now 0435 and I can barely keep my eyes open - this site is suppose to launch tomorrow at 2000! Thanks in advance to anyone who is willing/able to read and/or help.
Update: Thanks for a quick response, here are the best answers I can give you:
Does it give you an error?
Yes, I get a server error and through my server error log, specifically:
PHP Warning: require() [function.require]: open_basedir restriction in effect. File(/var/www/vhosts/[example.com]/httpdocs/[folder]/[folder where secure php files exist]/[file.php]) is not within the allowed path(s):
So I'm 99.99% sure its because of the open_basedir restriction.
Are you sure that your webserver is set as the owner of vhosts/ ?
I'm pretty sure, I'm kinda new to controlling servers and I don't really know what that means exactly but I have a virtual dedicated server through Godaddy, running Parallels Plesk v10.3.1, I did the above file moving going through Shell SSH.
In Plesk, I can change the 'Document root' to anything below /var/www/vhosts/example.com and Plesk will change the 'open_basedir' to anything I set. For example, If I set the document root to 'httpdocs' in Plesk then 'open_basedir' is changed to the same folder and everything works fine. The problem is I don't want public access to everything in /httpdocs/[folder]
My goal is I want to change 'document root' to /httpdocs/[folder]/html and 'open_basedir to /httpdocs but I can't change that local value in open_basedir for some reason. I want to do this for security purposes so people can only directly access the non important php files, but php itself I want to give more access to folders.
Are you trying to include using relative or absolute paths?
My paths in the php file that I'm trying to include/require to files above 'document root' looks exactly like this format:
require '../[folder where secure php files exist]/file.php';
If I'm understanding you correctly, I'm not using the entire path of the server.
ANSWER: (This was changed to the answer):
Apparently, in Plesk 10, Plesk's program sets whatever the 'document root' path will be, to the 'open_basedir' BUT there is no user friendly way to change 'open_basedir' in Plesk 10!!!
So instead it is a little bit of a hack, you have to first go here:
/usr/local/psa/admin/conf/templates/default/service/php.php
Then change both of these lines in the file, (line 11 and 29):
echo "php_admin_value open_basedir {$OPT['dir']}/:/tmp/\n";
to this:
echo "php_admin_value open_basedir /var/www/vhosts/[your.domain]/httpdocs/:/tmp/\n";
or to wherever you want the restriction to stop.
Then make sure your run these lines is SSH:
/usr/local/psa/admin/sbin/httpdmng --reconfigure-all
/etc/init.d/httpd stop
/etc/init.d/httpd start
But I'm having a new problem now. The 'document root' is pointing to the correct folder:
/var/www/vhosts/[my.domain]/httpdocs/[folder]/html
without any error however when the server gets to a:
require '../[folder]/[file.php]';
It skips through it like its not even there! Not giving me an error msg or anything. It's also skipping all my embedded css files, js files, images, videos...its not going to any of the directories! I have a feeling it's a 'php.ini' setting or something weird that Plesk is doing.
Solved: The last issue was because I never worked with accessing files above the root. PHP is allowed to go above the root but you can't do this:
src="../img/imagefile.jpg"
in HTML.
So after restructuring all my site files my website is now up and running! Thanks to all that helped, hopefully someone won't have to do that again. Also, I saw a post where Plesk is updating this because it is a big issue. Someone who works for Parallels said, http://forum.parallels.com/showthread.php?t=113236 this will be an option in the next version, so until then it's hack time!!

Finding out what the page is loading in with PHP

I'm working on a directory and on some MOD_REWRITES. I have actually deleted the .htaccess file form the site, But there is still something overwriting it.
Is there any PHP Variables that I can use to find out where the over hanging .htaccess file is being loaded from?
There are so many files, that I fear that there may even be more than one.
Cheers guys
Confusing title.
To answer your title question: do print_r($REQUEST) and find a variable you like.
To answer your body question: check each parent directory's .htaccess, until you hit the root.
.htaccess files are processed in the order they're found, so if there's one overriding things for your page, it would be in one or more of the parent directories. There's also the main server httpd.conf files, which are a preferred location for long-standing .htaccess directives, as that's read only once at server startup, and not per-request as .htaccess files are.
You can check the /etc/apache2/... configuration files, but first make sure you deleted and .htaccess is not just hidden (in unix, files starting with . are hidden by default).

Categories