How can I change the PHP version used by phpmyadmin? - php

I have phpmyadmin installed on my ubuntu server, that runs several versions of PHP depending on the website used.
The default version is 7.4, but phpmyadmin use 7.2 for unknown reason.
Simple question : where do I change that ?
Cannot find it in any forum or documentation...
I tried to put in phpmyadmin/apache.conf what I use in my virtual hosts sites :
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/"
</FilesMatch>
but it doesn't work and I still have 7.2
Thanks a lot !

Solution found !
As my Phpmyadmin installation doesn't use the virtual host file system, the file to modify is /etc/phpmyadmin/apache.conf
I put a code, but outside the Directory tags, and you have to put it inside to make it work :
<Directory /usr/share/phpmyadmin>
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/"
</FilesMatch>
</Directory>
And then, restart Apache change the PHP version of phpmyadmin page.
Thanks !

Add the below code inside /etc/phpmyadmin/apache.conf
<Directory /usr/share/phpmyadmin>
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php/php8.1-fpm.sock|fcgi://localhost/"
</FilesMatch>
</Directory>
After that restart Apache
sudo systemctl restart apache2

Here's how I do it:
Go to phpMyAdmin config
cd /etc/apache2/sites-available
Open config file
sudo nano phpmyadmin.conf
Put the following line inside the tags to serve 7.4:
include /etc/apache2/conf-available/php7.4-fpm.conf
Restart apache:
sudo systemctl restart apache2
Note that my setup is mostly from this tutorial.

Related

Problem encountered running PHP on localhost [duplicate]

