Loading a PHP file in Chrome displays PHP codes - php

The Problem:
Exactly as it says. My phpinfo.php file contains the following:
<?php phpinfo(); ?>
The file itself is located in /var/www/html/info.php.
What I did (prior to the problem):
I erased all installations of PHP, oci8, and what not. I'm not sure if I did a good job - basically, I typed in yum history and then undid every install relating to PHP.
This was so I could have a clean system (supposedly), before trying all the PHP stuff again, without resorting to a reformat - I had Oracle 11g and apache already setup there.
Take note, before this complete wipeout, said file up there was working fine.
To install PHP with oci8, I followed a guide here, with some differences, but I'll list it down, just the same.
yum install php-pear
yum install php-devel
pear download pecl/oci8
tar xvzf oci8-2.0.6.tgz
cd oci8-2.0.6
phpize
./configure --with-oci8=$ORACLE_HOME
make
make install
setsebool -P httpd_execmem 1
Afterwards, I added the following at the very end of /etc/php.ini file:
[OCI8]
extension=oci8.so
Then, I restarted apache via service httpd restart.
And then, I encountered the problem.
The System:
Fedora 19 x86_64
Oracle 11g
Apache 2.4.6
What I tried:
I thought at first it was Konqueror's problem. Fiddling with the View settings sometimes fixed it - most of the time, it did nothing.
So I installed Google Chrome, which displayed the same thing.
At this point I went, what the heck, I just installed php via yum install php. Maybe php-pear or php-devel on its own is not enough to run a php file.
No dice. All I wanted was to start over and install PHP with oci8 from scratch.
It appears PHP itself has a problem, and I'm stuck. A bit of research online says something about the tags, that php can't run <?.... ?>, as opposed to <?php ..... ?>, but as you can see with my phpinfo example, it didn't help much.
Other Information:
I get this from PHP's error log. I'm not sure if it means anything, as I recall seeing something like this back before I nuked my system, but perhaps they can be of some use.
AH01276: Cannot serve directory /var/www/html/: No matching
DirectoryIndex (index.html,index.php) found, and server-generated
directory index forbidden by Options directive
AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
They don't seem to appear in the error log at any predictable frequency - loading up any PHP file or restarting apache are the only two things I've done.

It's not the browser. Probably, you don't have php module activated in your Apache. Look at your httpd.conf, and put the following lines there:
# Load the PHP module:
LoadModule php5_module lib/httpd/modules/libphp5.so
# Tell Apache to feed all *.php files through PHP. If you'd like to
# parse PHP embedded in files with different extensions, comment out
# these lines and see the example below.
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>

Related

Why does phpinfo() in webpage show version 5.6, but php -v from command line shows 7.3?

Have read previous answers and understand that I must have two versions installed, but cannot locate where the 5.6 could be. I changed /etc/bin/php to point to the version 7.3 I installed using brew. I updated the /etc/apache2/httpd.conf to use php#7.3. I restarted the server to be sure it would start apache reading from the httpd.conf. Yet, when I run phpinfo from the webpage, It starts with 5.6 and does not include the http.conf info about the server administrator, yet it says it's using http.conf. For some reason sudo apachectl restart will not work saying that the port is already in use. I removed the /usr/local/php5 link ( renamed it to php5.bak ), so that it would not be used.
What other things should I look at?
When you use php -v command you use php-cli which can be diffrent version.
Also if you have multiple versions installed you may want disable apache module for old one.
sudo a2dismod php5 // disable php5.6
sudo a2enmod php7.3 // enable php7.3
There can be many different things that are causing it but I'm betting on MacOS Apache that's installed with the system. Try killing it from the startup:
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
I have found a "partial" answer. I am running Mac OS X 10.12.6 on a mac-mini as a web server. The location of the configuration file for apache is:
/Library/Server/web/config/apache2/httpd_server_app.conf
Thus all of the /etc/apache2/httpd.conf and other suggestions, while they work fine on many unix and even OS X ( non-server ) where one has used brew to install, they don't work here. I made some changes in the above file and verified that AFTER going to the Server app, selecting WebSites in the services menu, and clicking toggling the ON/OFF button to off, then back to on, the server is restarted. All of the attempts using different apache2ctl restart, etc. do not work.
I am still somewhat puzzled that I don't see the server administrator that I enter showing up in the phpinfo.php display, but some other changes did.
My next quest, and suggestions are welcome, is how to change the http_server_app.conf file so that instead of php5, it will use my php7 that is available from the command line. The attempt to change:
LoadModule php5_module libexec/apache2/libphp5.so
#LoadModule php7_module libexec/apache2/libphp7.so
did not work as libphp7.so could not be located. I'm now looking for it. At one point in the conference file, I find:
<IfModule php5_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>
Will I need to have one like this for php7_module, once I find it and use it above?

Apache mod_lua enabled, PHP class LUA not found

