I would like to pipe email through a PHP script.
To be recognized has a script to be execute by Shell, I've put that line a the begining of my file:
#!/usr/bin/php -q
I've enabled PHP's Mail Parse extension.
I have 2 issues:
If I move my script into a sub directory, any email can't be piped, despite of the new valid patch set in my c-panel (Seems like PHP IO stream can't be read in sub directories?). Otherwise, I can pipe email in /public_html (where my php.ini file is), but I'm still unable to call a Mail Parse's function that directory.
My script seems to use another php.ini file, because when I call a function from Mail Parse, PHP warns me that the function is undefined (if I use another script manually, in the same directory and same code, all works and there's no warning.). I've put that line to use a specific php.ini file #!/usr/bin/php -c /homeXX/XXXX/public_html/php.ini. It didn't worked.
Thanks for any answer, it'll be very appreciated.
Setting up stuff in your php.ini ist one thing.
I think you need to install pear/pecl and the mailparse package to make it work.
Depending on you linux flavor you can do that with (debian/ubuntu)
sudo apt-get install php-pear
sudo pecl install mailparse
and your php.ini needs the path to pear (if not already set) in
Path and Directories section.
take a look at the manual about mailparse
UPDATE: Depending of server configuration, you have to avoid space between command line option (-c) and path (/path/to/script). That solution worked in my case!
Related
I am trying to create a cron job that will back up my MySQL database. However it doesn't seem to ever call it.
I then tried to check if I could even run it from the terminal and I can't do that either. What is the problem?
I don't understand what the PATH variable means, I guess it must be something to do with that?
I'm just running php /var/www/html/backup.php
If php installed , go to the specified file location (cd to the file location in terminal) and enter below
php exampleFile.php
You need to install php if it's not there.
Try apt-get install php for debian http://php.net/manual/en/install.unix.debian.php
I've you've got it installed, try to use the full path to executable:
/usr/local/bin/php /var/www/html/backup.php
(Replacing /user/local/bin with the actual path to the php executable)
My server uses Ubuntu with PHP5 and NginX.
I have installed pear using sudo apt-get install php-pear, and later uninstalled it using sudo pear uninstall pear. Today I downloaded phpmailer using sudo apt-get install libphp-phpmailer.
I wrote code to send email with phpmailer. It begins with:
require_once("class.phpmailer.php");
and I edit the php.ini both in /etc/php5/cli and in /etc/php5/fpm to set:
include_path = ".:/usr/share/php/libphp-phpmailer"
It did work well if I execute this php program in command line, but if I visit this php page through my browser, it produce a HTML500 error, and I checked the error.log file, which shows:
PHP message: PHP Fatal error: require_once():
Failed opening required 'class.phpmailer.php'
(include_path='.:/usr/share/php:/usr/share/pear') in ...
I wander how comes this path? I am sure I have edited the include_path in both php.ini files. Is there another configuration file I missed? Where does the string ".:/usr/share/php:/usr/share/pear" come from?
If you are absolutely sure all paths are correct then it could be a file permission issue.
Find out what user Nginx runs under. It will probably be nginx. Run groups nginx and the output should be nginx : nginx, meaning the user nginx exists, and has only one group, which is also nginx.
On the command line navigate to the location of class.phpmailer.php and run ls -l to view the permissions of the files in that directory. Example output would be: -rw-r--r-- 1 someuser somegroup, meaning read and write access is granted to the owner (someuser), read access for the group (somegroup), and read access to everybody else.
The user nginx (if that is what it is running under) needs to have read access to that file. So change the owner/permissions as necessary.
If you need further explanation of how to do any of this just give me a shout and I will update this with further instructions.
My system has two PHP interpreters. One came bundled with the OS and the other I installed via the XAMPP package. All of my PHP extensions are applied to the XAMPP installation but PHPUnit seems to only run the version of PHP that came with my machine.
Does anybody know of a way I can configure or rebuild PHPUnit so that it uses my XAMPP PHP interpreter exclusively?
For Mac/Linux, the first line of the phpunit script with starts with
#!/usr/bin/php
change that to
#!/Applications/XAMPP/xamppfiles/bin/php
or whatever other php interpret you want to use.
Find the folder you installed PHPUnit in. There should be a file called phpunit.bat. It should have a line that reads something like
set PHPBIN="C:\php\php.exe"
%PHPBIN% "C:\php\phpunit" %*
Change it to read
set PHPBIN="C:\xampp\php\php.exe"
%PHPBIN% "C:\xampp\php\phpunit" %*
Or whatever the path to your PHP executable is
Since modifying phpunit file did not work for me because of phar signature errors, I was running phpunit with different php version by calling interpreter explicitly (on Linux):
php7.1 /usr/local/bin/phpunit
php5.6 /usr/local/bin/phpunit
Following the example with XAMPP, full path to php interpreter could be provided:
/Applications/XAMPP/xamppfiles/bin/php /usr/local/bin/phpunit
In agreement with Thomas' statement, additionally there's a line further below
if (strpos('/Applications/MAMP/bin/php5.3/bin/php', '#php_bin') === 0) {
set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path());
}
That I've been told you're also supposed to change to reflect the PHP you're interested in using
(I've set mine to MAMP obviously)
I've switched back and forth from 5.2 and 5.3 a lot recently :)
This applies to phpunit installed using Homebrew on Mac OS 10.9. I’ve editing the file located at /usr/local/Cellar/phpunit/4.2.6/bin as seen below. CAVEAT: I don’t know how Homebrew will handle this on a PhpUnit update, but for now it’s working to be able to select the php version that PhpUnit is using for it's testing.
#!/usr/bin/env bash
php=/Applications/MAMP/bin/php/php5.3.14/bin/php
#php=/Applications/MAMP/bin/php/php5.4.4/bin/php
/usr/bin/env $php -d allow_url_fopen=On -d detect_unicode=Off /usr/local/Cellar/phpunit/4.2.6/libexec/phpunit-4.2.6.phar $*
On Windows, this may be achieved using a similar approach to the ones mentioned in other replies.
In your /path/to/composer/phpunit directory, open the phpunit file in an editor. The first line should look like this:
#!/usr/bin/env php
Simply download your desired version of PHP for Windows, place the contents of the ZIP file somewhere to your liking, and reference the fully quantified path to the php.exe file, instead of just php. Like so:
#!/usr/bin/env /c/misc/php-5.5.9-nts-Win32-VC11-x86/php.exe
In my case, I put it in /c/misc/php-5.5.9-nts-Win32-VC11-x86/, which corresponds to C:\misc\php-5.5.9-nts-Win32-VC11-x86\ using Windows path syntax.
Remember to verify that the correct php.ini file is being used (php --ini or in a script file php_ini_loaded_file()).
I have use DB::Connect in my program for accessing the database.
I ran my php program this shows the error
DB.php file is not their.
require_once 'DB.php';
PEAR::setErrorHandling(PEAR_ERROR_DIE);
Then I copy the DB.php file and PEAR.php file from another machine to my
machine after that If I ran from command line it didn't through the error.
while running from browser this shows error. How to solve this problem.?
How to install this DB.php?
PEAR provides a command line installer that should take care of all the details:
pear install DB
Since PEAR packages are mainly PHP code, you can also copy the files manually, but you must make sure you copy everything, not only the first required file, and your script must also be able to find the files so you must add pear to the include_path PHP directive.
I just made a new install of WAMP on Windows 7 and I'm trying to get PEAR to work. Things are going wrong from the very beginning. When I try to execute the go-pear.bat file, it shows me this.
phar
"C:\wamp\bin\php\php5.3.1\PEAR\go-pear.phar"
does not have a signature Warning:
require_once(phar://go-pear.phar/index.php):
failed to open stream: pha r error:
invalid url or non-existent phar
"phar://go-pear.phar/index.php" in C:\
wamp\bin\php\php5.3.1\PEAR\go-pear.phar
on line 1236 Press any key to continue
. . .
How can I help it that the file doesn't have a signature?
This blog-post might interest you : Pear: “go-pear.phar” Does Not Have a Signature
It explains how to change a configuration option in php.ini to avoid this error message, and what's said it for WAMP 2.0 and PHP 5.3, so might work in your case.
Just in case anyone comes here from Google: We fixed the .phar download yesterday on http://pear.php.net/go-pear.phar.
In some circumstances (well, actually only on Windows :-)) the file could corrupt from the download. So for example, a lot of people wanted to download it and ended up copy-pasting the contents, etc..
We've asked some people on Windows to test and so far it worked for everyone I talked to. Let me know if it works for you.
Let’s try this from the PEAR directory. cd PEAR and let’s try that again.
php.exe -d phar.require_hash=0 go-pear.phar
Now the PEAR install runs fine.
If the go-pear.bat file won't run, try this procedure:
issue this command with cmd.exe:
php -d phar.require_hash=0 go-pear.phar
Allow the installer to edit php.ini.
Check the contents of PEAR_ENV.reg - located in the PEAR directory YOUR-PHP-INSTALL-PATH\PEAR\ folder (ex. c:\PHP\PEAR\PEAR_ENV.reg) to be sure it has the paths right. Edit as needed and run it. Check your path and environment variables for correctness, then do the same in go-pear.bat and php.ini (mine needed to be corrected to point correctly to my php.exe file).
Issue the
pear
command at the command line to test the path configuration. It will run and do everything but still can't install packages due to a missing dependency.
Download and uncompress Structures_Graph from the PEAR website (direct link).The file has three folders - docs, Structures and tests. Copy the Structure folder into the YOUR-PHP-INSTALL-PATH\PEAR\ folder (ex. c:\PHP\PEAR\Structures).
Issue the command:
pear install Structures_Graph
Even though the files are present, Structures_Graph is not really installed unless you issue the above command.
Issue the command:
pear update PEAR
Enjoy!
Good luck and thanks to Marcos Roriz for the graph dependency half of my solution!