WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Apache can't execute index.php automatically  (Read 9089 times)

Offline Adam

  • Full Member
  • ***
  • Posts: 121
Apache can't execute index.php automatically
« on: April 05, 2017, 09:35:04 AM »
Hi all,

I've Apache & PHP installed on TCL. By default, there is index.html in /usr/local/apache2/htdocs. I've removed that file and replaced it with index.php. Code as below.
However, it seems like the Apache unable to process index.php automatically as seen in the screenshot below. Please advise.

Quote
tc@box:~$ df -h | grep apache
/dev/loop22             944.0K    944.0K         0 100% /tmp/tcloop/apache2
/dev/loop23               3.3M      3.3M         0 100% /tmp/tcloop/apache2-mod-php5
tc@box:~$

tc@box:~$ cd /usr/local/apache2/htdocs
tc@box:/usr/local/apache2/htdocs$ ls -lh
total 4
lrwxrwxrwx    1 root     root          55 Apr  5 13:24 index.html -> /tmp/tcloop/apache2/usr/local/apache2/htdocs/index.html
-rw-r--r--    1 tc       staff         20 Apr  4 18:27 index.php
tc@box:/usr/local/apache2/htdocs$ rm -f index.html
tc@box:/usr/local/apache2/htdocs$ ls -lh
total 4
-rw-r--r--    1 tc       staff         20 Apr  4 18:27 index.php
tc@box:/usr/local/apache2/htdocs$
tc@box:/usr/local/apache2/htdocs$ lynx localhost
                                                                                                                                                         Index of /
                                                                             Index of /

     * index.php


tc@box:/usr/local/apache2/htdocs$ cat index.php
<?php
phpinfo();
?>
tc@box:/usr/local/apache2/htdocs$

This is another test
Quote
tc@box:/usr/local/apache2/htdocs$ cat index.html
<html>
<body>
This is HTML!
</body>
</html>
tc@box:/usr/local/apache2/htdocs$ cat index.php
<?php
echo 'This is PHP!';
?>
tc@box:/usr/local/apache2/htdocs$

index.php file is executed instead of index.php
Quote
tc@box:/usr/local/apache2/htdocs$ lynx localhost

   This is HTML!

I'm able to execute index.php manually
Quote
tc@box:/usr/local/apache2/htdocs$ lynx localhost/index.php

   This is PHP!

However, Apache still can't process index.php even though index.html has been removed.
Quote
tc@box:/usr/local/apache2/htdocs$ ls -lh
total 8
-rw-r--r--    1 tc       staff         44 Apr  5 13:54 index.html
-rw-r--r--    1 tc       staff         30 Apr  5 13:57 index.php
tc@box:/usr/local/apache2/htdocs$ rm -f index.html
tc@box:/usr/local/apache2/htdocs$ ls -lh
total 4
-rw-r--r--    1 tc       staff         30 Apr  5 13:57 index.php
tc@box:/usr/local/apache2/htdocs$ lynx localhost
                                                                                                                                                         Index of /
                                                                             Index of /

     * index.php
« Last Edit: April 05, 2017, 09:59:59 AM by Adam »

Offline polikuo

  • Hero Member
  • *****
  • Posts: 723
Re: Apache can't execute index.php automatically
« Reply #1 on: April 05, 2017, 09:59:11 AM »
Hi Adam
The php executable is in php5.tcz
Did you load it ?

Offline Adam

  • Full Member
  • ***
  • Posts: 121
Re: Apache can't execute index.php automatically
« Reply #2 on: April 05, 2017, 10:08:34 AM »
Hi Adam
The php executable is in php5.tcz
Did you load it ?

I've apache2-mod-php5.tcz installed. I thought this apache comes with php?
Quote
Title:          apache2-mod-php5.tcz
Description:    php5 - Apache 2 module and extensions
Version:        5.4.3
Author:         Various
Original-site:  http://www.php.net
Copying-policy: GPL (see /usr/local/share/doc/License/apache2-mod-php5.txt)
Size:           3.4M
Extension_by:   gutmensch
Tags:           apache php module version 5
Comments:       For use with apache2.tcz extension. This extension does not depend on php5.tcz, nor are they related.
                Usage: Install and restart your Apache Web Server. If your httpd.conf is not
                in the default location, you have to add "Include conf/php5/mod_php5.conf" manually
                to your conf.
                Suhosin extension by Stefan Esser is included.
                Edit /usr/local/apache2/conf/php5/php.ini to your needs and add to backup.
                Do the same with the extension configuration files in /usr/local/apache2/conf/php5/extensions/.
                IMPORTANT: For some of the included extensions you need special additional libraries,
                please take a look into dist.ini.
                ---
                This extension is PPI compatible.
