Run my php files from outside htdocs - php

I have my xampp installed and running sites from the htdocs folder. I want to create a website directory in a different location and run the files online from there.
I know I can do this somehow using both Virtual Host settings and changing my hosts file in System32.
I want to change my URL from localhost/websites/mysite/ to just mysite/
Can anyone offer assistance, thank you

Locate httpd.conf file on your local XAMPP install:
C:\xampp\xampp\apache\conf\httpd.conf
Edit the “DocumentRoot” line to the location of the remote \htdocs folder.
Example:
“C:/xampp/xampp/htdocs” to “C:/Users/Ann/Documents/My Dropbox/Dev/Xampp/xampp/htdocs”
Edit the “Directory” tag to the same remote location you set for DocumentRoot.
“C:/Users/Ann/Documents/My Dropbox/Dev/Xampp/xampp/htdocs”
Save the file and restart your local Apache server.
Navigate to your "localhost” in your browser and you should see the remote web site files.

You don't have to configure anything and then reconfigure ...
What I do is the following:
I have a simple PHP file in htdocs folder, named 'PHPexec.php', which accepts files from anywhere and it runs them as 'include' files. Example: Suppose you want to run "D:\PHPs\xxx.php'. You run http://localhost/PHPexec.php?f=D:\PHPs\xxx.php. PHPexec.php will receive the pathfile as a $_GET variable and run it as an 'include' file:
$file = $_GET['f']; // After checking if it is set etc.
include $file;
Simple as that. From the moment you create your 'PHPexec.php', you have just to run http://localhost/PHPexec.php?f={PHP_file}. Your PHP file will be run as if it were stored in localhost! No configurations and re-configurations ...
(You can configure your 'PHPexec.php' to also accept variables to pass to the PHP file, etc.)

Related

How to run PHP files on XAMMP on A Mac

I have saved a PHP file to my Applications/XAMMP/htdocs directory and I want to run it in a browser.
I have used all sorts of url combinations including:
http://localhost/xammp/htdocs/HelloWord.php
http://localhost/xammp/HelloWord.php
amongst others and I cannot find the right url.
I am using XAMPP on a Mac Majove.
If you installed the XAMPP VM version, then you can probably access it via http://192.168.64.2/HelloWord.php (check the General tab in the XAMPP app for the IP address)
If you installed the native version, then I guess it is
http://localhost/HelloWord.php
The htdocs/ folder is the document root. Its content is served under the server address. Neither the xampp nor the htdocs folder will be part of the URL. The paths are relative to the document root, and you shouldn't be able to access parent directories above htdocs/ (although server-side code such as PHP has access to the file system and may work with files outside of the document root).
First of all, expecting the php file to have information that can be visualized in a web browser, inside xampp if you have the .php file in the htdocs folder you should be able to visualize it like this:
http://localhost/HelloWord.php
Found it by trial and error, quite different from what I took from various instructions on line:
http://localhost/HelloWord.php
XAMPP's default root should be "htdocs" or "www". Put your PHP files into those folder and try again.
if it is not work, find the configuration of Apache and PHP in XAMPP folder.

XAMPP won't open PHP files in directory (Mac)

All the servers are running correctly in XAMPP, and I when I run http://localhost the XAMPP page comes up. However when I try to run a php through xampp by accessing the directory where the file is stored, i.e.,
http://localhost/Applications/XAMPP/xamppfiles/htdocs/gallery.php
I get error 404. I've tried loads of different paths, but here is the path to the file in finder path image
Any ideas?
Thanks!
your webserver is resolving the domain localhost to a specific directory, the so called document root. (this can be adjusted in your server config). I would assume that it points to /Applications/XAMPP/xamppfiles/htdocs. so your file should be accessible via
http://localhost/gallery.php

PHP mailer - include path when folders are outside root

I had phpmailer running fine on a hosted server. I moved to a VPS which is linux/ubuntu so most of the installation is done via the console.
Previously my include was simply:
include('phpmailer/class.phpmailer.php');
include('phpmailer/class.smtp.php');
Both those were inside the root folder, when i ran the install via the console it stored the files in usr/shar/php/libphp-phpmailer
I have never worked with files outside the root, is there a special way to reference them in include()?
For reference, my root folder is: var/www/
This may work for you now
include('/usr/share/php/libphp-phpmailer/class.phpmailer.php');
include('/usr/share/php/libphp-phpmailer/class.smtp.php');
Since you have console access to that machine, cd in to /usr/share/php/libphp-phpmailer and make sure those files are there. If they aren't, you can try to locate those files.
In ubuntu/debian you can find files using 'sudo updatedb; locate class.phpmailer.php' (updatedb ensures your file name database is up to date)
use the following ../ as move back to directory
like if are at www/html/ and want to access file in www/lib/
include(../lib/filename) ;

How can i connect two files on a mac?

I just bought my first mac and I develop in PHP. I run MAMP to serve my php files. You have to save files to Applications/MAMP/htdocs to be able to serve a file. I would rather have one file in the root directory that sends all the files I create to htdocs so that I can access them easier in emacs and such from the command line. How could I do this?
You should check httpd.conf of MAMP. You can change the root folder of you WWW there. Look for the http.conf file in the Apache directory, and then look for htdocs and change that path.

MKDIR is not working correctly?

i'm using Xampp. When I tried to do this earlier, it worked, but now it is not working.
I'm trying to make a directory in my www folder to hide it from baddies who steal files.
Each user gets their own folder in uploads to put their files on.
Xampp uses apache, and Xampp is a local web server. It allows me to design websites without the need of an online host. The www folder is in my C:\program files\xampp\php\www\ and I need to make a directory there. I know it's possible because i've done this before, I have just forgotten how to make it happen.
When I make a directory I use:
$uploaddir1 = "xampp/php/www/uploads/".$esclcusername."/";
mkdir($uploaddir1,0777);
Do I need to include C:\program files\ before xampp?
And finally, how would this be possible on a real online web host?
I saw your question here and searched some on google. This is what i found:
mkdir("D:/hshome/rubygirl58/gameparody.com/clansites/".$sitename."/lib", 0777)
So yes, I think you have to include the complete path.
Greetings,
Younes
you need to make sure that you give permisions to the parent folder to create dirs in it (0777)
to get the full path you can use dirname(FILE) wich will return the path for the directory of the file in wich it is runned

Categories