# How do I get Apache to work



## max21 (Dec 24, 2016)

I installed Apache and I am trying to open php files.  I can do it with this:

```
10.0.0.1:8080
```
… and it will only open the index.php file in the www-data directory.
But if I want to open up any other .php file I have to do:

```
http://10.0.0.1:8080/ex2.php
```
This is wrong because I have type in the Name of the php file behind this:

```
http://10.0.0.1:8080/
```

How do I make this stick so that when I click on any .php file it will automatically open the web browser with the php web page in it.

Here is what I I'm using out the httpd.conf file.  I don't know what I am missing or typed in the wrong way.

```
ServerRoot "/usr/local"

Listen 10.0.0.1:8080

LoadModule authn_file_module libexec/apache24/mod_authn_file.so
LoadModule authn_core_module libexec/apache24/mod_authn_core.so
LoadModule authz_host_module libexec/apache24/mod_authz_host.so
LoadModule authz_groupfile_module libexec/apache24/mod_authz_groupfile.so
LoadModule authz_user_module libexec/apache24/mod_authz_user.so
LoadModule authz_core_module libexec/apache24/mod_authz_core.so
LoadModule access_compat_module libexec/apache24/mod_access_compat.so
LoadModule auth_basic_module libexec/apache24/mod_auth_basic.so
LoadModule reqtimeout_module libexec/apache24/mod_reqtimeout.so
LoadModule filter_module libexec/apache24/mod_filter.so
LoadModule mime_module libexec/apache24/mod_mime.so
LoadModule log_config_module libexec/apache24/mod_log_config.so
LoadModule env_module libexec/apache24/mod_env.so
LoadModule headers_module libexec/apache24/mod_headers.so
LoadModule setenvif_module libexec/apache24/mod_setenvif.so
LoadModule version_module libexec/apache24/mod_version.so
LoadModule mpm_prefork_module libexec/apache24/mod_mpm_prefork.so
LoadModule unixd_module libexec/apache24/mod_unixd.so
LoadModule status_module libexec/apache24/mod_status.so
LoadModule autoindex_module libexec/apache24/mod_autoindex.so
<IfModule !mpm_prefork_module>
    #LoadModule cgid_module libexec/apache24/mod_cgid.so
#
</IfModule>
# ...........................................................................
<IfModule mpm_prefork_module>
    #LoadModule cgi_module libexec/apache24/mod_cgi.so
</IfModule>
# ###########################################################################  NEXT
# ###########################################################################  GROUP
LoadModule dir_module libexec/apache24/mod_dir.so
LoadModule alias_module libexec/apache24/mod_alias.so

# Third party modules
IncludeOptional etc/apache24/modules.d/[0-9][0-9][0-9]_*.conf

<IfModule unixd_module>

User www
Group www

</IfModule>
# ###########################################################################
# ###########################################################################  MAIN
# 'Main' server configuration
ServerAdmin max21@yahoo.com

ServerName localhost

<Directory />
    AllowOverride none
    Require all denied
</Directory>

# ######################################################################
# ###################################################################### DocumentRoot

DocumentRoot "/usr/local/www/apache24/data"
<Directory "/usr/local/www/apache24/data">

    Options Indexes FollowSymLinks
    AllowOverride None
        Require all granted

</Directory>
# ##################################################################  funny that 10.0.0.1:8080
# ################################################################## work  if php is at the top
# ################################################################## and not if added at bottom.
    DirectoryIndex *.php
    DirectoryIndex index.html
    DirectoryIndex index.htm
</IfModule>
# ####################################################################
# #################################################################### SECURITY
# Prevent .htaccess & .htpasswd files from being viewed by Web clients.
#
<Files ".ht*">
    Require all denied
</Files>
# ####################################################################
# #################################################################### LOG ERROR
ErrorLog "/var/log/httpd-error.log"

# #################################################################### ERROR
# ####################################################################       LOGLEVEL
LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "/var/log/httpd-access.log" common

</IfModule>
# #################################################################### tell clients
# #################################################################### REDIRECT
# ####################################################################       doc moved
<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/usr/local/www/apache24/cgi-bin/"
</IfModule>
# ####################################################################
# #################################################################### CGI
# ####################################################################     ScriptSock
<IfModule cgid_module>
</IfModule>

<Directory "/usr/local/www/apache24/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>
# ################################################################
# ################################################################ MINE extension
# ################################################################       to MIME-type
<IfModule mime_module>
    TypesConfig etc/apache24/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php
</IfModule>
# ################################################################
# ################################################################    MINE_MAGIC
# ################################################################
<IfModule proxy_html_module>
Include etc/apache24/extra/proxy-html.conf
</IfModule>

# ################################################################
# ################################################################    SSL/TLS
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
# .....................................................................
Include etc/apache24/Includes/*.conf
LoadModule php7_module        libexec/apache24/libphp7.so

# ################################################################## at the end
# ################################################################## FilesMatch
# ...................
# ...................
<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>
```