Change-log:     2010/05/30      Initial version 5.3.2
                2010/07/02      Corrected mysql flags to use mysqlnd, removed kerberos flag because it is only for imap
                2010/07/02-1    Added postgresql support
                2010/07/02-2    Added enchant support
                2010/08/20      Bump to 5.3.3
                2010/09/14      PHP module is automatically added to Apache by mod_php5.conf file.
                2010/09/14-1    Added xsl extension
                2010/10/16      Added bsddb and iodbc support, moved extensions to dist.ini, extracted more extensions
                2010/11/02      Added mbstring
Current:        2012/05/07      Updated to PHP 5.4.3

Offline bkm

  • Jr. Member
  • **
  • Posts: 72
Re: Apache can't execute index.php automatically
« Reply #3 on: April 05, 2017, 10:11:46 AM »
I am having the same issue.

In fact, when I reboot, the default index.html is written back into the htdocs folder every time and it takes priority over the index.php

Even if I delete all of the .html files in the htdocs directory, when opening a browser of the location it simply displays an index of the files there instead of running the index.php

I have installed the php5.tcz to load on boot. Is there something else I need to add to bootlocal.sh to make it available to the apache2-mod-pho5.tcz module? This module is already called out specifically in the httpd.conf file.

BKM
« Last Edit: April 05, 2017, 10:13:59 AM by bkm »

Offline Adam

  • Full Member
  • ***
  • Posts: 121
Re: Apache can't execute index.php automatically
« Reply #4 on: April 05, 2017, 10:15:12 AM »
I am having the same issue.

In fact, when I reboot, the default index.html is written back into the htdocs folder every time and it takes priority over the index.php

Even if I delete all of the .html files in the htdocs directory, when opening a browser of the location it simply displays an index of the files there instead of running the index.php

I have installed the php5.tcz to load on boot. Is there something else I need to add to bootlocal.sh to make it available to the php apache module?

BKM
Exactly!
Quote
tc@box:~$ cat /opt/.filetool.lst
opt
home
/etc/passwd
/etc/shadow
/usr/local/etc/ssh
/etc/sudoers
/etc/resolv.conf
/usr/local/var/lib/slocate/slocate.db
/usr/local/apache2/htdocs
tc@box:~$

I can delete the default index.html file (blue color), but the same file will be created again after reboot. Is it possible to remove this file permanently?
Quote
tc@box:/usr/local/apache2/htdocs$ ls -lh
total 8
lrwxrwxrwx    1 root     root          55 Apr  5 14:01 index.html.bak -> /tmp/tcloop/apache2/usr/local/apache2/htdocs/index.html
-rw-r--r--    1 tc       staff         44 Apr  5 14:04 index.html.test
-rw-r--r--    1 tc       staff         30 Apr  5 13:57 index.php
tc@box:/usr/local/apache2/htdocs$

Offline polikuo

  • Hero Member
  • *****
  • Posts: 723
Re: Apache can't execute index.php automatically
« Reply #5 on: April 05, 2017, 10:17:09 AM »
I've apache2-mod-php5.tcz installed. I thought this apache comes with php?
No, it's not  a part of the dependence.
http://tinycorelinux.net/7.x/x86/tcz/apache2-mod-php5.tcz.tree

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Re: Apache can't execute index.php automatically
« Reply #6 on: April 05, 2017, 10:20:41 AM »
I can't say for sure how the PHP5 extension is organized, but I can say that you need to enable PHP handling in apache by adding something like this to your httpd.conf file:

LoadModule php5_module modules/mod_php5.so (or whatever the php5 module name is)
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

Use this instead for FPM:

<Proxy "fcgi://127.0.0.1:9000/" enablereuse=on max=10>
</Proxy>
<FilesMatch \.php$>
    # Use the standard TCP socket
    SetHandler "proxy:fcgi://127.0.0.1:9000/"
</FilesMatch>

Usually these directives are in a separate include file. I'm using PHP7 on 64-bit so I'm guessing about your configuration. Don't forget to add your apache config files to /opt/.filetool.lst to make them persistent across reboots.




Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11619
Re: Apache can't execute index.php automatically
« Reply #7 on: April 05, 2017, 10:27:29 AM »
Hi Adam
Code: [Select]
tc@box:~$ cat /opt/.filetool.lst
opt
home
/etc/passwd
/etc/shadow
/usr/local/etc/ssh
/etc/sudoers
/etc/resolv.conf
/usr/local/var/lib/slocate/slocate.db
/usr/local/apache2/htdocs
tc@box:~$
You need to remove the leading  /  marks on those last 7 entries.

