Problem with debugging PHP with Eclipse and xdebug - php

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.

Related

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.

API written in PHP on apache web server return the php code itself [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.

Can't use phpbrew with apache2 on Xubuntu 16.04. Installation of php versions are OK but source code printed and no PHP executed

I've got a problem to use phpbrew with my Xubuntu 16.04 x64 and apache2. I used it on xubuntu 14.04 without problem but now i'm really stuck :/
I will try to explain it with all informations needed.
All went fluently during installation of each version with that command line
phpbrew install 7.0.16 +default +mysql +pdo +apxs2=/usr/bin/apxs2 +mb
When i switch php version it's ok and i see the right version when i do
php -v
but i can see it's changing only CLI version of php
PHP 7.0.16 (cli) (built: Feb 28 2017 17:25:51) ( NTS )
If i take a look in .phpbrew/php i can see a folder for each versions of php i've installed and when i look in /etc/apache2/mods-available/ i've got phpX.X.load pointing the corresponding libphpX.X.XX.so in the folder /usr/lib/apache2/modules/ . All libphpX.X.XX.so are present in the folder.
When i restart apache, i've got no errors.
I precise that i've installed phpbrew with that requirements (https://coderwall.com/p/hguzxa/phpbrew-on-ubuntu-16-04-php7)
So now i'm just trying that simple php line in a index.html file
<?php echo '<h1>Hello, world!</h1>';?>
But it seems apache can't interpret php because it appears like that
Hello, world!';?>
Finally, when i look the file /var/log/apache2/error.log, there is no error info inside.
Thank you in advance if you can help me for that!
Your browser prints for you
Hello, world!';?>
because your Apache server is misconfigured and can't handle PHP scripts. This behavior from browser was confused you, because you're using valid HTML tag inside your string. Just try to print this string
<?php echo 'Hello, world!';?>
and there is nothing in browser window. But, if you open page source code, you will see that your PHP string comes into DOM document as raw value, without processed PHP tags.
For resolving this info just try to add missing config for Apache:
touch /etc/apache2/conf-available/php.conf
Place the next content in this file
<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_php7.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>
Now, you tell Apache with config how it can process PHP scripts.
So, now just run
a2enconf php
systemctl restart apache2.service
You can review Apache running state with
systemctl status apache2.service
Now, don't forget to check that your test script named like something-to-test.php (not html) and run it in you browser.
Enjoy your processed PHP script and happy coding ;)

I need libphp7.so module to configure apache on Centos

I follow the tutorial of this link to use php7 or phpng on my Centos 6.5 with apache.
I can execute php scripts in the console but I would like to be able to run php scripts using the Apache Server.
I need some help because I can't find the libphp7.so module. I don't know if I have to build it or what.
I believe you need to add --with-apxs2 to your configure script. According to the link you provided I do not see that in the configure flags. --with-apxs2 will "Build shared Apache 2.0 Handler module". You may also need to make sure in your apache configuration you have:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
The first time I built php7 it just displayed the source rather than execute it, but adding that caused it to execute the code.
If you want to try it out with Docker I just created a Docker image for PHP7 at https://registry.hub.docker.com/u/silintl/php7/ You can also just view the Dockerfile which includes all the commands used to install and configure it.
In my config file /etc/httpd/conf.modules.d/15-php.conf which is loaded by the parent config file /etc/httpd/conf/httpd.conf I found the following default configuration:
<IfModule !mod_php5.c>
<IfModule prefork.c>
LoadModule php7_module modules/libphp7.so
</IfModule>
</IfModule>
<IfModule !mod_php5.c>
<IfModule !prefork.c>
LoadModule php7_module modules/libphp7-zts.so
</IfModule>
</IfModule>
Using information provided by #JanePage and #PhilipShipley, i change it to this:
LoadModule php7_module modules/libphp7.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
and Apache started working fine.
Thanks Phillip who gaves some clues for this issue, but in my case I've solved my problem this way :
1 - Copy the Library php7.so that you have into apache module directory with this command :
sudo cp /etc/httpd/modules/libphp7.so /opt/bitnami/apache2/modules
2 - Add in your Apache config file following code :
LoadModule php7_module ./modules/libphp7.so
SetHandler application/x-httpd-php
And PHP worked fine after that !

Categories