Happy Holidays


----------



## ShelLuser (Dec 24, 2016)

I completely fail to understand your problem here. It's quite normal that you need to specify the name of the PHP file in order to open / execute it. The only reason this isn't required for your index page is because you probably have set a 'DirectoryIndex' variable, which tells Apache which file to open automatically whenever its pointed a certain location.


----------



## max21 (Dec 24, 2016)

Back in the day I took a course in PHP where I learn how to install Apache and PHP under Windows-XP.  I thought it was Apache or a PHP thing, but now that I remember behind your reply:


ShelLuser said:


> I completely fail to understand your problem here. It's quite normal that you need to specify the name of the PHP file in order to open / execute it. The only reason this isn't required for your index page is because you probably have set a 'DirectoryIndex' variable, which tells Apache which file to open automatically whenever its pointed a certain location.


I did not realize that and I study hard.  Now I kind of remember; it did have something to do with the configuration of the web browser  or the Windows registry … Now I find this 

http://stackoverflow.com/questions/6269467/working-with-php-offline


> This won't be much use to you now, but there has been recent talk (and submission of code) of providing a built-in web server into PHP itself.
> See the RFC at https://wiki.php.net/rfc/builtinwebserver
> You could then write your script (e.g. app.php), execute php -S localhost:8000 to start the web server and then see the results in your browser at http://localhost:8000/app.php



The past has return.  Now that’s a walk back down memory lane.  I just forgot how to, and still can’t remember.

I did have PHP and Apache working together under Windows-XP during that course and you could click any .php file, from anywhere on your hard-drive and it will show the complete web-page in your default web browser.

I remember I had one Opera standalone browser configured to keep something like http://Localhost:8080/ even if you don’t open up anything other than the web browser.  So it was sticky.

Whatever, there got to be a way to make it work with FreeBSD mate web browsers thru using *about:config* or *opera:config* to replace the http:// and https:// *www.* part of the string with localhost:8080/ or 10.0.0.1:8080 so that whenever you click a .php file it will open it up as a web-page.  I’m going to play a bit with opera:config and if I get it I’ll post it, but if someone know about this already, please save me the effort.  There are a few other things I need to get done before Christmas morning.

Thanks ShelLuser, you save my sanity and more again


----------



## drhowarddrfine (Dec 24, 2016)

Well, no. You don't need to do anything with your browser and FreeBSD is not an issue here. The problem is your server may not be fully configured. For PHP to work with your server, it needs to know where to find the interpreter to run the PHP code. This apparently is working for the index page but is not set up to run for other directories and that is where the issue lies. By default, Apache will only work with HTML pages and not PHP.


----------



## max21 (Dec 24, 2016)

EDIT: I forgot to post the correct file.  I had posted my info.php result.


----------



## drhowarddrfine (Dec 25, 2016)

As I said, if you are modifying anything in the browser in an attempt to get PHP to work, you're doing it wrong. And whatever it is you just posted, that is not the httpd.conf file where your configuration for Apache should be.


----------



## max21 (Dec 26, 2016)

drhowarddrfine said:


> As I said, if you are modifying anything in the browser in an attempt to get PHP to work, you're doing it wrong. And whatever it is you just posted, that is not the httpd.conf file where your configuration for Apache should be.


Sorry drhowarddrfine, I had posted my info.php results and forgot to post the mail file.  Here is my httpd.conf:

```
Listen 10.0.0.1:8082
LoadModule authn_file_module libexec/apache24/mod_authn_file.so
LoadModule authn_core_module libexec/apache24/mod_authn_core.so
LoadModule authz_host_module libexec/apache24/mod_authz_host.so
LoadModule authz_groupfile_module libexec/apache24/mod_authz_groupfile.so
LoadModule authz_user_module libexec/apache24/mod_authz_user.so
LoadModule authz_core_module libexec/apache24/mod_authz_core.so
LoadModule access_compat_module libexec/apache24/mod_access_compat.so
LoadModule auth_basic_module libexec/apache24/mod_auth_basic.so
LoadModule reqtimeout_module libexec/apache24/mod_reqtimeout.so
LoadModule filter_module libexec/apache24/mod_filter.so
LoadModule mime_module libexec/apache24/mod_mime.so
LoadModule log_config_module libexec/apache24/mod_log_config.so
LoadModule env_module libexec/apache24/mod_env.so
LoadModule headers_module libexec/apache24/mod_headers.so
LoadModule setenvif_module libexec/apache24/mod_setenvif.so
LoadModule version_module libexec/apache24/mod_version.so
LoadModule mpm_prefork_module libexec/apache24/mod_mpm_prefork.so
LoadModule unixd_module libexec/apache24/mod_unixd.so
LoadModule status_module libexec/apache24/mod_status.so
LoadModule autoindex_module libexec/apache24/mod_autoindex.so
<IfModule !mpm_prefork_module>
    #LoadModule cgid_module libexec/apache24/mod_cgid.so
#
</IfModule>
# ...........................................................................
<IfModule mpm_prefork_module>
    #LoadModule cgi_module libexec/apache24/mod_cgi.so
</IfModule>
LoadModule dir_module libexec/apache24/mod_dir.so
LoadModule alias_module libexec/apache24/mod_alias.so
IncludeOptional etc/apache24/modules.d/[0-9][0-9][0-9]_*.conf

<IfModule unixd_module>
User www
Group www

</IfModule>
ServerAdmin max21@yahoo.com
ServerName localhost
<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "/usr/local/www/apache24/data"
<Directory "/usr/local/www/apache24/data">
    AllowOverride None
    Require all granted
</Directory>
<IfModule dir_module>
    DirectoryIndex index.php
    DirectoryIndex index.html
    DirectoryIndex index.htm
</IfModule>
<Files ".ht*">
    Require all denied
</Files>
ErrorLog "/var/log/httpd-error.log"
LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
    CustomLog "/var/log/httpd-access.log" common
</IfModule>
<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/usr/local/www/apache24/cgi-bin/"

</IfModule>
<IfModule cgid_module>
</IfModule>
<Directory "/usr/local/www/apache24/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
<IfModule mime_module>
    TypesConfig etc/apache24/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php        # 

</IfModule>
<IfModule proxy_html_module>
Include etc/apache24/extra/proxy-html.conf
</IfModule>
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
Include etc/apache24/Includes/*.conf


LoadModule php7_module        libexec/apache24/libphp7.so
AddType application/x-httpd-php .php                # newly added
AddType application/x-httpd-php-source .phps            # newly added
# ...................
# ...................
<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>
```


----------



## max21 (Dec 26, 2016)

After removing all of those comments out of the httpd.conf file I see that I did not provide the FullPathName for LoadModule php7_module.  The module is in place so I added the correct path and this is the error I got.  Apache, PHP and Varnishd are all in the same jail:

```
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Starting nginx.
Performing sanity check on varnishd configuration:
varnishd: the configuration file /usr/local/varnish/default.vcl syntax is ok
Starting varnishd.
Classic hash: 16383 buckets
Performing sanity check on apache24 configuration:
httpd: Syntax error on line 578 of /usr/local/etc/apache24/httpd.conf: Cannot load /mnt/d/ALL/usr/local/libexec/apache24/libphp7.so into server: Cannot open "/mnt/d/ALL/usr/local/libexec/apache24/libphp7.so"
Starting apache24.
httpd: Syntax error on line 578 of /usr/local/etc/apache24/httpd.conf: Cannot load /mnt/d/ALL/usr/local/libexec/apache24/libphp7.so into server: Cannot open "/mnt/d/ALL/usr/local/libexec/apache24/libphp7.so"
/usr/local/etc/rc.d/apache24: WARNING: failed to start apache24
Performing sanity check on php-fpm configuration:
[26-Dec-2016 05:11:20] NOTICE: configuration file /usr/local/etc/php-fpm.conf test is successful
Starting php_fpm.
#
```


----------



## ShelLuser (Dec 26, 2016)

To my knowledge PHP (www/mod_php56 or php70) does not auto configure itself. So I ended up setting up a file called php5.conf in the Includes directory:


```
<IfModule mod_php5.c>
        DirectoryIndex index.php
        AddType application/x-httpd-php .php
        AddType application/x-httpd-php-source .phps
</IfModule>
```
Although this can also be set up in httpd.conf I personally prefer this approach.


----------