I have recently been trying to install PHP and Apache on my computer. After many hours, they're installed. I have modified the httpd.conf and php.ini files like everyone says. I then created a simple PHP script:
<?php phpinfo(); ?>
But when I try to run it with http://127.0.0.1/phpinfo.php it just shows the source code instead of executing it. I am using Apache 2, PHP 5 and Windows Vista.
EDITED LINES:
PHP.INI:
short_open_tag = On
HTTPD.CONF
LoadModule php5_module "C:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
PHPIniDir "C:/php"
You must enable php! Check the folder mods-enabled in the Apache directory (default: /etc/apache2/) to see if you find a file named php. I don't remember the extension but I think it's .so.
Also check in /var/log/apache2/error.log to see if you have any other errors.
Wow, lots of solutions here! Here's what I did on Ubuntu 16.04:
sudo apt-get install php libapache2-mod-php
sudo a2enmod mpm_prefork && sudo a2enmod php7.0
sudo service apache2 restart
For PHP 7 (May apply to previous versions as well), but I had to do this:
Add this to the bottom of /etc/apache2/apache2.conf
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Run this from the terminal:
sudo a2dismod mpm_event && sudo a2enmod mpm_prefork && sudo a2enmod php7
Then don't forget to restart Apache so it knows you changed stuff:
sudo service apache2 restart
This is a summary from: https://www.atlantic.net/community/howto/try-php7-lamp-ubuntu-14-04/
open the file
/etc/apache2/httpd.conf
and change
#LoadModule php5_module libexec/apache2/libphp5.so
into
LoadModule php5_module libexec/apache2/libphp5.so
So just uncoment the PHP module load in httpd.conf
I found this to solve my related problem. I added it to the relevant <Directory> section:
<IfModule mod_php5.c>
php_admin_flag engine on
</IfModule>
A different answer that worked for me. Is that, to install [sudo] apt-get install libapache2-mod-php5.X
Apache shows php code instead of executing Issue fixed
1. Opened php5.6 conf or php7.x conf
# following command:
$ sudo vi /etc/apache2/mods-enabled/php5.6.conf
2. Commented following lines
3. Restarted the server
$ sudo service apache2 restart
4 Enjoy :)
Thanks to others on this thread for their suggestions. Following the steps mentioned I found that the apache server was not able to start reporting a syntax error in a load file in /etc/apache2/mods-enabled. Turns out that both php7.0 and php7.1 were enabled.
a2dismod php7.0
systemctl restart apache2
and php is rendered correctly again.
Add following configuration to /etc/apache2/apache2.conf
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
And restart the apache via sudo service apache2 restart
Alright if you've tried what you've been told above or earlier(which are possible reasons) and it still displays the code instead of executing it then there is one thing which you are doing wrong that hasn't been addressed.
The url you used to access your php code; some people try to execute their php code by just dragging the .php file into the web browser. this is wrong practice and could lead to this kind of problem.
if you have saved a file as "test.php" in the C://wamp/www folder then you must access this file this way:
localhost://test.php.
this kind of mistake will arise when you access it this way: localhost://wamp/www/test.php
Hope I helped someone out there. o/
~Daniel
If you are a ubuntu user, after installing apache must run the following command in fresh installation
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
In my case works fine.
Posting what worked for me in case in helps someone down the road, though it is an unusual case.
I had set a handler to force my web host to use a higher version of php than their default. There's was 5.1, but I wanted 5.6 so I had this:
<FilesMatch \.php$>
SetHandler php56-cgi
</FilesMatch>
in my .htaccess file.
When trying to run my site locally, having that in there caused php code to be output to the browser. Removing it solved the problem.
For PHP7 and Apache2.4, this is all you need to do:
sudo vim /etc/httpd/conf/httpd.conf
Go to the very bottom and insert the following (all by itself):
<FilesMatch "\.*">
SetHandler application/x-httpd-php
</FilesMatch>
Then, restart Apache to load the new configuration:
sudo service httpd restart
Apache will now execute all HTTP/S requests with PHP. If all you have are html, css, and php files, then this will work fine for you. If you have other languages running, then you'll need to tailor the file matching to your situation. I've tested this with phpMyAdmin and it works fine.
None of that other stuff all the people are talking about here was necessary for me. When I put the "AddType Application....." thing in the correct spot, Apache just told me that that module was already loaded and skipped it.
More information can be found here: https://httpd.apache.org/docs/2.4/mod/core.html#filesmatch
My install was done as follows:
sudo yum install -y httpd24 php70 mysql56-server php70-mysqlnd
You should also read this, if you haven't: https://httpd.apache.org/docs/current/howto/htaccess.html#when
You could delete your .htaceess file and let the system creates a new (blank or basic) one. It may be that some lines you added are incorrect statements, or something else inside is causing the problem. You can then add line by line from your old .htaccess file to see what caused the problem.
That worked for me. The lines telling machine not to display php extensions were problem in my case (RewriteCond and RewriteRule). My old .htaccess file worked just fine on a shared server, but this issue appeared when I switched to VPS.
This was happening to me also when running $_POST in MAMP. All of my .ini and httpd files were all set up correctly. If you are doing form handling and you have an html document and posting the info to a php formhandler running $POST, make sure that you are running the html file from localhost via your server, and not just locally.
This was a shortcut I did to run html documents, by just clicking the html file in my directory and launching in my web browser, when in reality to check if php is being processed in your form, you must run your html through your servers. A very simple protocol that I overlooked.
Example:
Wrong: file:///Applications/MAMP/htdocs/form/form.html
Right: http://localhost:your port number/form/form.html
Now the php should be processed once you click your submit button
What worked for me:
In active httpd.conf, find
<IfModule mime_module>
...
</IfModule>
It was missing the following
AddType application/x-httpd-php .php
AddHandler application/x-httpd-php .php
After restarting apache, .php files are correctly parsed.
if the module userdir is enabled and your site is in a userdir (~/public_html) you must check /etc/apache2/mods-enabled/php5.conf.
The following part makes it work (on Ubuntu 14.10 utopic):
# 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>
none of the above applied or worked for me... PHP7, Apache Httpd 2.2 on CentOS 6
fact is, I installed (all with yum) php BEFORE Apache... you must do the reverse: always install Apache first, then PHP, and then it works...
Indeed, you are likely missing libphp7.so and libphp7-zts.so in /etc/httpd/modules/
I was able to recover anyhow without UNinstalling PHP. I did add the magic line in /etc/httpd/conf/httpd.conf: AddType application/x-httpd-php .php
And then run: yum install php php-mysql
I tried a number of the solutions above however the fix in our scenario was to install the fpm-module.
We had installed httpd before php which may have had something to do with the issue, but to resolve we installed the following:
yum module install php:7.2
This installed the php-fpm-7.2.11-4.module+el8.1.0+5443+bc1aeb77.x86_64.rpm module which we then enabled by:
systemctl enable --now php-fpm
From that point we left the /etc/httpd/conf.d/php.conf as default and restarted httpd
service httpd restart
Then everything worked.
Hope this helps, took way longer than it should have to figure out.
I had the same problem, caused by the Debian/ Ubuntu default configuration of module suphp. It contained suPHP_Engine off for whole /usr/share, which resulted in the php sources being shown in the browser. Deactivating with a2dismod suphp was the interim solution.
I had the same problem. When I run a php file, the web browser showed me the php code instead of execute it. I had tried many times: uninstall/reinstall the wampserver64, working around the PHP/Apache settings/modules, etc. After 2 days: I realised that when I tried to run the php file within the notepad++ by pressing the default combination "ctrl + alt + shift + R" for chrome. It was trying to execute my php file like: "file///C:/wamp64/www/bla/bla.." in my chrome's address bar. That was my problem. I made the changes according to page Configuring Notepad++ to run php on localhost?. My problem was solved. But after 2 days..
Run Xampp (apache) as administrator. In google chrome type:
localhost/<insert folder name here>/<insert file name>
i.e. if folder you created is "LearnPhp", file is "chapter1.php" then type
localhost/LearnPhp/chapter1.php
I created this folder in the xampp folder in the htdocs folder which gets created when you download xampp.
Debian 9 solution:
touch /etc/apache2/conf-available/php.conf
Add to file next lines:
<IfModule mod_php5.c>
<IfModule mod_mime.c>
AddType application/x-httpd-php .php
</IfModule>
<FilesMatch ".+\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
</IfModule>
<IfModule mod_php.c>
<IfModule mod_mime.c>
AddType application/x-httpd-php .php
</IfModule>
<FilesMatch ".+\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
</IfModule>
Then run:
a2enconf php && service apache2 restart
Some times if you have php version conflicts it happens
To overcome that please follow the below steps
Step 1 : Yum list installed | grep 'php'
if you have multiple versions of php like php 5.6 and php 7.0 this confilict will happens
Step 2 : yum remove **your php version **
Step 3 : Then restart the apapche /etc/init.d/httpd restart or service apache2 restart
This solution worked for me. I purged apache2 and reinstall. It happened after purge and install. If it is the first install, you would not face this problem.
In my case with PHP7.3 Apache2.4 Ubuntu 18.04 I had to execute:
$ a2enmod actions fastcgi alias proxy_fcgi
Do your other sites/subdirectories work? Is it just a single dir that shows this behavior?
Then check for syntax error in your index.php. If you miss the very first character in a PHP-file: the "<" in "<?php", then the browser shows the rest of the file as it would be a text-file.
Example:
?php
phpinfo();
?>
Then the browser shows just "?php phpinfo(); ?>" instead of the output of phpinfo().
Centos 7, PHP 8, Apache 2
I've recently upgraded a centos server to use php 8.
After the upgrade php had stopped working and apache started serving me the php code as text.
Having spent a good while looking for which config setting had not updated I tracked it down to this:
in /etc/httpd/conf.d
<IfModule mod_php7.c>
needed changing to:
<IfModule mod_php.c>
There are other places that you may see the mod_php7 check that could probably be updated to the mod_php variant but this one definitely fixed it for me.
Don't forget to restart the server afterwards.

