I've created a phar of a Symfony2 web application, but I'm having some troubles with the cache-folders.
I found out that I could mount an external file/folder into a phar. That would fix my issue, but I can't get the example on the PHP site working.
I have a phar which contains an index.php:
<?php
$configuration = simplexml_load_string(file_get_contents(
Phar::running(false) . '/config.xml'));
?>
Then I include the .phar with the following code:
<?php
// first set up the association between the abstract config.xml
// and the actual one on disk
Phar::mount('phar://config.xml', '/var/www/$projectname/config.xml');
// now run the application
include 'phar-archive.phar';
?>
All files exists, but I get the following error:
PHP Fatal error: Uncaught exception 'PharException' with message 'config.xml is not a phar archive, cannot mount' in /var/www/$projectname/index.php:3
I already tried relative/absolute paths, changing permissions but can't get this to work. Additionally a working example of how I could mount a folder into a phar would be great !
First check that variable $projectname exist in this place (just run echo $projectname; before Phar::mount). If all ok, then change
Phar::mount('phar://config.xml', '/var/www/$projectname/config.xml');
to
Phar::mount('phar://config.xml', "/var/www/{$projectname}/config.xml");
It seems that variable $projectname not converted to its value because you used single quotes.
Related
i created a script in order to insert some articles via a php script. This script is working on my local machine (xampp), but when i deploy the whole joomla project to my web server i get the following error message:
Error displaying the error page: Application Instantiation Error: Application Instantiation Error
By adding some echo calls, i was able to find the line which causes the error:
$app = JFactory::getApplication('site');
Now i am wondering how to fix this behaviour and make my function also run on the web server.
Below i will provide my system informations and the beginning of my php function until the line, which causes the error message:
Systeminformations
joomla version: 3.6.5 Stable
db version: 5.6.34-79.1-log
php version: 5.6.30-he.0
web server: Apache
PHP snippet
<?php
echo "STARTING; ";
// get db connection
include('../includes/mysql.inc.php');
// get all sql querys
include('./autoNewsQuerys.inc.php');
/**
* Prepare joomla framework to insert article correctly
*/
if (!defined('_JEXEC')) {
define('_JEXEC', 1);
define('JPATH_BASE','/is/htdocs/wp1088688_4E1H7PYJFK/www');
require_once(JPATH_BASE . '/includes/defines.php');
require_once(JPATH_BASE . '/includes/framework.php');
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
}
echo "searching app;";
$app = JFactory::getApplication('site');
echo "Found app;";
Full browser output
STARTING; searching app;Error displaying the error page: Application Instantiation Error: Failed to start the session because headers have already been sent by "/is/htdocs/wp1088688_4E1H7PYJFK/www/1500AutoNews/autoNews.php" at line 3.
So as you can see the error is caused by the JFactory call. 'Found app' is never printed out.
Just copy the Joomla index.php file to another file and then replace the $app->execute code with your code.
Note: You don't need to include any MySQL library - since you are loading the Joomla environment then you have access to the JDatabase class, which is a database abstraction layer.
Another note: this file autoNewsQuerys.inc.php likely contains some issues (maybe you are trying to instantiate the app there, but the Joomla environment hasn't loaded yet). You should move it to the end.
if it was working on localhost and it is not working on Web server then the biggest issue is with defining the base path. Give a hardcoded base path of your joomla installation. I suggest you to check your base path using a php script. Create a php file and name it path.php. Put it in the Joomla main folder. Content of the file
<?php
echo "The Base path is ".getcwd();
?>
Once you get the path just change the Base_Path. For ex:
define('JPATH_BASE', '\var\www\joomla');
I'm getting an error that class is not found, but I clearly have the right path for where it is located:
<?php
require_once('stripe-php-2.1.0/stripe/lib/Stripe.php');
Stripe::setApiKey('my_key');
var_dump($_POST['stripe-token']);
?>
Every article I've come across all claim that the problem is (not including the right path) in the require_one, include, or require. (I've tried all 3). But still no luck. My database calls follow the same format and my WAMP server has no problem creating my database class.
This is copied directly from my file explore (copy paste)
website\stripe-php-2.1.0\stripe\lib\Stripe.php
My php file that I am using to try and access Stripe sits in the same place as 'website'.
PHP version 5.5.12
tutorial references: http://www.larryullman.com/2013/01/09/writing-the-php-code-to-process-payments-with-stripe/
Other reference: http://www.youtube.com/watch?v=Lka_JBM9bbY
It's because it uses a namespace. Try:
\Stripe\Stripe::setApiKey('my_key');
It is better to initialize all classes.
require_once ("stripe_folder/init.php");
then use namespaces:
\Stripe\Stripe::setApiKey('key_key_key_key_key_key');
I'm getting this error
Fatal error: Cannot redeclare getAllStaff() (previously declared in /Applications/XAMPP/xamppfiles/htdocs/StaffTools/database/StaffHandler.php:5) in /Applications/XAMPP/xamppfiles/htdocs/StaffTools/database/staffHandler.php on line 15
I'm building an application in Apatana Studio 3 and I renamed a file from staffHandler.php to StaffHandler.php (uppercase S) so the former no longer exists.
I get all my PHP files from the database directory using the below PHP code
foreach(glob("database/*.php") as $filename) {
include $filename;
}
And then call a method called getAllStaff() here:
<select name="staff">
<?php getAllStaff(); ?>
</select>
Obviously, this method is now in StaffHandler.php. This was working fine until I changed the filename of the name.
Things I've tried
Clearing my cache in Firefox
Rebuilding & cleaning my project in Aptana
Changing the filename back to staffHandler.php
Conditional function statemet if(!function_exists....
Why on earth would PHP throw an error like that for a file that doesn't exist anymore?
UPDATE: RESOLVED
I had a reference to the staffHandler.php file buried within all my PHP scripts and I think this was the source of the problem. When I ran ls -la at the terminal in the database directory only StaffHandler.php appeared but when I ran find staffHandler.php and rm staffHandler.php it erased both staff and Staff. Must've been some kind of link between created by application code.
I'm trying to upload a file to sftp server using phpseclib library. Here's the code I've written
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib0.3.5');
$fileName = "sImg3.jpeg";
$fileData = file_get_contents($fileName);
$b64Data = base64_encode($fileData);
// upload the file to ftp server
include('Net/SFTP.php');
include_once('include/config.php'); // contains sftp connection details
$sftp = new Net_SFTP($ftpHost);
if (!$sftp->login($ftpUser, $ftpPasswd))
{
die("Failed to connect to SFTP server");
}
else
{
$sftp->put($filename,$b64Data);
echo "Uploaded the file (".$filename.")\n";
}
When I try to run this, I'm getting:
PHP Fatal error: Call to undefined function crypt_random_string() in
/var/www/phpseclib0.3.5/Net/SSH2.php on line 1014
I've installed php5-mcrypt and phpseclib. Do I need to install any other dependencies for phpseclib? Please let me know.
Thanks much in advance,
Regards,
Sudheer
crypt_string_random is defined in Crypt/Random.php:
https://github.com/phpseclib/phpseclib/blob/0.3.5/phpseclib/Crypt/Random.php
But then again Net_SSH2 auto-includes Crypt/Random.php:
https://github.com/phpseclib/phpseclib/blob/0.3.5/phpseclib/Net/SSH2.php#L749
And Net_SFTP extends Net_SSH2:
https://github.com/phpseclib/phpseclib/blob/0.3.5/phpseclib/Net/SFTP.php#L253
And Net_SSH2 does a require_once so if anything you should be getting some sort of "file not found" error, if you're getting an error at all, not a "function not defined" error..
The problem is caused by how PHP handles nested include statements and relative paths. If you look at the current phpseclib programming, at least 'some' of the includes still use include() instead of require_once() which silently fail - which is why you don't see the errors about failing includes.
It all comes down to how PHP resolves relative pathing of nested includes - using the starting location of the parent script or the starting location of the current/child script. More info on the conundrum of PHP nested includes with relative pathing here:
php nested include behavior
When I ran into this problem myself, I worked around it by promoting /phpseclib out of it's own subfolder and into my existing /includes folder. Then I only ever include phpseclib files from within php scripts in my /includes folder so that the relative paths in phpseclib's nested include statements will work.
I am trying to install xml diff ; https://github.com/mmacia/XMLdiff and i have not managed yet to make it work.Whenever i run any test example,i get
Fatal error: Interface 'PHPUnit_Framework_Test' not found in
C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php on line 85
Has anyone managed to install and use the library.I am using xampp on windows.
I believe your problem has to do with PHPUnit's Autoloader.php not being included. This file sets the php spl_autoloadspl_register function which is responsible for loading in interfaces and classes like PHPUnit_Framework_Test.
According to this SO question, you have to include the autoloader file manually. Without knowing more about your set-up and how that particular library works, I would say do something like this in the appropriate file(s):
// define phpunit path
if ( ! defined('PHPUNIT_PATH')) {
// define an absolute path to your PHPUnit dir
// CHECK THIS, i'm not good with php on windows:
define('PHPUNIT_PATH','C:\xampp\php\PEAR\PHPUnit');
}
// Then include the autoloader like this:
include PHPUNIT_PATH.'Autoloader.php';
I hope this helps you or anyone else out.
Check execution flags for C:\xampp\php\PEAR\PHPUnit\Framework\Framework\Test.php
The file needs to be executable by the user who is launching tests (probably you).