429

I'm trying to execute some PHP code on a project (using Dreamweaver) but the code isn't being run.

When I check the source code, the PHP code appears as HTML tags (I can see it in the source code). Apache is running properly (I'm working with XAMPP), the PHP pages are being opened properly but the PHP code isn't being executed.

Does someone have a suggestion about what is happening?

Note: The file is already named as filename.php

Edit: The Code..:

<?
include_once("/code/configs.php");
?>

The print

5
  • 61
    Are you using short tags <? instead of <?php? Commented Feb 25, 2011 at 19:09
  • Do you get any results from phpinfo?(See example 1, php.net/manual/en/function.phpinfo.php) If you don't, you probably need to reconfigure apache. Commented Feb 25, 2011 at 19:12
  • 44
    Don't EVER use short tags. ( <? ). They are deprecated, don't really work in a lot of places, and are otherwise completely unneccessary. Saving three keystrokes is not a valid reason to allow potential for your code to fail on probably half of the servers it may run on. Commented Feb 11, 2015 at 19:53
  • 8
    I am aware that short tags are not short echo tags, which is why I specified which I was talking about in the comment. At the time of writing, short tags were flagged for deprecation for the php 6 release, though that has apparently changed since. The problem still exists that a lot of servers have them disabled, which makes your code significantly less portable. This does not apply to short echo tags (<?=), which should run fine on php 5.4+ regardless of server settings. Commented Mar 18, 2016 at 0:44
  • Also taking a look at tail -f -n 50 /var/log/apache2/error.log helped me find the issue. Commented Sep 7, 2020 at 9:28

37 Answers 37

1
2
0

After trying everything above and nothing works, consider restarting your pc. Solved mine.

Sign up to request clarification or add additional context in comments.

Comments

0

It is possible to install phpmyadmin on raspberry 64 bit and it even was not difficult in my case.
I am running several hp-laptops with openSuse Tumbleweed and some Raspberries.
On the latest Raspberry 3 B + I 64bit raspbian buster light, kde plasma Desktop.
Linux raspi10 5.10.60-v8+ #1449 SMP PREEMPT Wed Aug 25 15:01:33 BST 2021 aarch64 GNU/Linux
I am using nginx 1.14.2 with fastcgi (not using 'sock') and php 8.0.10 (php-fpm).
I downloaded 'composer' first. (Use apt or aptitude for that). After that go to https://docs.phpmyadmin.net/en/latest/setup.html
Look for the shell command

composer create-project phpmyadmin/phpmyadmin

It will install a complete directory 'phpmyadmin' in the current directory.
Move that to /var/lib/ and set the user:group permissions according to your settings in nginx.conf
In my case:
chown -R www-data:www-data /var/lib/phpmyadmin

Create a symlink to /srv/www/public or /var/www/html or wherever your server is looking for stuff.
You can add a second symlink named phpMyAdmin to phpmyadmin
Make sure that the root instruction in nginx.conf is set accordingly.

My nginx configuration is (nearly) identical on all my machines. It is very compact right now.
To get started this is the easiest way. All further servers and features can be added later.
No entry in /etc/nginx/sites-enabled and nothing in /etc/nginx/vhosts.d
Start with just one pool in php.ini. To configure that, google a litlle and test by checking the status of php-fpm.

Comments

0

PHP 8, Centos 7, Apache 2, Remi Repo

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.

Comments

0

This right here solved my problem (php 8.1, ubuntu 22.04.2):

sudo apt-get install apache2 php8.1 php8.1-cli libapache2-mod-php8.1 -y
sudo systemctl restart apache2
sudo systemctl enable apache2

To verify that everything works correctly please navigate to your webroot (most likely /var/www/html), delete the index.html and create a new index.php. Once these steps are done write the following into the new index.php:

<?php

phpinfo();

?>

Now go to your browser, enter your server's ip/domain and if you see some page that displays various information about your php installation you are ready to go!

Comments

-1

After trying everything I came up to this solution


This error appears when the PHP 7.0 FPM is not enabled by default.

To enable PHP 7.0 FPM in Apache2, run:

 sudo 2enmod proxy_fcgi setenvif
 sudo a2enconf php7.0-fpm
 systemctl restart apache2

If you have php7.4, enter 7.4 instead of 7.0 in the above commands.

Comments

-1

Today, PHP comes with a built in web server, so no further installation should be needed, therefore one of the easiest way to render a PHP file for development usage would be:

  1. Open a terminal and change to the source directory which contains your web app (its main file is usually called index.php).
  2. Inside this directory, type php -S localhost:7777 (the port number is chosen arbitrary).
  3. Open a web browser an type in localhost:7777 in the address bar and the desired web page should be rendered.

If you have finished your visit, return to your terminal and press CTRL-C to shut down the development server.

This information is also given by invoking php --help in the terminal, further stuff is given at https://www.php.net/manual/en/features.commandline.webserver.php

Comments

-2
sudo apt-get install apache2 php7.x libapache2-mod-php7.x
a2query -m php7.x
sudo a2enmod php7.x
sudo service apache2 restart

x- your php7 subversion

2 Comments

php7 is discontinued
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
1
2

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.