LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-21-2019, 07:07 AM   #1
Michaelcc
LQ Newbie
 
Registered: Aug 2019
Posts: 7

Rep: Reputation: Disabled
php


Hi

My php program is working in linux environment but in browser not working ..its shows blank..i mean i make a php one program in /var/www/html folder. i run this program in command prompt its working properly eg.php /var/www/html/test.php but in browser its showing blank.


pleas suggest me how can i solve this issue
 
Old 08-21-2019, 07:17 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Michaelcc View Post
Hi
My php program is working in linux environment but in browser not working ..its shows blank..i mean i make a php one program in /var/www/html folder. i run this program in command prompt its working properly eg.php /var/www/html/test.php but in browser its showing blank.

pleas suggest me how can i solve this issue
Since you don't tell us ANYTHING (version/distro of Linux, show us your PHP code, tell us version of PHP, etc.), we have no idea. Short answer: you have a bug in your code.

Longer answer: look at your PHP logs and your Apache error logs. There is SOME error in your code, preventing a browser from displaying things.
 
Old 08-21-2019, 08:58 AM   #3
pingu_penguin
Member
 
Registered: Aug 2004
Location: pune
Distribution: Slackware
Posts: 350

Rep: Reputation: 60
did you check the permissions of the file ? is it readable, executable etc
 
Old 08-21-2019, 09:31 AM   #4
Michaelcc
LQ Newbie
 
Registered: Aug 2019
Posts: 7

Original Poster
Rep: Reputation: Disabled
permission is -rw-r--r--


can i set 777?
 
Old 08-21-2019, 09:35 AM   #5
pingu_penguin
Member
 
Registered: Aug 2004
Location: pune
Distribution: Slackware
Posts: 350

Rep: Reputation: 60
try
# chmod 750 (path/to/your/php/script)

What are the group and owner permissions of the script ?
If you are planning to use it with apache , you might have to change those too , unless I am horribly wrong.
 
Old 08-21-2019, 09:36 AM   #6
pingu_penguin
Member
 
Registered: Aug 2004
Location: pune
Distribution: Slackware
Posts: 350

Rep: Reputation: 60
We also would appreciate additional details , the error can be elsewhere too , so give in as much possible safe details as you can.
 
Old 08-21-2019, 09:38 AM   #7
Michaelcc
LQ Newbie
 
Registered: Aug 2019
Posts: 7

Original Poster
Rep: Reputation: Disabled
Hi

Thanks for your reply.

I set the permission 777 , and owner and group is Apache
 
Old 08-21-2019, 09:40 AM   #8
pingu_penguin
Member
 
Registered: Aug 2004
Location: pune
Distribution: Slackware
Posts: 350

Rep: Reputation: 60
Ok , I would set it 755 or 750 if I were you.

Did you restart the apache service , just in case ?
 
Old 08-21-2019, 10:02 AM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
What distribution / version are you running?

The original permissions are correct. Apache uses a module to "run" php code and therefore all files in the document root folder should be world read only (644).

As stated you need to check the Apache log files for errors where depends on what distribution you are running ( could be /var/log/httpd).

You need to post your PHP script. It is possible the script will work from the command line but not from Apache.
 
Old 08-21-2019, 10:35 AM   #10
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Michaelcc View Post
permission is -rw-r--r-- can i set 777?
...and...
Quote:
Originally Posted by Michaelcc
I set the permission 777 , and owner and group is Apache
Is there a reason you're not answering any other questions? You were asked about the PHP log files, Apache log files, and to show us the script. Since you're invoking this with "php /var/www/html/test.php" and it's working, it's most probably *NOT* anything with permissions, and setting it to anything but 644 isn't a good idea.

What is the actual LINK you're putting in the web browser to get this to come up??
 
Old 08-21-2019, 11:57 AM   #11
urbanwks
Member
 
Registered: Sep 2003
Distribution: Slackware64-Current, FreeBSD 12.1, Alpine 5.4, Manjaro 19, Alpine on WSL [Win10]
Posts: 194

Rep: Reputation: 213Reputation: 213Reputation: 213
Does any php script work for you on Apache?

Try a file with just:

Code:
<? phpinfo(); ?>
and see if you get anything. If it's blank, the php module probably isn't setup properly in httpd.conf.
 
1 members found this post helpful.
Old 08-22-2019, 02:42 AM   #12
Michaelcc
LQ Newbie
 
Registered: Aug 2019
Posts: 7

Original Poster
Rep: Reputation: Disabled
Hi

