Php not running error

Why is my php script not running on boot? Running from command line works fine

I have placed the following information into my crontab file by entering «crontab -e» (in both root and «ubuntu» users, on a 32 bit Canonical Ubuntu AWS instance):

@reboot /usr/bin/php /usr/share/nginx/www/cron/updateIp.php 
@reboot /usr/bin/php /usr/share/nginx/www/cron/updateIp.php >> /home/ubuntu/crontab.log 

And /home/ubuntu/crontab.log contains nothing after two reboots. I imagine that php and/or nginx is not loaded when this cronjob is attempting to run? Without any error logs to check however, I am at a loss as to what to do next. EDIT: Even after logging into the box via SSH with the same user that the crontab -e was created under. the cronjob does not run. EDIT 2: (results of syslog):

Nov 9 13:29:02 ip-10-122-254-128 CRON[603]: (root) CMD (php /usr/share/nginx/www/cron/updateIp.php) Nov 9 13:29:02 ip-10-122-254-128 CRON[604]: (ubuntu) CMD (/usr/bin/php /usr/share/nginx/www/cron/updateIp.php >> /home/ubuntu/crontab.log 2>&1) 

EDIT 3: This link actually provided the answer I was looking for. Apparently I needed to install php-cgi and mention it specifically, even though whereis php does not show it? Simply installing php5-cgi and changing /usr/bin/php to /usr/bin/php-cgi worked like a charm. I already had php5-cli and php5-fpm installed so I figured php5-cgi wasn’t necessary, but I suppose it must have been.

Источник

PHP code is not being executed, but the code shows in the browser source code

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.

Читайте также:  Java if else лямбда

The print

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.

Don’t EVER use short tags. (

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 (

36 Answers 36

Sounds like there is something wrong with your configuration, here are a few things you can check:

  1. Make sure that PHP is installed and running correctly. This may sound silly, but you never know. An easy way to check is to run php -v from a command line and see if returns version information or any errors.
  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 Apache’s httpd.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, or whichever extension specified in the MIME definition in point #3, otherwise it will not be executed as PHP.
  5. Make sure you are not using short tags in the PHP file ( not enabled on all servers by default and their use is discouraged. Use
  6. Make sure you are accessing your file over your webserver using an URL like http://localhost/file.php not via local file access file://localhost/www/file.php

Don’t know why, but installer of PHP 5.3.15 doesn’t add the line AddType application/x-httpd-php .php . Thanks a lot!!

@shmeeps: Where have you seen that short tags are deprecated? I’ve done some searching and can only find recommendations against them, nothing about deprecation. Granted for applications which are to be distributed it is better to use

point 2 worked for me the safe way — apt-get purge apache2; apt-get install apache2 libapache-mod-php5

@full_prog_full Try uploading a file with a .php extension with the contents and see if accessing the file through a web browser results in «Success» being displayed without the associated PHP code.

sudo a2enmod proxy_fcgi setenvif sudo a2enconf php7.0-fpm sudo service apache2 restart 

While this code snippet may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post. Remember that you are answering the question for readers in the future, not just the person asking now! Please edit your answer to add explanation, and give an indication of what limitations and assumptions apply.

@RaymondNijland true but this is canonical and I found this question and it saved me after over an hour of troubleshooting.

How and Why: This happens when PHP7 doesn’t configure the default fast-CGI service in the make script. sudo a2enmod proxy_fcgi setenvif creates three new mods /mods-available/proxy.conf proxy_fcgi.load proxy.load Likewise, sudo a2enconf php7.0-fpm creates a config file /conf-available/php7.0-fpm.conf Once this is done and Apache2 can then run the PHP7 module as a fast-CGI service.

I’m running Apache on Ubuntu and my issue was that the /etc/apache2/mods-available/php5.conf file was missing this:

 SetHandler application/x-httpd-php 

I added it back in and php was parsing php files correctly.

note for php 7 users, add this to your httpd.conf file:

# PHP 7 specific configuration AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps DirectoryIndex index.html index.php  

Just to help other people with this issue. The httpd.conf file is located in /etc/apache2/httpd.conf If you’re using Ubuntu, it would be apache2.conf in the same directory that needs to be modified for PHP7.

I found another problem causing this issue and already solved it. I accidentally saved my script in UTF-16 encoding. It seems that PHP5 can’t recognize

You’re just opening your php file into browser. You have to open it using localhost url. if you open a file directly from your directory it will not execute the php code in any case.

use: http://locahost/index.php or http:127.0.0.1/index.php

Also use: sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt if you are a ubuntu user.

Why is mcrypt required when i’m just including a file? You should noticed that this question is old and the short tags issue was mentioned 16 times, also in the top comment of my question.

I just share my solution, I was also facing the same error and after executing this command of mcrypt my issue solved. you may also try.

This was my problem, my virtualmin/apache configuration was for 127.0.0.2 but i was putting my external ip address in the browser, i just updated my v/a config and now its working

I’m posting this answer because my Virtualmin/Webmin admin interface decided it was a good idea to disable my PHP engine.. took me a while to find the solution, so I thought I’d share it with you guys:

Also, be sure to check that none of your website config files related to this specific host or virtualhost have any php_admin_value’s in them that turn off PHP, like this:

php_admin_value engine Off 
# php_admin_value engine Off 

And restart your webserver.

@cronoklee In vHost settings of httpd.conf. For existing hosts, you need to edit apache config in webmin. For future hosts, go to virtualmin > server template > apache website. Eitherway, this is not as secure as fastcgi — virtualmin’s default. So the correct approach should be to troubleshoot why fcgi doesn’t work, for example it may be caused by file permissions.

If you’re using a version of Apache that doesn’t have httpd.conf, look in /etc/apache2/mods-enabled/php7.conf or php5.conf

When in doubt about the location of a certain configuration setting, you can always use grep to find what you’re looking for by (for example in this case) typing: sudo grep php_admin_value /etc/* -R

This just happened to me again, along with the server downloading html files, rather than processing. I had not use the webserver apache for some time on the computer and meanwhile Ubuntu updated like two more versions from originally installed LTS. Now it is

$ cat /etc/issue Ubuntu 16.04 LTS 

So the php worked after like so:

$ sudo apt-get install lamp-server^ $ sudo a2enmod php7.0 $ sudo service apache2 restart 

The webserver was now parsing the php. Maybe now got to update some webs since php7.0 now running where as it was before running php5. Oh well.

I know it should sound silly. but seldom it happens.

Check if you are trying to execute php from

ps> you can notice that if you write from shell

it answer with the code (it means php functions)..

PHP works fine (checked using command line). but, when I access the file using URL, it shows PHP code.

I’ve solved this by uninstalling XAMPP, and installing WAMP. Thanks for the help.

In case we are in the same page do following

sudo apt-get install php -y sudo apt-get install php- -y

To enable PHP 7.2 FPM in Apache2 do:

a2enmod proxy_fcgi setenvif

update 2: Apache downloads .php file instead of rendering

After that, I faced above issue. There are similar questions like this.

I don’t know why but it only happened for my .php files in /var/www/html/ root folder. everything was ok for sub-directories. (for example wordpress and phpmyadmin worked fine)

So here is my solution. I decided to enable php module. so I ran this command:

Considering dependency mpm_prefork for php7.2: Considering conflict mpm_event for mpm_prefork: ERROR: Module mpm_event is enabled — cannot proceed due to conflicts. It needs to be disabled first! Considering conflict mpm_worker for mpm_prefork: ERROR: Could not enable dependency mpm_prefork for php7.2, aborting

so I decided to disable mpm by running following commands:

sudo a2dismod mpm_prefork sudo a2dismod mpm_worker sudo a2dismod mpm_event 

systemctl restart apache2

then enable php7.2 (my installed version):

and right now everything works fine.

Источник

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