PHP - Server Document Root Question
I have been trying to learn how to build a php/mysql website using my local computer for testing. I'm at the point now where I need to move my files over to our server so I can give an update and show how much I have done. On my computer I have been setting up my include lines like this.
include $_SERVER['DOCUMENT_ROOT'] . '/includes/head.inc.php'; the problem is that when I move my files over to the server I want to put them in a .htpassword protected directory called dbsite until the new site is ready to go live at which point I will move the files out of that directory and put them in the root dir. (there is currently I live site which I am replacing with this new one in the root right now, but until I'm ready I can't delete/overwrite the current one) My question is, is there a way to make $_SERVER['DOCUMENT_ROOT'] = the dbsite dir instead of the actual root dir? Just temporarily while the site is in the testing directory on the server. Otherwise I have to change all of my lines on my local computer from include $_SERVER['DOCUMENT_ROOT'] . '/includes/head.inc.php'; to include $_SERVER['DOCUMENT_ROOT'] . '/dbsite/includes/head.inc.php'; which will then cause the files on my local computer to not work correctly. Am I making sense as to my dilemma? Is there an easier/better solution? Thanks. Similar TutorialsHey y'all.
I'll gladly admit that I'm not a server guy - I have the utmost respect for people comfortable enough with *nix to handle Apache setup and configuration in a production environment. I can noodle about in *nix typically without killing anything vitally important, but trust me when I say no-one wants me to be a server administrator. That having been said, I do have a development server behind my home network firewall running Ubuntu that I use to test and develop the sites that I create on my separate Windows box. So I try to keep up with the way a shared server would be set up in a real-world situation, to a degree. For instance, I haven't bothered setting up the mail server or FTP, but I do create virtual host files for each of my projects.
So, I've got a virtual host set up on the directory /var/www/myAwesomeSite.com/ with the .conf file containing the following configuration:
<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName myAwesomeSite.com DocumentRoot /var/www/myAwesomeSite.com/www <Directory /var/www/myAwesomeSite.com/www> AllowOverride All </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>Now, in my php scripts echoing out $_SERVER['DOCUMENT_ROOT'] gives me 'myAwesomeSite/www' as I would expect. And using $_SERVER['DOCUMENT_ROOT'] in any require() statements actually does include the requested file, so that part seems to be working fine. My question is this: when I use a leading slash ('/'), shouldn't that equate to the document root? I use it at work all the time and it works flawlessly, but on the dev server I have set up here, it's a no-go. Is there another config command that I need to issue to make it work, or am I crazy? Basically, am I missing a setting somewhere that will make this: require_once('/path/to/my/include.php');work like this? require_once($_SERVER['DOCUMENT_ROOT'].'/to/my/include.php');*edit* I just realized that I used the wrong slash in the title of this post, but I don't see a way to change the topic title. crap. Edited by maxxd, 23 November 2014 - 11:20 AM. Howdy,
So I am creating a website with SQLite and this time I decided to follow the rule of putting the SQLite DB outside of the document root. However, the admin would need to admin, basically, the DB, so I have two choices:
a) Put PhpLiteAdmin (The SQLite DB manager like PHPmyAdmin is for MySQL) in the document root while giving it a path to the actually DB that is outside of the document root;
b) Set a subdomain to a directory outside of the document root of course and put both PhpLiteAdmin and the SQLite DB there and the admin would access it like this - db.Awesome-Website.com;
Which one of those two options are safer?
Thank you very much!
I need to find a way to resolve a relative path outside the document root, in a cross-platform friendly manner. My users have a settings page where they are able to set the path to a folder where files should be included. This path may not exist at the time of saving the setting. The given path is then retrieved from the database when files are being saved, the path is checked to see if a folder needs to be created, and the file is saved to the path. Two possible paths they may use a * files (This is the webpath: http://site.com/files or absolute path /home/user/public_html/files) * ../files (This is the absolute path: /home/user/files where the webroot is /home/user/public_html/) The first path is easy to deal with. However, I'm having a rough time resolving the second path into a usable system path (i.e. /home/user/files). This needs to be cross platform compatible (windows/'Nix). I've played around with realpath(), but I'm just not finding something that works for me. Any suggestions? This might be better for the Apache forum, but I'll explain anyways. I'm switching up my local dev environment so I can use SVN. I have a directory for all my SVN stuff on my local machine now in /var/svn. When I call $_SERVER['DOCUMENT_ROOT'] its listing the document root as /var/www. For this alias I've setup in apache I want the document root to be /var/svn/myproject. Alot of my includes are failing because of this now. Hey guys. Basically i have a file containing Database connection information stored at the root of my site www.worldwidelighthouses.com/Lighthouses-Database-Connection-Information.php I want to be able to connect to it using pages such as www.worldwidelighthouses.com/Lighthouses/English-Lighthouses/Beachy-Head-Lighthouse.php and www.worldwidelighthouses.com/Lightships/Lightship1.php Obviously 1 is 1 directory down, one is 2 directories down. My server doesnt allow for include 'www.worldwidelighthouses.com/Lighthouses-Database-Connection-Information.php' So whats the best way to always find this file, no matter what directory i am in? Finding out how far away i am from the server root and adding ../ to the include for each folder down was my first idea. Is this best? Thanks, Danny. I have a client and a server solution setup at the moment. We are currently creating an API that will be run on the clients end that will allow their clients to connect to them. On our end, we want to log the number of attempts are API is being used so that we may charge the clients appropriately. My question is this. How is the most efficient way of doing this? Do I call mysql_connect from the client and just shoot the insert log statements across the web. Should I create a php script on our end that looks for post/get input and takes the data and inserts it? What if the client can't connect to our server; should I cache the data and send it off all at once? Should I create a job that every hour shoots up x records API requests happened? Relatively confused at what angle I should be taking when approaching this. I want this to be scalable to a point where we can have thousands of requests an hour, and not horribly slow down apache/mysql running at either end (Specially if the server is talking with several clients). Hi all. I have a video upload page utilizing ffmpeg to convert to .flv format via ajax with progress bar. Currently I am having an issue where the user uploads the video however the same upload script also converts to .flv format (exec("ffmpeg -i etc..")) after the file is uploaded. This is working fine however if the user selects to move away from the page after the video is uploaded it is causing the users browser to lockup (and sometimes crash). How can I make the exec() command to convert the video format strictly run server side and allow the user to move away from the page even though the conversion is still processing? Thanks for any advise on how to handle this issue. Before reading, just know I am NOT a PHP programmer and have no experience with PHP. I am just trying to install a premade php based website.
My questions is: How do I make .php pages connect to my database?
I know the question is very broad and probably doesn't really make sense but I've been having errors trying to install/configure a php website. The php website has a config which I have filled out correctly and seems to work on my PC via localhost using XAMPP fine but it doesn't work on my Windows Server 2012 Apache machine whenever the .php configuration tries to alter or conenct to the MySQL database it displays errors like this:
Fatal error: Call to undefined function mysql_connect() in C:\Apache24\htdocs\includes\classes.php on line 378
That's just an example of one predefined PHP website errors that I've received they are all very similar. What I think is happening is the PHP code is trying to connect to the database but there's some sort of configuration variable on Apache that I have not correctly filled out. I have tried this twice with two different CMS and searched google far and wide to find an answer to my problem. I hope the answer is something simple. If you need anything because you think you know what is happening then I will provide any information needed to fix this problem.
Thank you.
This may be a stupid question so forgive me if it sounds like a dumb question. I have my own server set up and I was wondering if it was at all possible to have a script running that is hosted on my server, while my PC is off or possibly just without having to load it within my web browser. I have a few scripts I wish to run forever without lagging my old PC. Is there a way to do this? Thanks. P.S All the scripts will be using the file_get_contents function to open HTTP streams, and a few explode functions here and there. I have a PHP web system that store in a windows server. In the system, there is a function for user to upload files to another server (Shared server in Unix). When i try to upload a file, it gives warning: Warning: move_uploaded_file(\\unixserver/sharedfolder/upload/test.txt) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\wamp\www\upload\index.php on line 40 For your information, my username has been assigned in xxx's group that has access to read and write on that folder. Besides, i'm able to open,create and delete files on that folder's server manually (samba). The safe mode setting is off. Does anybody has any idea why this thing happen? Hi, I am not a PHP programmer. I took on a new client with a simple PHP site, without any databases. The site is up and running on the web. I would like to get it running on my local machine for further development. I have latest version of WAMP installed, running Apache version 2.2.11 and PHP version 5.3.0 I created a directory in the WAMP "www" project directory and it shows up there like it's supposed to when I browse to "localhost" Problem: The home page of website displays text but no, images, styles, footer, header, nav links, etc. Here is the code for the home page: <? define("NAV","home"); require_once('local/local.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>TITLE</title> <meta name="keywords" content=""> <meta name="Description" content=""> <? include("common/dochead.php"); ?> </head> <body onLoad="<? include('common/preloads.php'); ?>"> <!-- ============================ main ============================= --> <div id="main-frame"><div id="main" class="noCollapse"> <? include("common/sign.php"); ?> <div id="right-frame"> <? include("common/navigation.php"); ?> <div id="content-frame"> <div id="content"> <h1>Welcome</h1> <p>This is the content area. This is the content area. This is the content area. </p> </div><!-- end content --> </div><!-- end content-frame --> </div><!-- end right-frame --> <div class="clearFloats"></div> </div><!-- end main --></div><!-- end main-frame --> <? include("common/footer.php"); ?> </body> </html> Any help would be greatly appreciated. I have spent many hours on this. Regards I'm trying to make a simple website where people register to my website. When the user doesn't fill anything inside the boxes they get a message "Please fill all required fields" on the register.php page On my local host require_once works good. It shows up.
But when i upload the files to my sever the require_once does not show up on the register.php It just refreshes and i dont get the message "Please fill all required fields"
This is the code that works in local host but not in a live server <?php require_once 'messages.php'; ?>
Here is my full code
Register page: <html> <?php require_once 'messages.php'; ?> <br><br> <form action="register-clicked.php" method="POST"> Username:<br> <input type="text" name="usernamebox" placeholder="Enter Username Here"> <br><br> Email:<br> <input type="text" name="emailbox" placeholder="Enter email here"> <br><br> Password:<br> <input type="password" name="passwordbox" placeholder="Enter password here"> <br><br> Confirm Password:<br> <input type="password" name="passwordconfirmbox" placeholder="Re-enter password here"> <br><br> <input type="submit" name="submitbox" value="Press to submit"> <br><br> </form> </html>
Register clicked <?php session_start(); $data = $_POST; if( empty($data['usernamebox']) || empty($data['emailbox']) || empty($data['passwordbox']) || empty($data['passwordconfirmbox'])) { $_SESSION['messages'][] = 'Please fill all required fields'; header('Location: register.php'); exit; } if ($data['passwordbox'] !== $data['passwordconfirmbox']) { $_SESSION['messages'][] = 'Passwords do not match'; header('Location: register.php'); exit; } $dsn = 'mysql:dbname=mydatabase;host=localhost'; $dbUser='myuser'; $dbPassword= 'password'; try{ $connection = new PDO($dsn, $dbUser, $dbPassword); } catch (PDOException $exception){ $_SESSION['messages'][] = 'Connection failed: ' . $exception->getMessage(); header('Location: register.php'); exit; }
messages.php <?php session_start(); if (empty($_SESSION['messages'])){ return; } $messages = $_SESSION['messages']; unset($_SESSION['messages']); ?> <ul> <?php foreach ($messages as $message): ?> <li><?php echo $message; ?></li> <?php endforeach; ?> </ul> Edited Wednesday at 12:49 AM by bee65 Hi folks, I'm curious if I can for example, save a file from my server and it will save to all other servers - obviously if they accepted the connection first. It's for a software I developed and is almost complete and know there will be frequent updates to it. Instead of users downloading upates, I want the update files from my server to somehow synchronize to their server automatically? Anything called this?? Thanks for info. Following a tutorial on udemy, i tried to learn the very basics of mvc structure. I built the same project on my local server and it worked without giving me any error. but when i tried it on live server. its not working as it should. not showing any error. I tried to figure out the problem and found that for every page loading, it stops at the same line in my main.php file. <?php require($view); ?> starting from the above line. it stops. i came here to share my problem but i am unable to upload my files here. if there is a way to upload and share my files, please guide. zip file size of the whole project is 31.6 kb This isn't exactly an application design question, but rather a system design one.
I am about to install an Inventory Control System inside this store I work in.
The store itself also owns a Linode VPS running Centos 6.4 which hosts our website.
This new Inventory System will come built in with a Microsoft SQL Server, and supposedly it is a SQL Anywhere database, but I'm not too sure what that means.
I need to make this database publicly accessible, but only via the Linode VPS. Surely, setting restrictions is easy enough to address that issue. That isn't my question.
My first idea is to put this server into the DMZ, easy. But it doesn't exactly sound safe. So my next idea was to put a middleman server in the DMZ, this way the Linode can send queries to that middleman server and it will send that data to the SQL Server and back. This is very vaguely described I know, but I don't want to get too much into details, but rather, understand how I can create that middleman server, and what could Install onto it that would allow me to securely process queries?
My first thought was to install a webservice, that accepts an XML/JSON request and returns an XML/JSON response.
Then, I realized directly afterwards that I don't have any experience setting up a webservice like that.
What kind of options are there out there? Ultimately, my question is, should I just put the Server in the DMZ or should I create the middleman, and if so, can someone point me in the right direction as to getting a webservice set up? Edited by Zane, 15 July 2014 - 11:28 PM. If I an deep inside of nested folders, how do I get back to the Web Root (as far as directory notation goes)?? Debbie Having problems pointing to where files are. Is this the root?: Code: [Select] include "../connectdb.php"; That file is locate din the root. If I am already in the root when I include that statment, the file isn't found. If I use the above code while I am in the subdirectory hello, (root/hello), it works. I use this in every page, so I think I need a way to point to the absolute root, not relative. Hi guys, I've got a simple script that I'm running from a folder above the root (as a cron job). I've tried the script in the httpdocs folder and it works fine. Code: [Select] mail('email@example.com', 'Before include', '', 'From:<email@example.com>'); // include the myriad class include($_SERVER['DOCUMENT_ROOT'].'/path/to/class'); mail('email@example.com', 'After include', '', 'From:<email@example.com>'); // initiate and instance of our class $obj = new class_name; $email = $obj->email; $file = $obj->file_name; mail('email@example.com', 'End of file', $email.' & '.$file, 'From:<email@example.com>'); If I run this file in httpdocs, it's fine and I get all emails. If I run this from 1 folder above the root (from a cron job), I get the first 2 emails but not the last one, suggesting that the include hasn't worked. Could this be a permissions problem? I have tried running the cron job as both root and apache and changed the owner/group of the script to match. Is there a reason why includes won't work above the root? Hi, I want to get root path and use on links even if i'm in sub to sub folder etc... suppose my site name is fitness.com and having two subfolder. so url will become http://www.fitness.com/dir/dir_sub here i want to put a link to go to root directory file. there are different ways to do that. e.g: Code: [Select] <a href='../../filename.php'>go to that page</a> but i want to use some constant that always shows to root directory. as i defined here Code: [Select] define("SERVER_NAME" , $_SERVER['HTTP_HOST']); //and used it like this <a href='<?php echo SERVER_NAME; ?>/filename.php'>go to that page</a> it works when we're on root directory. but when we go to sub directory it added sub directory name with it. which i don't want. is there any way? Thanks Hi All, I googled this and there is endless results. I went through a lot of them but couldn't get this working properly. How do I link from within my web site root to files outside the root? It works for me using relative links i.e. ../../phpfiles/includes but that is going to get messy and I can't get a way of doing absolute links to work. If someone could lay that out so a newbie can get it clearly I would really appreciate it! Also - I understand why I should put all of my php files outside the web root but is this a guaranteed way to secure these files other than someone hacking my ftp access? I've looked at a few site hierarchy examples - Am I right that the only pages within the web site root should be template pages with calls to required files (outside the root), session checks, and content includes and all other includes that have php executable code should be outside the root? I really appreciate the advice and insight. Thank you! |