extremely very sorry for the delay response.

<?php

/*if (isset($argc)) {
for ($i = 0; $i < $argc; $i++) {
echo "Argument #" . $i . " - " . $argv[$i] . "\n";
}

$email = $argv[1];
$pass= $argv[2];*/

$email='bshdsbdh.bshdbs@gmail.com';
$pass='test@123';
if(isset($email)){

`echo '8VYABqmL1Z' | sudo echo '[smtp.gmail.com]:587 {$email}:{$pass}' > /etc/postfix/sasl_passwd`;
`echo '8VYABqmL1Z' | sudo postmap /etc/postfix/sasl_passwd`;
`echo '8VYABqmL1Z' | sudo chmod 640 /etc/postfix/sasl_passwd*`;
`echo '8VYABqmL1Z' | sudo chown rootostfix /etc/postfix/sasl_passwd*`;
`echo '8VYABqmL1Z' | sudo systemctl reload postfix`;

}
else {
echo "argc and argv disabled\n";
}


this is my php script, in command line its working properly.
 
Old 08-22-2019, 04:50 AM   #13
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
PHP works differently from the command line versus web server.

Since the web server typically runs as the apache user and as far as I know it does not have sudo rights.
 
Old 08-22-2019, 05:13 AM   #14
Michaelcc
LQ Newbie
 
Registered: Aug 2019
Posts: 7

Original Poster
Rep: Reputation: Disabled
Hi

Thanks for your quick reply. am new in linux environment so next what should i do, please guide me
 
Old 08-22-2019, 07:01 AM   #15
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Michaelcc View Post
Hi
extremely very sorry for the delay response.
Code:
<?php

/*if (isset($argc)) {
        for ($i = 0; $i < $argc; $i++) {
                echo "Argument #" . $i . " - " . $argv[$i] . "\n";
        }

$email = $argv[1];
$pass= $argv[2];*/

$email='bshdsbdh.bshdbs@gmail.com';
$pass='test@123';
if(isset($email)){

`echo '8VYABqmL1Z' | sudo echo '[smtp.gmail.com]:587 {$email}:{$pass}' > /etc/postfix/sasl_passwd`;
`echo '8VYABqmL1Z' | sudo postmap /etc/postfix/sasl_passwd`;
`echo '8VYABqmL1Z' | sudo chmod 640 /etc/postfix/sasl_passwd*`;
`echo '8VYABqmL1Z' | sudo chown root:postfix /etc/postfix/sasl_passwd*`;
`echo '8VYABqmL1Z' | sudo systemctl reload postfix`;

}
else {
        echo "argc and argv disabled\n";
}
this is my php script, in command line its working properly.
Right; so again, you have ignored most of the questions asked:
  • Version/distro of Linux?
  • Version of PHP?
  • Have you checked the PHP and Apache error log files? What do they say?
And your entire script **DOES NOT** put anything on the screen...you've got nothing to actually display something in a web browser, so your code is doing exactly what it should. PHP works the same on any platform, so being new to Linux doesn't matter in this case. Are you also new to PHP??

In order for your script to work through your browser, you'll have to add the Apache user (wwwrun, apache, etc...can't tell you, since you won't tell us what version/distro of Linux you're using), to sudoers or to the wheel group. Which is an **INCREDIBLY BAD IDEA**, since you're going to be allowing a web-facing user root access to your system. Don't do that.

It would be far better to have an external shell-script that takes two command-line arguments, and in that shell script have the sudo command assume an elevated permission status. Set ONE USER up in sudoers to have access to ONLY that shell script, to mitigate any potential damage. Call it like:
PHP Code:
$result shell_exec('/bin/bash /path/to/script.sh param1 param2'); 
Then the $result variable will be whatever the return code/output of that script is. At that point, your PHP code can display it with simple echos
PHP Code:
echo "<pre>$result</pre>"
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
After upgrading php 5.3.8 to php 5.4.30 php files are not being executed kingkashif Linux - Server 5 06-26-2014 10:15 AM
[SOLVED] Am trying to install packages like net-snmp, php-mysql, php-snmp, php but with errors Maj Linux - Newbie 1 07-26-2013 02:12 PM
PHP - Mail.php and Mail/mime.php issues LVsFINEST Linux - Server 1 02-08-2009 05:44 PM
php apache or php cgi - php learner rblampain Linux - Security 3 12-17-2004 11:10 PM
To PHP or not to PHP Jasutinsama Programming 0 01-15-2001 01:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration