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.
Related
I have installed yii2 and I have tried to run using the PHP built in server using ./yii serve. When I open http://localhost:8080 I got the following permission error:
PHP Warning – yii\base\ErrorException session_start():
open(/var/lib/php/sessions/sess_t1462ivbhhq79igqjp6b4fekth, O_RDWR)
failed: Permission denied (13)
On other application on the same machine that it run on Apache, I fired up phpinfo() and I found that path /var/lib/php/sessions is set to session.save_path.
To work around the permission issue, I have tried to run sudo ./yii serve and it worked fine.
Now, I care about the security of my development system, where, occasionally, I expose it to the Internet to serve my clients visits to the currently developed apps. I don't know weather I keep running the app using sudo or is there a better way to change /var/lib/php/sessions permissions to allow php from the cli, php -S, to access it?
I have done the following to change the save session path to another accessible path by PHP cli:
From the terminal php --ini to get a list of configurations files and I meant by Loaded Configuration File entry to specify the path of the loaded php.ini file. In my case it is /etc/php/7.2/cli/php.ini.
Using any text editor that could be run as sudo, in my case I used kate, I opened the specified php.ini file and I search for: session.save_path entry of the php.ini and I uncommented it then change the path to a path in my home. In my case I set it to be /home/myuser/tmp/sessions. Save the file.
Now ./yii serve works fine without need to sudo and without need to change any settings of the php.ini for Apache.
I have installed macports and updated my path:
via docs:
http://guide.macports.org/#installing.shell.postflight
but now if I test any of the sites in my Sites folder, I get a 404.
so for instance if I go to localhost/~carey/test.php which is just a php_info, I get a 404
If I go to:
localhost/
I get the It Works! page
Am I missing a step to configure Macports to run apache from my Sites directory?
If I run $env from the command line I get:
TERM_PROGRAM=Apple_Terminal
SHELL=/bin/bash
TERM=xterm-256color
TMPDIR=/var/folders/rs/943jh19j31j3ld55yxqgf2mm0000gn/T/
Apple_PubSub_Socket_Render=/tmp/launch-NehzDd/Render
TERM_PROGRAM_VERSION=326
TERM_SESSION_ID=A329EAC2-AE9F-4460-BB1B-B35981BAE0ED
USER=carey
SSH_AUTH_SOCK=/tmp/launch-CgUaVv/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0:0
PATH=/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin
__CHECKFIX1436934=1
PWD=/Users/carey
LANG=en_US.UTF-8
SHLVL=1
HOME=/Users/carey
LOGNAME=carey
SECURITYSESSIONID=186b0
_=/usr/bin/env
and I can run any macport install, but I cannot configure the terminal to connect to my localhost in the browser.
So I think I have macports installed correctly, but I dont know how to make it run out of the /opt directory.
I also think this is relative to establishing the env variables, so apache knows to look to the /opt dir, but I don't know how to change it.
I am running Mavericks.
UPDATE
Following the docs recommended by eborisch here:
https://trac.macports.org/wiki/howto/MAMP
I have been able to setup the localhost directory, but still an issue.
Since I have multiple users on the machine, I had to comment out this line in httpd.conf:
Include conf/extra/httpd-userdir.conf
and added this to the httpd-userdir.conf file:
#
# Include user configurations
#
Include /private/etc/apache2/users/*.conf
which connects my Sites folder to the localhost.
I also needed to add this to the httpd.conf file to parse php files as php:
AddType application/x-httpd-php .php
Now, I have a file in my Sites dir called test.php, which has <?php phpinfo() ?>
and if I run localhost/~carey/test.php in the browser it works. phpinfo() returns that I am running php5.5.10 out of the /opt/ dir. So, all seems well. The problem is if I try to run any sites from folders in this directory. It just displays the directory tree, rather than treating it like a site.
For instance if I run,
localhost/~carey/mysite
it just returns:
Index of /~carey/mysite
Parent Directory
2005/
2006/
index.php
../
If I run
localhost/~carey/mysite/index.php
it runs that file correctly (ie looks correct in the browser)
Seems like an .htaccess issue, but not sure how I would resolve that globally for each folder in the Sites directory
any suggestions?
Probably better served on https://lists.macosforge.org/mailman/listinfo/macports-users/ the macports mailing list. But some basics:
Is the osx web server running? (Web sharing under the sharing control panel?) If so, turn it off, or configure the two to use different ports.
Is the macports apache2 installed? (sudo port install apache2)
Is it running? (sudo port load apache2)
Have you edited its configuration (/opt/local/apache2/conf/httpd.conf)?
See https://trac.macports.org/wiki/howto/MAMP for instructions on getting things up and running.
I installed PHP 5.3.x in my Ubuntu 12.04 Server using apt-get.
Now when I am trying to run a specific PHP script I get this error message--
"extension_dir does not exists /usr/lib/php5/20090626"
But when I logged in via SSH and went to the above path- it does exist and also contains some PHP extensions.
How do I resolve this problem?
The reason is that the php file is not accessible to browser.You should change the file permission .You can use chown and change the file permission like 777
use chown command for changing the ownership of the folder to the php user.
EDIT:
Please visit here
The user running apache is also running php
On Windows, when I run
pear config-set auto_discover 1
I get the following error
PEAR_Config::writeConfigFile fopen('C:\Windows\pear.ini','w') failed (fopen(C:\Windows\pear.ini): failed to open stream: Permission denied)
even though I had mentioned during PEAR installation that my config file was c:\pear\pear.ini.
How to fix this, please (without running PEAR in admin mode or changing the permissions of c:\windows\pear.ini)? I guess my problem will be solved if I can figure out where PEAR is getting the directory for pear.ini from.
Thanks!
In the PEAR installation, when I got to the step of modifying the paths I changed the path for pear.ini from C:\Windows\pear.ini to $prefix\pear.ini and I still ran into this same error. Apparently the installation script did not update everything that it needed to.
Based on a comment on a bug report for PEAR (http://pear.php.net/bugs/bug.php?id=16939), I added an environment variable PHP_PEAR_SYSCONF_DIR to point to my PEAR install folder (C:\php\PEAR).
I am now able to successfully run the same config-set command that you were initially attempting to run.
Note the follow-on comment on the bug report however. I only needed one PEAR installation on my machine whereas you may need multiple installations.
I was able to fix this by opening the command prompt as administrator. This is done by right-clicking on the command prompt icon and selecting 'Run as Administrator'. Once command prompt is open, navigate to your php directory and run: php go-pear.phar again. Should run without an issue.
The issue is, when you open your command prompt, your current account doesn't have the privilege to write to your windows directory. Running your command prompt as administrator, will allow for writing to c:\windows
Hope this helps.
My operating system is Windows 7.
I got my WAMP2.2 install in my computer.
Then I try to install PEAR.
However, I can not find my go-pear.bat file in my wamp directory.
Fine. I download in here: http://pear.php.net/go-pear.phar
and install using this file.
I put the file in
C:/wamp/bin/php/php5.3.8/pear/go-pear.phar
Run the command: php -d phar.require_hash=0 PEAR/go-pear.phar
After the installation, I include the path of pear in php.ini in php and apache folder.
I also include C:/wamp/bin/php/php5.3.8/ in windows $PATH variable.
But when I run pear command. It said it can not find the pear command.
I check the folder and just find a file called pear.bat and pear.ini.
I tried to run pear.bat again in command line. It still does not work.
Experts, please help on this issue.
Ok since many people may be asking the same thing. Let's suppose the following.
I'm currently running 2.2 E which includes Apache 2.2.22 – Mysql 5.5.24 – PHP 5.3.13 XDebug 2.1.2 XDC 1.5 PhpMyadmin 3.4.10.1 SQLBuddy 1.3.3 webGrind 1.0
Now, to install PEAR do the following:
Download this file:
http://pear.php.net/go-pear.phar
And put it on your WAMP server directory under the PHP version on the bin folder.
Run the command to install PEAR and you're over it.
Example (defaults, no change has been done)
Get the file on the link ->http://pear.php.net/go-pear.phar
Go to this directory C:\wamp\bin\php\php5.3.13
Open command prompt (cmd.exe). Supposing you're using Windows Vista and higher, press Start, type "cmd.exe" and right click on it and select run as administrator/CTRL+SHIFT+Enter (Haven't tested on non-priviliges rights)
Use Window's cd command to change the directory to the go-pear.phar file you've just downloaded. In my case I'll be pin pointing it to my own directory, so I did it like follows:
cd "C:\wamp\bin\php\php5.3.13"
Press Enter. You should note that instead of saying "C:\system\32" is now displaying C:\wamp\bin\php\php5.3.13
Write the following command and press Enter:
php -d phar.require_hash=0 go-pear.phar
Select whether you like or not a local copy or a system one. By typing system:local and pressing enter you'll install a local copy. By typing system and pressing enter you'll install a system-wide copy.
Type yes to confirm the option chosen.
The next list of directories, will be the referring directories that PEAR will install its components. If you select from 1 - 12 you can change the directory you'd like to install. By typing all and pressing Enter you'll be able to change them all in a queued manner. In my case, I just pressed Enter and left all defaults
DO THE FOLLOWING IN CASE YOU CONTINUE TO HAVE SOME LISTINGS
11. It is very probable that afterwards you'll receive a message like:
WARNING! The include+path defined in the currently used php.ini does not contain the PEAR PHP directory you just specified: If the specified directory is also not in the include_path used by your scripts, you will have problems getting any PEAR packages working.
Below it will also appear:
Would you like to alter php.ini ? [Y/n]:
Type y and press enter
This should put you running with PEAR on WAMP server :)
pear.bat is the executable on windows. You have to put that directory in your system's PATH variable for the command to be recognized.
All the steps mentioned to below link for GUI based - easy understanding review and setup:
Click here
For anyone looking for a more current answer. On Windows 10 I had to edit .bash_profile to add the following:
function __pear {
pear.bat $#
}
alias pear=__pear