Php file not executing

NginX not executing PHP

I’ve been through dozens of potential solutions to this problem but cannot find anything that works. Basically, PHP files are not executing on my NginX + PHP_fpm + Ubuntu 14 server. I have all the packages, and they are running. I’ve cleared browser cache etc., but nothing has worked yet. I appreciate all the help! As of right now, if I try accessing the PHP file, the GET will return it as an HTML file but will not execute the script. Here is my nginx.conf file:

worker_processes 1; worker_rlimit_nofile 8192; events < worker_connections 3000; >error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; http < include /etc/nginx/mime.types; #default_type application/octet-stream; default_type text/html; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; >
## # You should look at the following URL's in order to grasp a solid understanding # of Nginx configuration files in order to fully unleash the power of Nginx. # http://wiki.nginx.org/Pitfalls # http://wiki.nginx.org/QuickStart # http://wiki.nginx.org/Configuration # # Generally, you will want to move this file somewhere, and start with a clean # file but keep this around for reference. Or just disable in sites-enabled. # # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. ## # Default server configuration # server < listen 80 default_server; listen [::]:80 default_server ipv6only=on; # SSL configuration # # listen 443 ssl default_server; # listen [::]:443 ssl default_server; # # Note: You should disable gzip for SSL traffic. # See: https://bugs.debian.org/773332 # # Read up on ssl_ciphers to ensure a secure configuration. # See: https://bugs.debian.org/765782 # # Self signed certs generated by the ssl-cert package # Don't use them in a production server! # # include snippets/snakeoil.conf; root /usr/share/nginx/html; # Add index.php to the list if you are using PHP index index.php index.html index.htm index.nginx-debian.html; server_name localhost; location / < # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; >error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html < root /usr/share/nginx/html; ># pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ < try_files $uri =404; include snippets/fastcgi-php.conf; # With php5-cgi alone: #fastcgi_pass 127.0.0.1:9000; # With php5-fpm: #fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; #fastcgi_index index.php; include fastcgi_params; ># deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht < # deny all; #>> # Virtual Host configuration for example.com # # You can move that to a different file under sites-available/ and symlink that # to sites-enabled/ to enable it. # #server < # listen 80; # listen [::]:80; # # server_name example.com; # # root /var/www/example.com; # index index.html; # # location / < # try_files $uri $uri/ =404; # >#> 

Источник

Читайте также:  Set of classes java

PHP script not executing on Apache server

I have just reinstalled Apache and PHP5 but when I visit my doc root it just downloads a «download» file. And when I try documentroot/index.php it just downloads the PHP file. I have PHP installed but Apache doesn’t seem to want to execute it.
People suggested adding a ‘Load Module’ line to my httpd.conf but I don’t have that file.

7 Answers 7

sudo apt-get install apache2 php5 libapache2-mod-php5 

will install everything you need and will start the apache server with support for PHP.

To verify that the php module is loaded, type:

if not enabled, then load with:

sudo service apache2 restart 

Update for php7.x (tested on Ubuntu 16.04, 16.10, 18.04, 18.10)

Thanks to the comments, I update the answer for php7.x.

sudo apt-get install apache2 php7.x libapache2-mod-php7.x 
sudo service apache2 restart 

It would be better to use a2enmod than to copy the file manually between mods-available and mods-enabled. a2enmod creates a symlink and so you’ll only have one copy of the configuration.

for ubuntu 16.04 with php7 I have executed these commands in order apt-get install libapache2-mod-php , a2query -m php7.0 , service apache2 restart

For ubuntu 14.04 : # a2query -m php7.0 php7.0 (enabled by site administrator) Still php code is not executing

Ubuntu 16.04 has moved to PHP 7. This single command will do the job for you:

sudo apt-get install apache2 php libapache2-mod-php 

Here libapache2-mod-php is a meta-package that installs libapache2-mod-php7.

I ran into the same problem, but my particular problem was unique. I was running in a user directory (using mod_userdir) — meaning you access my webpage with http://host.name.com/~username/example.php

This is disabled by default in php*.conf in my mods-enabled directory. I had to modify it to comment it out:

# # # php_admin_flag engine Off # # 

That was a pain to figure out..

Well, I doubt anybody had THIS particular problem, but I figured I’d add it because it was perplexing as crud to me and MAYBE somebody is doing the same thing. Nobody uses ~/user anymore I guess, except me.

You have to restart apache after this of course.

For people who have found this post from Google almost 6 years in the future (and beyond!), you may run into this problem with Apache 2 and PHP 7 while also using the UserDir module.

Another possible cause of this problem could be that you are trying to run the script in a «user directory» from the the UserDir module. Running PHP scripts in user directories is disabled by default. You will run into this problem if the script is in the public_html directory in your home folder and you are trying to access it from http://localhost/~your_username .

To fix this, open up /etc/apache2/mods-enabled/php7.2.conf . You must comment or delete the tag block at the bottom that reads

  php_admin_flag engine Off  

Источник

PHP Not Executing on Command Line

Hello I have php working fine with my apache server. However, when executing the php script from the command line (like /usr/bin/php file.php ) it just echos the sourcecode of my script back at me, even when executing a PHP in the web directory. Anybody know how to fix this?

are you sure that executable php file exists in usr/bin/php ? Have you tried creating batch file and running your code?

What does Your script file look like? Maybe You need

3 Answers 3

#!/usr/bin/php echo 'hello world!'; 

because There’s no actual PHP code in there. There’s just some text that LOOKS like php code. You need to have

and then you’ll get the expected

In your past questions, you seem to prefer using short open tags (

/usr/bin/php -d short_open_tag=yes file.php 

If this works, then your current config has short_open_tag disabled. You’ll have to edit your CLI config file to change this. You can find the location of the config file using this:

Configuration File (php.ini) Path => /etc/php5/cli Loaded Configuration File => /etc/php5/cli/php.ini 

Edit the file listed by «Loaded Configuration File». The line with:

I have been fighting this issue for over 4 months and finding nothing to fix it.

My problems started when I installed a new 3T drive and then moved all my projects off the default 1.5T drive. Could never get anything working right in «localhost» since. Also cannot get aliases working in the 2 virtual hosts I created, but their index.html files now show fine at:

But none of the following work:

  1. localhost/phpmyadmin,
  2. localhost/seopanel,
  3. localhost/test.php,
  4. localhost/info.php,
  5. php on the command line.
https://www.linuxquestions.org/questions/newreply.php?do=newreply&noquote=1&p=6214546 

and since I get no errors in any of the error logs, can not figure out what is denying localhost and the cmd line from working. Test of:

Both work, so not sure why it is only echoing the file contents as «cat file» would do.

Has to do somehow with it not rendering «localhost»

Источник

How to Fix Apache Not Executing PHP Files

fix apache not executing php

Sometimes Apache web server displays PHP files without actually executing the code in them. In this case, users don’t see the result of executed PHP but the underlying code. It can pose security risks to expose your website’s code to visitors. This is a common problem especially if you are using Apache/PHP for the first time. In this article, we will look at how to fix Apache not executing PHP files.

How to Fix Apache Not Executing PHP Files

Here are the steps to get Apache to execute PHP files.

1. Update Apache configuration file

Open terminal and open Apache configuration file.

$ sudo vi /etc/apache2/apache2.conf

Add the following lines to the bottom of your file.

 SetHandler application/x-httpd-php ​

2. Disable & Enable modules

To get PHP execution working properly, you need to disable and then enable mpm_event_module, and enable mpm_prefork and php7 modules.

$ sudo a2dismod mpm_event && sudo a2enmod mpm_prefork && sudo a2enmod php7.0

3. Restart Apache Server

Restart Apache Server to apply changes.

$ sudo service apache2 restart

That’s it. Now open your browser and go to your website. You should see PHP code being executed properly. Apache is a powerful web server that offers plenty of useful features. Of course, there can be many other reasons for PHP not being executed on your server. We have listed the most common solutions to this problem. If they don’t work for you, then you need to go through your Apache configuration file for errors.

Источник

Оцените статью