I've, somehow, managed to play with LUA on my local machine (Windows). Now I tried to put that on my dev server (Debian 9 with Apache 2.4.25 with PHP 7.0.27-0+deb9u1 and Lua 5.3.3).
After hours, dozens of errors and thousands of StackOverflow's pages read, I have finally been able to manually compile and build PECL lua-2.0.5 and successfully made apache module.
I used $ a2enmod lua. Now, on phpinfo() I see mod_lua along others Loaded Modules.
I can run lua scripts from cli. No problem here.
I can't use lua from PHP scripts:
Fatal error: Uncaught Error: Class 'Lua' not found in [...]
I can't use lua through Apache as well (through http://domain/path/to.lua), even after editing /etc/apache2/apache2.conf with new lines:
LoadModule lua_module modules/mod_lua.so
<Files "*.lua">
SetHandler lua-script
</Files>
None of the 4 line made any noticeable difference.
Running Lua scripts directly through Apache (from URL) is optional. But I really need to be able to interpret Lua from my PHP scripts. But even with mod_lua displayed in Loaded Modules in phpinfo(), PHP can't find class Lua. Why?
After building the extension it has to be enabled, some install scriptss do it for you.
depending on your OS the php.ini to do it could vary in mine (ubuntu 16) are
/etc/php/7.0/apache2/php.ini
/etc/php/7.0/CLI/php.ini
if it has multiple config options you can/should make a dedicated extensionname.ini under /etc/php/7.0/{CLI|apache2}/conf.d
shortcut from commandline
$ php -dextension=/path/to/extension.so
or
$ phpenmod extensionname
this one can be found as php5enmod for php5
edit: in your case as you noticed the line to add to the .ini is extension=lua.so

PHP, PEAR, and oci8 configuration

I'll make this quick.
I installed Oracle 11g (with appropriate database, users, etc), Apache 2.4.6, and PHP 5.5.4 on a Fedora 19 system.
I wanted to connect PHP to Oracle. What I really wanted to do was to download MDB2_Driver_oci8, which I thought would be easy, but before I can do such a thing, PHP needs to have that plug-in enabled, so here's what I did:
Tried to install oci8 via the following: pecl install oci8
When that didn't exactly work the first few times, I figured out I, for some reason, needed "Development tools" - via yum groupinstall "Development Tools"
Then I figured out later that PHP actually doesn't do oci8 - it's PHP Devel. So, I had to install that too, via yum install php-devel.
And then, I finally got to install oci8. It asked for the Oracle Directory, and that was that. But it said the following:
Configuration option 'php_ini' is not set to php.ini location
You should add 'extensions=oci8.so' to php.ini
First, I did a locate oci8.so - found it in /usr/lib64/php/modules/
Second, I added what it told me to, to the php.ini file.
Third, I checked the usual php_info() test page - no mention of OCI8. Uh-oh.
Fourth, running both php -i and php -m listed oci8 as one of the modules. Weird.
In desperation, I went ahead and downloaded the MDB2_Driver_oci8. Maybe that will fix things. Nope.
When I loaded my PHP Webpage, it returned the following:
Error message: extension oci8 is not compiled into PHP
As well as: MDB2 error: not found
Strange. And then I decided to check the error logs:
PHP Startup - unable to load dynamic library '/usr/lib64/php/modules/oci8.so' - libclntsh.so.11.1: cannot open shared object file: No such file or directory in Unknown on line 0
And now I'm stuck. I tried going into the php.ini, and found that the extension_dir was commented out. I put it back in, which only seemed to break stuff.
Things of note:
I followed this (link) guide on how to configure PHP and install oci8.
./configure --with-oci8 doesn't work. Fedora says no such directory.
As both the webpage files and the actual server reside on the same PC, I did not install the Oracle Client files.
The extension_dir is commented out by default in the php.ini.
This is just one of my problems in a long line of problems concerning the replication of an already existing and working, but dying, setup. It seems whenever I want to solve a problem, I have to do X first. And by doing X, I uncover another problem, which I have to solve by doing Y, which has its own problems, etc, etc.
Any help would be much appreciated. Thanks.
I know this question is a bit old - but I'm writing this here incase others come looking for the solution.
PHP Extensions Directory
To get your PHP extensions directory, run this command
php-config --extension-dir
ORACLE configuration
When you run the config command for oracle, you need to provide it with your Oracle Home directory (this assumes you have installed ORACLE XE):
./configure -with-oci8=shared,$ORACLE_HOME/xe
SELinux policy
You need to adapt your SELinux policy to support what you are trying to achieve. Disabling it completely is not recommended.
On your Fedora system, try running:
which audit2allow
If you receive an error that indicates it cannot find audit2allow then you need to install this package:
yum install policycoreutils-python
Once you have this package, you can pipe your audit log files into audit2allow to have it create your policy file:
grep httpd /var/log/audit/audit.log | audit2allow -m httpd > http.te
This will create the file http.te that is human readable for you to review what the policy additions are that it will make to your SELinux configuration. If you are OK with the modifications, then run these commands (note the capital M in the following command vs. the lowercase m previously)
grep httpd /var/log/audit/audit.log | audit2allow -M httpd
semodule -i httpd.pp
This may take a few seconds to run - you can verify the policy has been installed by running:
semodule -l | grep httpd
You will need to restart httpd so that it can try to load the oci8.so plugin
service httpd restart
HTH
After reading a lot on the internet, I found this page, that indicates I should disable SELinux, and reboot.
That did the trick.