Offline bkm

  • Jr. Member
  • **
  • Posts: 72
Re: Apache can't execute index.php automatically
« Reply #8 on: April 05, 2017, 10:32:19 AM »
According to the info page of apache2-mod-php5.tcz

" For use with apache2.tcz extension. This extension does not depend on php5.tcz, nor are they related."

Once the apache2-mod-php5.tcz module is installed the appache2 config file is automatically updated with the following include statement:

Include conf/php5/mod_php5.conf

So everything should work. But it doesn't.

Additionally, I also have the usr/local/apache2/htdocs folder called out in my .filetool.lst but on reboot the index.html is added back to the htdocs directory even though it was deleted before the shutdown and forced backup. (and yes, mine is edited correctly without the leading / character)


BKM
« Last Edit: April 05, 2017, 10:34:49 AM by bkm »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11619
Re: Apache can't execute index.php automatically
« Reply #9 on: April 05, 2017, 10:40:18 AM »
Hi bkm
Additionally, I also have the usr/local/apache2/htdocs folder called out in my .filetool.lst but on reboot the index.html is added back to the htdocs directory even though it was deleted before the shutdown and forced backup. (and yes, mine is edited correctly without the leading / character)


BKM
The  index.html  file is being placed there when the Apache extension is loaded. Backup will only restore saved files, it will not
remove files that were not backed up. Add a command in  bootlocal.sh  to remove the unwanted file.

Offline bkm

  • Jr. Member
  • **
  • Posts: 72
Re: Apache can't execute index.php automatically
« Reply #10 on: April 05, 2017, 10:51:09 AM »
Add a command in  bootlocal.sh  to remove the unwanted file.

Done!!

Now all I need is a way to get the index.php to display when the site is accessed by a browser. Right now it displays an index of the contents of htdocs directory.

Not sure what is wrong with the php configuration. Trying to slug through the php.ini file now, but it is over 1800 lines of redundant confusion and so far nothing to indicate it to not be working properly.

BKM
« Last Edit: April 05, 2017, 10:52:51 AM by bkm »

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Re: Apache can't execute index.php automatically
« Reply #11 on: April 05, 2017, 10:55:20 AM »
Try adding this to your httpd.conf:

    <IfModule dir_module>
        DirectoryIndex index.php index.html
    </IfModule>

Offline bkm

  • Jr. Member
  • **
  • Posts: 72
Re: Apache can't execute index.php automatically
« Reply #12 on: April 05, 2017, 11:45:21 AM »
 8) 8) andyj  8) 8)

That did the trick. I would have been reading for months before I ever found that pearl of wisdom.

Anyone else reading this, remember to flush your browser cache before you retry you site  ::)

Thank you!

BKM

Offline Adam

  • Full Member
  • ***
  • Posts: 121
Re: Apache can't execute index.php automatically
« Reply #13 on: April 05, 2017, 02:15:31 PM »
Try adding this to your httpd.conf:

    <IfModule dir_module>
        DirectoryIndex index.php index.html
    </IfModule>

Yeah, that really does the trick. :)
And don't forget to restart the apache service.... of course :)
Many thanks andyj and others for helping. I really appreciate it :)
You guys are the awesome.  8)
Quote
tc@box:/usr/local/apache2/htdocs$ sudo apachectl -k restart
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
tc@box:/usr/local/apache2/htdocs$
tc@box:/usr/local/apache2/htdocs$ l
total 4
-rw-r--r--    1 tc       staff         30 Apr  6 02:06 index.php
tc@box:/usr/local/apache2/htdocs$
tc@box:/usr/local/apache2/htdocs$ cat index.php
<?php
echo 'This is PHP!';
?>
tc@box:/usr/local/apache2/htdocs$

tc@box:/usr/local/apache2/htdocs$ lynx localhost

   This is PHP!


Offline Adam

  • Full Member
  • ***
  • Posts: 121
Re: Apache can't execute index.php automatically
« Reply #14 on: April 05, 2017, 08:38:11 PM »
You need to remove the leading  /  marks on those last 7 entries.
Thanks Rich. May I know why? I still have those leading / marks on /opt/.filetool.lst but I don't have any problems with them.
As example, /etc/shadow file. I can change my password and use the same new password even after I reboot the TCL.