Apache+PHP - different php versions per VHost

On my local dev maschine (Ubuntu), I have apache2 and different php version to develop different projects, managed over Vhosts.
Is there a way to configure each vhost to use a specific (already installed) PHP version? So for example:
example1.local should use PHP 7.4
example2.local should use PHP 8.0
example3.local should use PHP 8.0
example4.local should use PHP 5.6
Currently, I am always running for example sudo a2enmod php{X} & sudo a2dismod php{Y} & sudo service apache2 restart to switch versions, which is really anoying.
I see you are using Apache. So you can use a .htaccess file and add there
AddHandler application/x-httpd-php74 .php
In this way your vhost uses php version 7.4
or with normal apache configuration
<VirtualHost *:80>
ServerAdmin webmaster#example.com
ServerName example.com
ServerAlias www.example.com
<IfModule mod_fastcgi.c>
AddHandler php74-fcgi .php
</IfModule>
</VirtualHost>

ubuntu 20.04 apache2 - php files downloading

php files do not load in the browser, but are downloaded. I have read through many solutions to this problem on both serverfault.com and stackoverflow. (Many of the posts are several years old with older versions of Apache and php, and some of the config files and their locations have changed.) I've found a common set of solutions to the problem, but none of them have worked for me. The following links contain examples of the suggestions I have tried that didn't solve my problem.
apache2 on ubuntu - php files downloading
Apache shows PHP code instead of executing it
https://serverfault.com/questions/25227/why-is-php-script-downloaded-instead-of-executed
https://serverfault.com/questions/286882/apache-is-not-interpreting-php-files
I installed apache2. If I go to "localhost" in my browser, it serves up the "Apache2 Ubuntu Default Page". I installed php. "php7.4.conf" and "php7.4.load" appears in both /etc/apache2/mods-available and /etc/apache2/mods-enabled. I verify that php is enabled with sudo a2enmod php7.4, which gives
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering conflict php5 for php7.4:
Module php7.4 already enabled
Based off multiple replies in different questions, I have ended up with the following in my /etc/apache2/apache2.conf file (note this is not the entire file):
Include /etc/phpmyadmin/apache.conf
AddType application/x-httpd-php .php
# Use for PHP 7.x:
LoadModule php7_module modules/libphp7.4.so
AddHandler php7-script php
AddType application/x-httpd-php-source .phps
AddHandler application/x-httpd-php .phps
AddHandler application/x-httpd-php .php
AddType application/x-httpd-php .php
# Add index.php to your DirectoryIndex line:
DirectoryIndex index.html index.php
Notes: I have verified that the apache2.conf file is being executed, by adding a bad line to the file and attempting to restart apache, which resulted in an error. libphp7.4.so is located in /usr/lib/apache2/modules.
And my /etc/apache2/mods-available/php7.4.conf and /etc/apache2/mods-enabled/php7.4.conf files look like this:
<FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".+\.phps$">
SetHandler application/x-httpd-php-source
# # Deny access to raw php sources by default
# # To re-enable it's recommended to enable access to the files
# # only in specific virtual host or directory
# Require all denied
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(ar|p|ps|tml)$">
# Require all denied
</FilesMatch>
# 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>
After every change I have made, I have restarted apache with sudo service apache2 restart. I do a test and still php files are downloaded. I'm using a simple php file called verify.php, which contains the following:
<?php
phpinfo();
?>
I've never worked with these things before so I could be missing something obvious? For some additional context, I'm working on a school project where I plan to use a php page to query a database and generate a table with the results.
In my case of similar hardship:
I do not need those statements in apache2.conf:List item
I have similar content in my /etc/apache2/mods-available/php7.4.conf and /etc/apache2/mods-enabled/php7.4.conf
I ran:
sudo a2dismod mpm_event && sudo a2enmod mpm_prefork && sudo a2enmod php7.4
However what got me to work is a misspelled 'php' as 'phd' (in SetHandler application/x-httpd-php of etc/apache2.conf):
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
I think that is the only needed command to call PHP as handler.
p.s. I have more than one instance of messed up config files.. i haven't found a good control template for all those linux configuration process. (this time the install was started by somebody, i took over the second part)
(This section contains notes and hints specific to Apache 2.x installs of PHP on Unix systems.
https://www.php.net/manual/en/install.unix.apache2.php)

PHP not showing text [duplicate]

I have recently been trying to install PHP and Apache on my computer. After many hours, they're installed. I have modified the httpd.conf and php.ini files like everyone says. I then created a simple PHP script:
<?php phpinfo(); ?>
But when I try to run it with http://127.0.0.1/phpinfo.php it just shows the source code instead of executing it. I am using Apache 2, PHP 5 and Windows Vista.
EDITED LINES:
PHP.INI:
short_open_tag = On
HTTPD.CONF
LoadModule php5_module "C:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
PHPIniDir "C:/php"
You must enable php! Check the folder mods-enabled in the Apache directory (default: /etc/apache2/) to see if you find a file named php. I don't remember the extension but I think it's .so.
Also check in /var/log/apache2/error.log to see if you have any other errors.
Wow, lots of solutions here! Here's what I did on Ubuntu 16.04:
sudo apt-get install php libapache2-mod-php
sudo a2enmod mpm_prefork && sudo a2enmod php7.0
sudo service apache2 restart
For PHP 7 (May apply to previous versions as well), but I had to do this:
Add this to the bottom of /etc/apache2/apache2.conf
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Run this from the terminal:
sudo a2dismod mpm_event && sudo a2enmod mpm_prefork && sudo a2enmod php7
Then don't forget to restart Apache so it knows you changed stuff:
sudo service apache2 restart
This is a summary from: https://www.atlantic.net/community/howto/try-php7-lamp-ubuntu-14-04/
open the file
/etc/apache2/httpd.conf
and change
#LoadModule php5_module libexec/apache2/libphp5.so
into
LoadModule php5_module libexec/apache2/libphp5.so
So just uncoment the PHP module load in httpd.conf
I found this to solve my related problem. I added it to the relevant <Directory> section:
<IfModule mod_php5.c>
php_admin_flag engine on
</IfModule>
A different answer that worked for me. Is that, to install [sudo] apt-get install libapache2-mod-php5.X
Apache shows php code instead of executing Issue fixed
1. Opened php5.6 conf or php7.x conf
# following command:
$ sudo vi /etc/apache2/mods-enabled/php5.6.conf
2. Commented following lines
3. Restarted the server
$ sudo service apache2 restart
4 Enjoy :)
Thanks to others on this thread for their suggestions. Following the steps mentioned I found that the apache server was not able to start reporting a syntax error in a load file in /etc/apache2/mods-enabled. Turns out that both php7.0 and php7.1 were enabled.
a2dismod php7.0
systemctl restart apache2
and php is rendered correctly again.
Add following configuration to /etc/apache2/apache2.conf
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
And restart the apache via sudo service apache2 restart
Alright if you've tried what you've been told above or earlier(which are possible reasons) and it still displays the code instead of executing it then there is one thing which you are doing wrong that hasn't been addressed.
The url you used to access your php code; some people try to execute their php code by just dragging the .php file into the web browser. this is wrong practice and could lead to this kind of problem.
if you have saved a file as "test.php" in the C://wamp/www folder then you must access this file this way:
localhost://test.php.
this kind of mistake will arise when you access it this way: localhost://wamp/www/test.php
Hope I helped someone out there. o/
~Daniel
If you are a ubuntu user, after installing apache must run the following command in fresh installation
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
In my case works fine.
Posting what worked for me in case in helps someone down the road, though it is an unusual case.
I had set a handler to force my web host to use a higher version of php than their default. There's was 5.1, but I wanted 5.6 so I had this:
<FilesMatch \.php$>
SetHandler php56-cgi
</FilesMatch>
in my .htaccess file.
When trying to run my site locally, having that in there caused php code to be output to the browser. Removing it solved the problem.
For PHP7 and Apache2.4, this is all you need to do:
sudo vim /etc/httpd/conf/httpd.conf
Go to the very bottom and insert the following (all by itself):
<FilesMatch "\.*">
SetHandler application/x-httpd-php
</FilesMatch>
Then, restart Apache to load the new configuration:
sudo service httpd restart
Apache will now execute all HTTP/S requests with PHP. If all you have are html, css, and php files, then this will work fine for you. If you have other languages running, then you'll need to tailor the file matching to your situation. I've tested this with phpMyAdmin and it works fine.
None of that other stuff all the people are talking about here was necessary for me. When I put the "AddType Application....." thing in the correct spot, Apache just told me that that module was already loaded and skipped it.
More information can be found here: https://httpd.apache.org/docs/2.4/mod/core.html#filesmatch
My install was done as follows:
sudo yum install -y httpd24 php70 mysql56-server php70-mysqlnd
You should also read this, if you haven't: https://httpd.apache.org/docs/current/howto/htaccess.html#when
You could delete your .htaceess file and let the system creates a new (blank or basic) one. It may be that some lines you added are incorrect statements, or something else inside is causing the problem. You can then add line by line from your old .htaccess file to see what caused the problem.
That worked for me. The lines telling machine not to display php extensions were problem in my case (RewriteCond and RewriteRule). My old .htaccess file worked just fine on a shared server, but this issue appeared when I switched to VPS.
This was happening to me also when running $_POST in MAMP. All of my .ini and httpd files were all set up correctly. If you are doing form handling and you have an html document and posting the info to a php formhandler running $POST, make sure that you are running the html file from localhost via your server, and not just locally.
This was a shortcut I did to run html documents, by just clicking the html file in my directory and launching in my web browser, when in reality to check if php is being processed in your form, you must run your html through your servers. A very simple protocol that I overlooked.
Example:
Wrong: file:///Applications/MAMP/htdocs/form/form.html
Right: http://localhost:your port number/form/form.html
Now the php should be processed once you click your submit button
What worked for me:
In active httpd.conf, find
<IfModule mime_module>
...
</IfModule>
It was missing the following
AddType application/x-httpd-php .php
AddHandler application/x-httpd-php .php
After restarting apache, .php files are correctly parsed.
if the module userdir is enabled and your site is in a userdir (~/public_html) you must check /etc/apache2/mods-enabled/php5.conf.
The following part makes it work (on Ubuntu 14.10 utopic):
# 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>
none of the above applied or worked for me... PHP7, Apache Httpd 2.2 on CentOS 6
fact is, I installed (all with yum) php BEFORE Apache... you must do the reverse: always install Apache first, then PHP, and then it works...
Indeed, you are likely missing libphp7.so and libphp7-zts.so in /etc/httpd/modules/
I was able to recover anyhow without UNinstalling PHP. I did add the magic line in /etc/httpd/conf/httpd.conf: AddType application/x-httpd-php .php
And then run: yum install php php-mysql
I tried a number of the solutions above however the fix in our scenario was to install the fpm-module.
We had installed httpd before php which may have had something to do with the issue, but to resolve we installed the following:
yum module install php:7.2
This installed the php-fpm-7.2.11-4.module+el8.1.0+5443+bc1aeb77.x86_64.rpm module which we then enabled by:
systemctl enable --now php-fpm
From that point we left the /etc/httpd/conf.d/php.conf as default and restarted httpd
service httpd restart
Then everything worked.
Hope this helps, took way longer than it should have to figure out.
I had the same problem, caused by the Debian/ Ubuntu default configuration of module suphp. It contained suPHP_Engine off for whole /usr/share, which resulted in the php sources being shown in the browser. Deactivating with a2dismod suphp was the interim solution.
I had the same problem. When I run a php file, the web browser showed me the php code instead of execute it. I had tried many times: uninstall/reinstall the wampserver64, working around the PHP/Apache settings/modules, etc. After 2 days: I realised that when I tried to run the php file within the notepad++ by pressing the default combination "ctrl + alt + shift + R" for chrome. It was trying to execute my php file like: "file///C:/wamp64/www/bla/bla.." in my chrome's address bar. That was my problem. I made the changes according to page Configuring Notepad++ to run php on localhost?. My problem was solved. But after 2 days..
Run Xampp (apache) as administrator. In google chrome type:
localhost/<insert folder name here>/<insert file name>
i.e. if folder you created is "LearnPhp", file is "chapter1.php" then type
localhost/LearnPhp/chapter1.php
I created this folder in the xampp folder in the htdocs folder which gets created when you download xampp.
Debian 9 solution:
touch /etc/apache2/conf-available/php.conf
Add to file next lines:
<IfModule mod_php5.c>
<IfModule mod_mime.c>
AddType application/x-httpd-php .php
</IfModule>
<FilesMatch ".+\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
</IfModule>
<IfModule mod_php.c>
<IfModule mod_mime.c>
AddType application/x-httpd-php .php
</IfModule>
<FilesMatch ".+\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
</IfModule>
Then run:
a2enconf php && service apache2 restart
Some times if you have php version conflicts it happens
To overcome that please follow the below steps
Step 1 : Yum list installed | grep 'php'
if you have multiple versions of php like php 5.6 and php 7.0 this confilict will happens
Step 2 : yum remove **your php version **
Step 3 : Then restart the apapche /etc/init.d/httpd restart or service apache2 restart
This solution worked for me. I purged apache2 and reinstall. It happened after purge and install. If it is the first install, you would not face this problem.
In my case with PHP7.3 Apache2.4 Ubuntu 18.04 I had to execute:
$ a2enmod actions fastcgi alias proxy_fcgi
Do your other sites/subdirectories work? Is it just a single dir that shows this behavior?
Then check for syntax error in your index.php. If you miss the very first character in a PHP-file: the "<" in "<?php", then the browser shows the rest of the file as it would be a text-file.
Example:
?php
phpinfo();
?>
Then the browser shows just "?php phpinfo(); ?>" instead of the output of phpinfo().
Centos 7, PHP 8, Apache 2
I've recently upgraded a centos server to use php 8.
After the upgrade php had stopped working and apache started serving me the php code as text.
Having spent a good while looking for which config setting had not updated I tracked it down to this:
in /etc/httpd/conf.d
<IfModule mod_php7.c>
needed changing to:
<IfModule mod_php.c>
There are other places that you may see the mod_php7 check that could probably be updated to the mod_php variant but this one definitely fixed it for me.
Don't forget to restart the server afterwards.

Problem with debugging PHP with Eclipse and xdebug

Can you help me with the following problem? I have Eclipse Helios configured with xdebug under Ubuntu. When I start to debug a given page everything seems fine, I can attach to the break point I want, but the problem comes when I tray to step over/into, Firefox (my default browser for debugging) prompt me to "save as" the php page.
Have you checked to ensure that PHP, Apache and MySQL are running?
If they aren't running then you will not be able to run a PHP script.
I think the command in ubuntu (if not running on LAMPP) is "sudo apachectl start" to start apache/php
Then you can put your scripts in /var/www/html/
If you are running LAMPP (http://www.apachefriends.org/en/xampp-linux.html) then you can probably "sudo /opt/lampp/lampp start" to boot everything up.
Then install your scripts to /opt/lampp/htdocs/
After you've done all of that, you should be able to run it.
I assume you're using Apache as your webserver. If so, it seems that Apache doesn't know how to handle *.php files.
Have you added:
# Required modules: dir_module, php5_module
<IfModule dir_module>
<IfModule php5_module>
DirectoryIndex index.php index.html
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
</IfModule>
</IfModule>
to your apache configuration file? This should do the trick.

Categories