Why is php not running?

I've seen this question answered many times, but most end either unanswered or by telling the asker to put this:
<?php phpinfo() ?>
in a test file. Obviously, if that produced what was expected, I wouldn't be here. Instead, I get a 404 error.
I'm using an ubuntu 12.04 server with Amazon. Apache is installed, php5 is installed, and apache was restarted. I followed the following sequence:
sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get install libapache2-mod-php5
sudo /etc/init.d/apache2 restart
Each one of the first three commands now gives me "apache2 is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded" Obviously, replace apache2 with php5 and libapache2-mod-php5 for the other two.
This is a sure way to tell me it's installed, correct? Well, when I use the command "top", php is not one of the services that are running, which tells me it's not running, correct?
Navigating to the IP address gives me Amazon's "It Works!" page, but navigating to any other page on the server produces a 404 error.
Any help is much appreciated.
Check out the apache config files. For Debian/Ubuntu theyre in /etc/apache2/sites-available/ for RedHat/CentOS/etc they're in /etc/httpd/conf.d/. If you've just installed it, the file in there is probably named default.
Make sure that the config file in there is pointing to the correct folder and then make sure your scripts are located there.
The line you're looking for in those files is DocumentRoot /path/to/directory.
For a blank install, your php files most likely needs to be in /var/www/.
What you'll also need to do is find your php.ini file, probably located at /etc/php5/apache2/php.ini or /etc/php.ini and find the entry for display_errors and switch it to On.
One big gotcha is that PHP is disabled in user home directories by default, so if you are testing from ~/public_html it doesn't work.
Check
/etc/apache2/mods-enabled/php5.conf
# Running PHP scripts in user directories is disabled by default
#
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
#<IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_flag engine Off
# </Directory>
#</IfModule>
Other than that installing in Ubuntu is real easy, as all the stuff you used to have to put in httpd.conf is done automatically.
To answer the original question "Why is php not running?"
The file your browser is asking for must have the .php extension.
If the file has the .html extension, php will not be executed.
Type in browser localhost:80//test5.php[where 80 is your port and test.php is your file name] instead of c://xampp/htdocs/test.php.
When installing Apache and PHP under Ubuntu 14.04, I needed to specifically enable php configs by issuing a2enmod php5-cgi
You need to add the semicolon to the end of all php things like echo, functions, etc.
change <?php phpinfo() ?> to <?php phpinfo(); ?>
If that does not work, use php's function ini_set to show errors: ini_set('display_errors', 1);

How to force php to work in my browser?

I just installed PHP on my computer (Ubuntu). If I create a test.php file with simple code and then run "php test.php", it works fine (I get what I expect).
However, when I open this file (test.php) with my browser (Mozilla) it asks me how to open this file. Not a problem. I click "open with" and then I select "/usr/bin/php" and... nothing happens. Browser does not display anything.
Can anybody help me with that? Why does my browser cannot display a local php-file using a local php server?
You need to install a web server (apache, lighttpd, ngnix etc.) on your machine, then make sure the server is setup to process php files through the php interpreter. After you have done all that, copy the php files to your server web root directory and access them through the browser.
XAMPP is probably the easiest way to get a development environment up and running.
Here is forum article on getting it running on Ubuntu.
Do you have a web server installed also?
This will install a full LAMP stack on Ubuntu.
sudo tasksel install lamp-server
But keep in mind this will launch Apache and MySQL daemons in the background.
To disable when you are not developing:
sudo /etc/init.d/apache stop; sudo /etc/init.d/mysql stop
When you are:
sudo /etc/init.d/apache start; sudo /etc/init.d/mysql start
You can make a macro in your favorite IDE to do this automatically.
Removing it is as easy as:
sudo tasksel remove lamp-server
Vertex
PHP through a browser will only work if you have php running as a webserver module (cgi, fcgi)
If you are on a regular linux distro you can probably apt-get emerge or zypper apache2 and the mod_php module from a repository. If you want to build from source, here is an small howto:
apache2php
If you're on *nix, try
locate httpd.conf
to find the apache configuration file. It should be somewhere like /etc/apache2/httpd.conf.
In the httpd.conf file, you need to do two things. First load the PHP module eg.
LoadModule php5_module libexec/apache2/libphp5.so
Then you also need a PHP file handler eg.
# PHP file handlers.
<IfModule php5_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>
To test it's running OK, start apache with the .conf file as a parameter and load up a .php file that contains:
<?php
phpinfo();
?>
If PHP is running ok under apache, you should see a purple/white/black page listing all the settings currently in use.
See http://php.net/manual/en/configuration.changes.php for details of the myriad settings you can use.
Make sure you restart apache each and every time you change the .conf file!!!!

Categories