- PHP exec() command not working
- Trial 1
- Trial 2
- Trial 3
- Trial 4 (The only one that returns an error!)
- Privileges:
- Finaly found the solution!!
- PHP script can’t run bash script. sh: Permission denied
- 5 Answers 5
- Troubleshooting:
- PHP — Connection failed: Access denied for user ‘username’@’localhost’ (using password: YES) [duplicate]
- 2 Answers 2
- PHP MySql (1045) Access Denied For User
- Access Denied for PHP Files Only
PHP exec() command not working
My problem is: I want to execute this command in PHP. The command is necessary to reload the configs for filezilla, after creating a new user with an PHP script.
C:\Program Files (x86)\FileZilla Server\FileZilla Server.exe /reload-config
It does work when i try it directly in CMD. But in PHP if doens’t somehow work. I tried so many things, that im going to try to give you all the manners i tried. I tried to do this at the following ways:
Trial 1
$command = '"C:\\Program Files (x86)\\FileZilla Server\\FileZilla Server.exe" /reload-config'; exec( $command, $output, $return); print_r($output); echo '
' .$return;
Trial 2
$command = '"C:\\Program Files (x86)\\FileZilla Server\\FileZilla Server.exe" /reload-config'; system( $command, $output); print_r($output);
Trial 3
$command = 'C:\\"Program Files (x86)\\FileZilla Server\\FileZilla Server.exe" /reload-config'; exec( $command, $output, $return); print_r($output); echo '
' .$return;
Trial 4 (The only one that returns an error!)
exec( 'C:\\"Program Files (x86)\\FileZilla Server\\FileZilla Server.exe" /stop 2>&1', $output); print_r($output);
Array ( [0] => Toegang geweigerd. )
Privileges:
In allmost all awnsers found they talked about privileges. I did following privileges: Gave all web users and IUSR privileges to CMD.exe and FileZilla Server.exe, and tried to set the IIS authentication from anonymous to an Administrator account Somebody said to try this:
echo '
'; system('set', $retval); echo '';
If i do that my output is: http://pastebin.com/SjzeQpJ0 If you guys want anymore details just ask. I hope you guys can figure it out for me. I tried to be as clear as possible. Thanks.
Finaly found the solution!!
- Login to the Remote of your server (if you have access to it) Open
- Open the IIS manager
- Select -> Application Pools node underneath the machine node (left panel)
- Right click on the desired domainname -> Advanced settings
- Scroll to Process Model -> Id
- Click on the 3 dots
- Check the Custom Account radio button
- Fill in an existing administration account which has access to the remote desktop and of course its password
- Press OK
- Now go to the .exe or whatever file you want to access throught the exec command and
- Right click on the file and select properties
- Go to the security tab
- Select Edit
- Now grand full rights to the account you selected before. If its not listed than add it manualy by clicking on Add
If you have done all of this, it now should work.
PHP script can’t run bash script. sh: Permission denied
I’m trying to exec a .sh script from PHP, however it is not executing. I checked the error logs, and I’m getting the ‘sh: Permission denied’ error. I checked under which user php is being run, and it’s done under the apache user. I tried changing the .sh’s ownership to the apache user, but there is no result. I thought at first this was because the script was outside the www/ dir, however even when I put the script in the same directory, the error is still being given. Are there any solutions to this other than adding the apache user to the SUDOers list? The sh script runs fine if I launch it from putty using the ‘php filename.php’ command.
Is it a shell script or a PHP file? Your last paragraph isn’t clear about that. Also, did you set execute permissions ( x ) on the file? Did you specify the script interpreter in a shebang line?
It’s a bash script to be ran from PHP. Yes I did make it an executable and I did specify the script interpreter. It works correctly when I execute the PHP script from putty and the bash script gets called and runs correctly. But if I run the php script from the webbrowser instead it fails to run the bash script and it will do this error since it’s running as the apache user and not the user I use in putty.
Try chmod 775 yourscript.sh . That will give r-x (read and execute) permissions to «Other» users on that file.
I tried it. No luck.. I can’t know the exact reason until tomorrow though. I don’t have access to the logs from my location. I will get back to you guys. Thank you for your help. 🙂
5 Answers 5
Try the following suggestions:
- Try to run below test command, and check whether it worked:
- php -r «echo exec(‘whoami’);»
- chmod 755 dir; chmod 755 file
- Try also to add a +s flag (sudo) to the file (not recommended):
- chmod u+s file ,
- Otherwise, move the script inside it,
- or add that directory to your Apache configuration,
- or add this directory to your include_path , e.g.:
- php.ini file: include_path «.:/usr/local/lib/php:/your/dir»
- or .htaccess file: php_value include_path «.:/usr/local/lib/php:/your/dir»
Troubleshooting:
- If you changed your php.ini or httpd.conf file, don’t forget to restart the web server,
- Check your Apache error log for additional details.
- Enable in your php.ini all kind of errors ( display_error , error_reporting , etc.).
Still no luck for me 🙁 Any suggestions?«` [root@kiwi tmp]# ls -ld /;ls -ld /tmp;ls -ld /tmp/sleep;grep ‘^include_path =\|^safe_mode =’ /etc/php.ini dr-xr-xr-x. 27 root root 4096 Sep 3 12:31 / drwxrwxrwt. 4 root root 4096 Sep 3 15:45 /tmp -rwxr-xr-x. 1 root root 24 Sep 3 15:39 /tmp/sleep safe_mode = Off include_path = «/tmp:/home/kiwi_build»«`
Such an issue might depend on the OS you use and how it is configured. Some linux distros (mainly those based on RHEL like CentOS or Fedora) come with SELinux activated by default. This can be checked, and temporarily changed, with the following commands:
root@ls:~# /usr/sbin/getenforce Enforcing root@ls:~# /usr/sbin/setenforce Permissive root@ls:~# /usr/sbin/getenforce Permissive
You can also have a more complete view on the current configuration with:
root@ls:~# /usr/sbin/sestatus SELinux status: enabled SELinuxfs mount: /selinux Current mode: permissive Mode from config file: enforcing Policy version: 21 Policy from config file: targeted
This change can be made permanent by editing the /etc/selinux/config file and set the SELINUX variable to permissive or disabled .
But, the correct way to solve this kind of issue, if you are indeed in this situation, is to check the /var/log/audit/audit.log log file. It will contain all the events related to SELinux rules. You’ll then probably should give your script the correct context, i.e. being authorized to be run by the apache/php user. Checking SELinux security context is done with ls -Z :
root@ls:~# ls -alZ /var/www/cgi-bin/ drwxr-xr-x root root system_u:object_r:httpd_sys_script_exec_t . drwxr-xr-x root root system_u:object_r:httpd_sys_content_t ..
This list the User, the Role and the Type of each file/directory. Here the httpd_sys_script_exec_t type gives the files in the cgi directory the permission to be executed by httpd. Your shell script should probably have the same type.
You can also feed the audit.log lines to the audit2allow command. It will output you the changes needed to make SELinux happy. But usually the changes suggested need to be done on the SELinux policy itself which is not what you should do in your case (still, this output can give some clue at what is going on).
PHP — Connection failed: Access denied for user ‘username’@’localhost’ (using password: YES) [duplicate]
I am facing this error. tried all solutions given in other threads. creating a new user@localhost and grant privileges to it. But nothing works for me. still getting this error..
The issue is on your MySQL configuration then (assuming you are using the correct username and password). Did you grant privileges to the «username» account on localhost? Did you flush privileges after? Is the account actually created with the proper «IDENTIFIED BY» clause for the «password»?
It’s most likely not an issue with your PHP code, but with your actual MYSQL configuration as mentioned above.
if you use phpmyadmin look on users and check if your user have correct host for access. webvaultwiki.com.au/(S(iungfwenvz2f5c55pioeinil))/…
2 Answers 2
Some thing wrong with username or password
If you are using windows by default username is «root» and password is «» (empty),
no i m not using root. i created a separate user for that database. and also grant all privileges to it . and also m using Ubuntu 16.04
1 of 2 things is probably happening
What do you get when you execute execute following query
FLUSH PRIVILEGES; SHOW GRANTS;
Update July 4,2016
I suspect that the user’s password was stored incorrectly. Try resetting the password (you may need to be connected as the root user for this to work):
ALTER USER 'username'@'localhost' -> IDENTIFIED BY 'cleartext_password';
If that doesn’t work you could try the older syntax:
SET PASSWORD FOR 'username'@'localhost' = PASSWORD('cleartext_password');
Replace cleartext_password with the password you wish to use. Then try to connect again.
Ok, let’s start with a fresh new user. Execute the 3 commands below as the root user.
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'cleartext_password'; GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost'; FLUSH PRIVILEGES;
If all 3 commands executed properly, try next to connect to your database as newuser .
Did it work? If not, what error do you see?
PHP MySql (1045) Access Denied For User
I’ve tried to search for an existing answer to this problem, but the answers I find have not worked thus far. I’ve been attempting to use PHP to connect to a MySql database. My web host uses cPanel on Linux. The code I’m using to do this seems standard enough:
$mysqli = new mysqli("localhost", "cPanelUsername_dbUsername", "dbPassword", "cPanelUsername_dbName");
Failed to connect to MySQL: (1045) Access denied for user 'cPanelUsername_dbUsername'@'localhost' (using password: YES)Access denied for user 'cPanelUsername'@'localhost' (using password: NO)
- «localhost» is the host server where the MySql server is located (it seems like this works)
- «cPanelUsername» is my cpanel username
- «dbUsername» is the database user, which I added to the database with all permissions granted
- «dbPassword» is the database password for dbUsername
- «dbName» is the database name
I ended up adding my cPanel username before the dbName and dbUsername after searching for answers to this issue elsewhere.
It looks like I have everything set up correctly but it’s not connecting (with the error above). I don’t have any direct control over the server that I wouldn’t have to ask my web host about, which may take a few days to get sorted out. Do I have something wrong with my connection code?
Access Denied for PHP Files Only
I am getting 403 Access Denied errors from Apache any time I try to access a PHP file. HTML files and text files work fine. I’ve played with every conceivable permissions combination on the PHP files I can think of, from 644 to 777. Doesn’t change anything.
I also played with the permissions on the FCGI wrapper and parent folder. With o+x (777, 775, 773, 771), I get this in the browser:
Access forbidden!
You don’t have permission to access the requested object. It is either read-protected or not readable by the server.
…and this in the vhost error log:
client denied by server configuration: /srv/www/hostname/fcgid-bin/php-fcgid-wrapper
With o-x (776, 774, 772, 770, or below), I get this in the browser:
Forbidden
You don’t have permission to access /fcgid-bin/php-fcgid-wrapper/index.php on this server.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
(13)Permission denied: access to /fcgid-bin/php-fcgid-wrapper/index.php denied
This is really boggling my mind seeing as my setup was working fine until I started getting this and I don’t know what I possibly could have done to change that. /usr/bin/php-cgi and the wrapper both work fine with the exact same input files when called directly.
ServerAdmin admin@hostname.com DocumentRoot "/srv/www/hostname/public/" ServerName hostname.com ServerAlias www.hostname.com SuexecUserGroup hostname hostname ErrorLog "/srv/www/hostname/logs/error.log" LogLevel debug CustomLog "/srv/www/hostname/logs/access.log" combined Order allow,deny Allow from all # http://www.linode.com/forums/viewtopic.php?t=2982AddHandler php-fcgi .php Action php-fcgi /fcgid-bin/php-fcgid-wrapper Alias /fcgid-bin/ /srv/www/hostname/fcgid-bin/ SetHandler fcgid-script Options +ExecCGI ReWriteEngine On ReWriteRule ^/fcgid-bin/[^/]*$ / [PT]