This question already has answers here:
Apache shows PHP code instead of executing it
(28 answers)
Closed 5 years ago.
i'm new in AWS and Ubuntu
i've facing a issue to execute php file on aws,
i've already install php and apache.
when I access aws it show file is there,but this file in directory
var/www/html/phpinfo.php
But when I delete file from var/www/html/phpinfo.php and past var/www/phpinfo.php no file show aws public IP, but on var/www/html/phpinfo.php it show plain php code
Update
follow these step
in apache2,conf
SetHandler application/x-httpd-php
then using terminal
sudo a2dismod mpm_event && sudo a2enmod mpm_prefork && sudo a2enmod php7
it show following message
considering conflict php5 for php7
module php7.0 already enabled
Enable Modes
etc/apache2/mods-enabled ls
I find these also
php7.0.conf and php7.0.load
By default apache2 point to /var/www/html/
So if you put your file in /var/www/ it's normal that you don't seen the file.
To change this you can edit your apache2.conf file
vi /etc/apache2/apache2.conf
For your second issue (apache2 showing plain php code)
It means that apache2 don't pass the code to your php interpreter.
Make sure that php is enable by checking that these 2 links are in the mod-enable folder in your /etc/apache2
lrwxrwxrwx 1 root root 29 août 3 14:30 php7.0.conf -> ../mods-available/php7.0.conf
lrwxrwxrwx 1 root root 29 août 3 14:30 php7.0.load -> ../mods-available/php7.0.load
if you don't have these links, type the following and try again:
a2enmod php7.0
service apache2 restart
.
Installing Apache and PHP is not enough, you also have to configure Apache properly to handle its mod_php when a file with the ".php" extension is requested.
You can find tons of articles about how to do that here and there on the Web :-) , but here is a good example:
http://symfony.com/doc/current/setup/web_server_configuration.html#apache-with-mod-php-php-cgi
Related
I'm testing file upload between client and server.
But file upload not working because below error.
Unable to move '/tmp/phpxQHW5q' to '/var/www/html/mri_image/test.jpg' in /var/www/html/server_form.php on line 49, referer: http://192.168.1.12/client_form.php
I have searched this problem at stackoverflow.
Most solution is permision problem.
So, tmp and mri_image folder own by apache and changed mod 755.
Then, not working i want to your help
For reference, my os is CentOS 7, php version is 7.3
I had an issue recently with Apache and PHP trying to write to /tmp, but stating that the script failed with an error "No such file or directory"
Centos 7 uses systemd, which has an awesome feature (PrivateTmp) that breaks Apache/PHP access to /tmp folders (particularly in cases where the files need to be shared to other processes/seen by others. This feature works by creating a sort of "virtual" /tmp directory for each process, so a file seen by Apache wouldn't be seen by PHP, etc.
First, copy the httpd.service and php-fpm.service files from /usr/lib/systemd/system/ to /etc/systemd/system using the commands below.
cp /usr/lib/systemd/system/httpd.service /etc/systemd/system/. && cp /usr/lib/systemd/system/php-fpm.service /etc/systemd/system/.
After copying those into place, edit each copy of the files in the new location and change the line with PrivateTmp=true to PrivateTmp=false using vi, or your preferred text editor.
vi /etc/systemd/system/httpd.service
vi /etc/systemd/system/php-fpm.service
After those changes, you need to restart systemd, as well as php-fpm and apache.
Restart systemd:
sudo systemctl daemon-reload
Restart apache:
sudo systemctl restart httpd
Restart php-fpm:
sudo systemctl restart php-fpm
I am using https://github.com/wilmoore/php-version to switch between php versions on my local machine, installed within ~/php/versions. Currently setting up separate VMs with different versions of php installed is not an option.
When I switch php version through the command line using the linked tool, I see it listed as php 7. This also works when using php -v. I have restarted terminal and the machine and it still says php 7.
I have updated composer.json to require php 7.0.2 and greater. Yet when I use phpinfo() in my laravel application, it always states the default PHP Version 5.5.9-1ubuntu4.14.
Where is laravel pointing to the php distribution in my Ubuntu 14.04.3 machine and where can I change this path?
EDIT: I am using Apache. I can see in the phpinfo() output that it is reading the ini file from /etc/php5/apache2/php.ini. I have looked in this file but cannot see where to point to the php distribution.
first make sure that php7.*.conf and php7.*.load files are exist in /etc/apache2/mods-available directory.
then use sudo a2enmod php7.* to enable the mod
use sudo a2dismod php5.* to disable the mod
after running the two commands restart your apache2 server
using sudo systemctl restart apache2
The Apache loads the php5_module library in /etc/apache2/mods-available/php5.load.
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
If you know the loactions of your alternative libraries you can change them in this file.
After editing you need to restart your apache. sudo service apache2 restart or sudo systemctl restart apache2.service
Had the same issue on ubuntu16.
ls -l /etc/apache2/mods-available/php7* ,
showed 2 versions -
/etc/apache2/mods-available/php7.0.conf
/etc/apache2/mods-available/php7.2.conf
Deleted the /etc/apache2/mods-available/php7.0.conf, restarted apache2, and phpinfo() via apache2 showed php7.2
I was upgrading my distro, from kali(wheezy) to sid. But when I was setting up my web server, I reinstalled all over, apache2, php, mysql etc., but I get this error when I access localhost/phpmyadmin: that URL is not showing an index / login page of phpmyadmin, but showing the code. In my /var/www the default is index.html, I renamed it to index.php, and it's ok, page is loaded, I do the same with my other directory in /var/www I added index.php or foo.php and access it, no problem, but when I enter phpmyadmin it's showing code. I tried installing phpminiadmin and adminer, but I get the same error, both are showing the code and not the web page.
Here is my apache2.conf
http://pastebin.com/MLYNQc6S
And here is my spec :
#php -v
PHP 5.5.7-2 (cli) (built: Dec 13 2013 00:25:07)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
# mysql --version
mysql Ver 14.14 Distrib 5.5.33, for debian-linux-gnu (i686) using readline 6.2
# apache2 -v
Server version: Apache/2.4.6 (Debian)
Server built: Aug 12 2013 18:20:23
uname -a
Linux angga.id 3.7-trunk-686-pae #1 SMP Debian 3.7.2-0+kali8 i686 GNU/Linux
and no error found in my /var/log/apache2/*log
I found this Localhost/phpmyadmin/ returns php code but didnt help.
so whats wrong with my server ?
EDIT 1 :
Like #Matt said in first comment. libapache2-mod-php5 is not installed, so I installing it with apt-get from repo.
apt-get install libapache2-mod-php5
but its return an error, like this.
dpkg: error processing libapache2-mod-php5 (--configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
libapache2-mod-php5
E: Sub-process /usr/bin/dpkg returned an error code (1)
I open synaptic and search for libapache2-mod-php5 there are showing two package with that name libapache2-mod-php5filter and libapache2-mod-php5 , I check it all, and install it, success, no error found,
i restart apache2 and go to localhost/phpmyadmin and its work.
thanks for matt.
Try this
sudo apt-get install libapache2-mod-php7.0
This installs the library for apache2 to use php7.0
please check below things, have found for you from some diff links:
1. Make sure that PHP is installed. This sounds silly, but you never
know.
2. Make sure that the PHP module is listed and uncommented inside of your Apache's httpd.conf This should be something like
LoadModule php5_module "c:/php/php5apache2_2.dll" in the file.
Search for LoadModule php, and make sure that there is no comment
(;) in front of it.
3. Make sure that the http.conf file has the PHP MIME type in it. This should be something like AddType application/x-httpd-php
.php. This tells Apache to run .php files as PHP. Search for
AddType, and then make sure there is an entry for PHP, and that
it is uncommented.
4. Make sure your file has the .php extension on it, otherwise it will not be executed as PHP.
5. Make sure you are not using short tags in the PHP file (<?), these are deprecated, and usually disabled. Use <?php instead.
Actually run your file over said webserver using an URL like http://localhost/file.php not via local access
file://localhost/www/file.php
Or check http://php.net/install
thanks
I had the same problem with Debian 10 (buster) and PHP 7.3.19.1 and apache2 version 2.4.38 and phpmyadmin 5.02.
The file usr/share/phpmyadmin/index.php was not interpreted.
After verifying all the manual installation I ran the following commands:
apt-get update
apt-get install libapache2-mod-php7.3
systemctl restart apache2
and finally it worked. The module PHP for apache2 was not available.
sudo apt install php libapache2-mod-php
sudo apt install php7.0-mbstring
sudo a2dismod mpm_event
sudo a2enmod mpm_prefork
service apache2 restart
after that
gedit /etc/apache2/apache2.conf
add the following line
Include /etc/phpmyadmin/apache.conf
service apache2 restart
libapache2-mod-php server-side, HTML-embedded scripting language (Apache 2 module) so we have to add this
In my case this was due to that I installed apache2 after the fact and then proper php mods hadn't been linked and thus activated. What you need to do:
cd /etc/apache2/mods-enabled
sudo ln -s ../mods-available/php7.2.conf
sudo ln -s ../mods-available/php7.2.load
Then you just do a restart of the server by executing the following command:
sudo systemctl restart apache2
If all other PHP pages are working fine, then this is probably not a PHP related issue.
Since only the phpmyadmin login page is showing php code rather than the actual login page, chances are that your symbolic link in your apache web root directory /var/www/html/phpmyadmin is referencing the phpmyadmin index file /usr/share/phpmyadmin/index.php instead of the phpmyadmin directory /usr/share/phpmyadmin.
This is an incorrect symlink:
$ ll /var/www/html
lrwxrwxrwx 1 root root timestamp phpmyadmin -> /usr/share/phpmyadmin/index.php
This is a correct symlink:
$ ll /var/www/html
lrwxrwxrwx 1 root root timestamp phpmyadmin -> /usr/share/phpmyadmin/
If the symlink is incorrect, change it:
$ sudo ln -sfn /usr/share/phpmyadmin /var/www/html/phpmyadmin
(Or instead delete it and recreate it:)
$ sudo unlink /var/www/html/phpmyadmin
$ sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
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>
I've tried to install GD library on PHP5:
sudo apt-get install php5-gd
Next,
sudo service apache2 restart
After that, when trying to run any PHP parsed page, a save dialog appears.
You can see screenshot:
I've tried to run phpinfo.php page, but same issue:
P.S :
$ php -i | grep -i --color gd
gd Output test results:
PHP Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in Unknown on line 0
gd
GD Support => enabled
GD Version => 2.1.0-alpha
gd.jpeg_ignore_warning => 0 => 0
GDMSESSION => ubuntu
_SERVER["GDMSESSION"] => ubuntu
I'm using LAMP server on Linux/Ubuntu 12.04
I had a similar problem in a server deployment not too long ago.
My issue was solved by executing the command:
sudo apt-get install libapache2-mod-php5
Post in the comments below if it doesn't work. Also, reboot your computer after executing this command (so all of the services are restarted), to make things simple.
I had the very same problem as Hamed. I had to add GD library required by the new project. So far apache2 and PHP5.4 were working together without any problems for months on my machine.
During the installation the script was asking to replace the php.ini and I guess that this was the source of the problem.
So after installing GD, Apache didn't understand PHP anymore so I've reinstalled libapace2-mod-php5 and I had again the similar problems. All my virtual sites have gone returning only standard apache message.
The reason for this is that new version of apache is looking for *.conf files in sites-available folder so you need to rename or copy old vhost file to one with that extension, so e.g.
First go the virtual hosts folder
$ cd /etc/apache2/sites-available
Then copy or rename (actually move) existing vhost file. The owner of this file is root so everything must go through the sudo command
$ sudo mv myvhost myvhost.conf
Enable the new vhost file
$ sudo a2ensite myvhost.conf
And finally restart Apache
$ sudo apachectl graceful
And everything is back to normal, I hope this will help someone.