PHP mailer - include path when folders are outside root - php

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) ;

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.

openshift wordpress serving old pages, ignoring header.php changes

I have openshift with wordpress cartridge.
I need to edit/write php files, and have done so via Wordpress theme editor page.
( i have confirmed by sftp that it did edit the files)
Also I have also edited php files localy, then uploaded them by sftp.
( I do not use git, because by default it does not include all the relevant directories, and is useless to me)
All the php files are in directory:
/var/lib/openshift/53....555/app-root/data/themes/purple-pro
What is supposed to happen, is html output is meant to change, after php file changes.
It does not.
Try restarting your app with rhc app restart -a <yourappname>
For other people having problems with openshift and editing php files.
It seems all PHP Files are cached/compiled, and even deleting a info.php file, still serves a old output webpage.
recomended solution is: use git so it can restart your webserver ( while also it deletes your wp-content directory ffs)
Actually works solution is:
use a linux terminal:
rhc app restart -a myapp
Viola, all the php files now run.

Run my php files from outside htdocs

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.)

How to run a PHP file on my computer that is outside the htdocs directory?

I just installed Apache and PHP on my computer to be able to run PHP files locally.
I can run a PHP file if it is located in Apache2.2\htdocs directory.
Is that possible to run PHP files outside this directory ?
I'm looking to a simple solution, because all I need is to write a small PHP code and try it locally.
I would like to be able to run the PHP file by right clicking it -> Open with Firefox
You can run a PHP script from anywhere using the command line:
php yourscript.php
There is some ways to do it, but the simplest way is using 'include' or 'required' php command:
<?
include ('/somewhere/outside/of/your/htdocs/file.php');
?>
Please note you may need to turn off 'open_basedir' php directive.
Newer versions of php come with php-cli: a command line interface. So to run php code, you just need to type:
php some_code.php
Or you can change paths in apache config to another dir
you cannot open it with firefox.
Because firefox has nothing to do win PHP.
So, you need to request this URL from a web-server
Create a windows shortcut with http://127.0.0.1/file.php
or whatever way you prefer to click web links
Yes. You don't say if you want to run it from the web server, or from the command line, but you can use include past the web root.
You can either run it from the command line,
or you can create a "wrapper" script within your htdocs that "includes" the file from outside of the htdocs directory
I had always wondered about it the same manner, say you have a folder in a drive either than the apache/htdocs folder in drive C, and you would like to develop directly in this folder. But think about it this way, would you put your folders else where and expect it to be running on the web? Now Way. Why would you do that?
Goto conf folder and open httpd file change
DocumentRoot "C:/your/path" and
Directory "C:/your/path"
This should work
if it says forbidden access go to this link
Error message "Forbidden You don't have permission to access / on this server"

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