I'm transferring a website to a different server. I need to change all the file paths. In my config folder I found this line of code. Where might I find the definition of
$_SERVER['DOCUMENT_ROOT']
in a standard PHP/MySQL website?
This is defined at the webserver's configuration.
For Apache it is the DocumentRoot directive in the configuration file; for nginx it is the root directive.
Once you have updated the web server configuration correctly, the variable will point to the location specified there. You do not want to manipulate this variable "manually" in your code as it will lead to problems later on.
It should be
$_SERVER['DOCUMENT_ROOT'];
Not
$SERVER['DOCUMENT_ROOT']
And document root will the (folder)path that you have placed at your server,And if you want to change it or view it,You can go through with your configuration of your server.
echo "<pre>";
print_r($_SERVER);
echo "</pre>";.
exit;
add this to top of your page, you will get all server variables... and dont forget to remove this snippet once you are done seeing the values.
Related
I have about 150 websites each on its own Apache virtual host running php7 on ubuntu 16. Each site has a config.php in the root dir with constants in it: define('MYVAR','myval');
I want to make a new constant that I will have to update every 2 months or so. I don't want to open each config and edit them. How can I have each site/virtual host be aware of this constant I want to set. I want to be available everywhere just like $_SERVER['REMOTE_ADDRESS']; is.
I do not want to create a file them symlink it to each site, thats messy. I would like to edit the apache config or edit a php config someplace to have a define() in it.
Is this possibe? or am I stuck sym linking a file or editing all my configs?
As pointed out in this link; PHP: possible to set constants in default php.ini file
You can't just invent variables in the PHP file, you'll need to auto-prepend a config file that has all the variables defined.
Ignore Below
You could store some global variables in your php.ini file.
The single php.ini file should be used by all your Apache virtual-hosts.
If you update your php.ini file and put a variable in like
my_custom_var = ABC123
Then you can access the variable with ini_get
echo ini_get('my_custom_var');
See more details on ini_get at http://php.net/manual/en/function.ini-get.php
I think you should try using OS environment variables.
Try setting the variables and then exporting them in your .profile file.
Ideally, this is where you should store sensitive credentials too. This way, even if your code is leaked, no one can get access to your existing server (never store Database or other credentials in your code)
You can either store your system variables in .profile or .bashrc file (I would recommend .profile). You can see how to set system variables here: https://unix.stackexchange.com/a/117470/209405
You can get the variables in PHP with the help of getenv($var) or with $_ENV[$var]. For more info, you can check here: http://php.net/manual/en/function.getenv.php and http://php.net/manual/en/reserved.variables.environment.php
The best non-intrusive way for me was to make sure mod_env was enabled then I added in the conf-enabled dir a conf file with the following in it
SetEnv MYLITTLEVAR thestringIwant
Then in php I can get it by:
print $_SERVER['MYLITTLEVAR'];
Tested and it works for me.
If want to make some variables globally available in PHP you need to add those variable in the apache config file.
if you're using ubuntu open /etc/apache2/apache2.conf file, And if you're using windows open httpd.conf. And add the following line.
SetEnv VARIABLE_NAME 'whatever value you want'
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
Background: I downloaded Joomla 3.2 directly from Joomla's website, extracted the contents and uploaded everything to a subfolder within my /public_html via FTP; with the host being domain.com. I access the frontend via www.{my_address}.com/Joomla3. I have .htaccess and php.ini in /public_html and .htaccess in my Joomla3 folder. It should also be noted that my php version is 5.3.13 and that I am using Filezilla for FTP transfers.
Problem: I am having trouble getting past the Pre-Installation Check. Everything under Recommended Settings is green while all the required settings are green...except the red "No" next to "Register Globals Off".
Attempts: From my desperate search through Google, here's what I've found/tried.
*Register_globals is turned off in php.ini by default in PHP5* - Yet the pre-installation check shows otherwise. Perhaps the host keeps it on?
Put register_globals = Off in php.ini - I placed it in /public_html/php.ini; No change. Also, I had to create php.ini myself. Perhaps it could be in the wrong location?
Place php_flag register_globals off in .htaccess - I placed it in /public_html/.htaccess; I receive a 500 Internal Server Error on both www.{my_address}.com and www.{my_address}.com/Joomla3. When I place the line in /public_html/Joomla3/.htaccess, www.{my_address}.com/Joomla3, I receive Error 500 on just www.{my_address}.com/Joomla3.
Go to Software/Services in HostGator Cpanel and click "php.ini QuickConfig" - Though I know it's for a different host, I tried looking for a similar option/tool on Domain.com's control panel (whatever it may be called), but couldn't find one. Perhaps I overlooked it?
*Put php.ini in /public_html/yourserver/administrator/* - Copied the aforementioned php.ini file into /public_html/Joomla3/administrator; No change. I copied the same file into /public_html/Joomla3/installation; I receive Error 500 yet again.
If you are running PHP5, name your initialization file php5.ini - I changed php.ini to php5.ini; No change. I moved php5.ini to /administrator and /installation.
Those are all the attempts I can think of so far. Please let me know how to solve this. I appreciate all the help I can get. I've been working with Joomla 2.5 and I'd like to experience 3.2.
Note: I don't know what's with the formatting mishap in the 1st and 5th points. Please disregard the asterisks that were meant to italicize.
Create php.ini and .htaccess files outside of your document root.
I will assume your document root is /home/yourusername/public_html then do the following:
Create php.ini file outside of the document root: /home/yourusername/php.ini.
Inside your php.ini file turn register_globals OFF:
register_globals = Off
Create .htaccess file outside of the document root: /home/yourusername/.htaccess.
Inside your .htaccess file put:
SetEnv PHPRC /home/yourusername/php.ini
Create a phpinfo.php file inside your document root: /home/yourusername/public_html/phpinfo.php
Inside your phpinfo.php file put this inside php tags: phpinfo();
Visit phpinfo.php and check the Loaded Configuration File - it should point to the new file.
In the end, I submitted a ticket to Domain.com's support staff with the request to turn Register_Globals off. They responded later that night after doing just that. I wish I could provide more details, but they hadn't provided any (even though I asked).
So, problem solved. Thanks anyways to those who provided ideas to try.
(Please be patient, this does have something to do with include.) I am waiting for a domain to transfer over and am trying to set it up on the new hosting service ahead of time. I realized that on the old site all the path names were absolute, so all my links on the new host point to pages on the old host. I decided to make them all relative (for future possible moves also). I first did it like this:
index.php
include ('./header.php');
header.php
include "./panel.php";
panel.php
Contents of panel.
This works, and my page displays:
Contents of panel.
Then I decided to set a variable for the domain because I want to include this header file from files in subdirectories and I can use the domain variable to make an absolute path. Right now I have a temporary domain name, which I can change later to the real domain name when the transfer comes through. So I changed header.php to:
$domain="http://tempdomain.com"; //I can change this after the transfer
$panel=$domain."/panel.php";
echo $panel;
if ((include $panel) !== 1)
{
echo "<br>include failed";
}
What I get is:
http://tempdomain.com/panel.php
include failed
I've looked at various sites for include syntax, but I can't find any error in my code. All these files are in the / directory. Any ideas?
When you include, you have to give the directory structured, not the url.
Your hosting server path may be home/public/www/htdocs/your_directory_name/panel.php something like this. Then it will work.
remort include is also posiible
if
1. server's php.ini should allow it.
2. the file which will be included should not be preprossed before include. That means it must return unprocessed code :)
First, the allow_url_fopen flag must be set in php.ini. Otherwise remote include() cannot be done. Run var_dump(ini_get("allow_url_fopen")); to see if it is the case.
Second, "Windows versions of PHP prior to PHP 4.3.0 do not support access of remote files via this function, even if allow_url_fopen is enabled." - see PHP docs
Third, your remote PHP script must produce valid PHP code as output. If you include() via http, then not the script itself, but its output will be included.
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).