Jump to content

Setting Up a Local Test Server - First Stumbling Block


Recommended Posts

Hello!

I hope that you are surviving CoVID-19 in the best of mental and physical health.  My newly acquired hard- and software is helping me in this regard, and for this I am very fortunate.  It was not easily obtained, but it was obtained in time!

BACKGROUND:  I have just created a new test server -- the first on my current equipment -- and downloaded my remotely hosted Grammar Captive site folder from the internet to become my first locally hosted server. Installed are Apache 2.4.41, PHP 7.3, and MacOS 10.15.4.  I also installed PERL along the way.  The test server appears to be working as it should.  A phpinfo.php file was inserted into the top folder of my web folder, and it displays proudly the information associated with the phpinfo() function.  Just to be sure I also included an .htaccess file with the following code in my /Sites folder -- the location of my site folder.

<IfModule mime_module>
    <Files grammarcaptive.com/overview.html>
        AddType application/x-httpd-ea-php73 .php .html
    </Files>
</IfModule>

<IfModule mime_module>
  AddHandler application/x-httpd-ea-php73 .php .php7 .phtml
</IfModule>

Although the Javascript in my landing page works fine, the javascript in my sites main page (overview.html) fails completely.  I am confronted with the following two error messages.
 

SyntaxError: expected expression, got '<'
ReferenceError: refer_type is not defined

As you consider these errors, please understand that the downloaded site folder is a mirror image of what works perfectly fine on my remotely located web host server.  The corresponding PHP and Javascript are provided below.

PHP (overview.html)

    if (isset($_GET['refer_type']) && filter_var($_GET['refer_type'], FILTER_VALIDATE_INT)) {
        $refer_type = $_GET['refer_type'];
    } else {
        $refer_type = 0;
    }

JAVASCRIPT (overview.html)

 

       var refer_type = <?php echo $refer_type; ?>;


JAVASCRIPT (overview.js)

    if (!refer_type && !navtype && (viewportWidth > 600) && !returnType) {
        var fileName = '';
        $.colorbox({opacity: '0.70', transition: 'elastic', speed: 700, width: 700, height: 'auto', scrolling: false, html:"<div id='welcome_slide'> <table> <tr> <td width=250 height='auto'> <img src='_images/freed_captive.png' height=200 width=200 /> </td> <td width=450 height='auto'> <h1>Hi!</h1><h2>My name is Roddy.</h2> <p class='welcome'>This is your gateway out of the prison of bad grammar.</p><p>Let me show you to the final gate!</p></td> </tr> </table> </div>",
            onClosed: function() {
                $("iframe.splash").colorbox({iframe: true, fastiframe: false, fixed: false, opacity: "0.65", open: true, rel: 'sweet', width: 700, height: 450, closeButton: true, href: function(){
                    var href = $(this).attr('src');
                    function extractFileName (href) {
                        var slash = '/';
                        var fullStop = '.';
                        href_str = '';
                        var href_arr = href.split(fullStop);
                        href_arr.pop();
                        if (href_arr.length > 1) {
                            href_str = href_arr.pop();
                            href_arr = href_str.split(slash);
                            if (href_arr.length > 1) {
                                href_str = href_arr.pop();
                            }
                        } else {
                            href_arr = href_arr[0].split(slash)
                            if (href_arr.length > 1) {
                                href_str = href_arr.pop();
                            } else {
                                href_str = href_arr[0];
                            }
                        }                                        
                        return href_str;
                    }
                    fileName = extractFileName(href);
                    _paq.push(['trackEvent', 'Gate One', 'Click', fileName]);                   
                    return href;
                }
            });
        }});
    }

COMMENT AND INQUIRY: Although PHP error reporting is included in the mainpage document, no error are reported.

    error_reporting(E_ALL);
    ini_set('log_errors', 1);
    ini_set('html_errors', 1);
    ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'error.log');
    ini_set('display_errors', 0);

The Apache error log yields only the following, and I am with the understanding that it is only an unimportant warning in a local test server.

        [Sat May 02 09:48:31.124803 2020] [mpm_prefork:notice] [pid 7841] AH00169: caught SIGTERM, shutting down
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using jupiter.local. Set the 'ServerName' directive globally to suppress this message

        [Sat May 02 10:21:07.064389 2020] [mpm_prefork:notice] [pid 157] AH00163: Apache/2.4.41 (Unix) PHP/7.3.11 mod_perl/2.0.9 Perl/v5.18.4 configured -- resuming normal operations
        [Sat May 02 10:21:07.064468 2020] [core:notice] [pid 157] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'

What does appear on the page is unread PHP.  This would suggest that the problem is related to the version of PHP.  This does not appear to be the case, however.  Recently I upgraded my remote server from PHP 7.2 to 7.3 so that it would match the PHP version my new machine.  And, the page functions quite normally on the remote server.

I am at a loss.

Please advise.

Roddy
 

 

 

 

Link to post
Share on other sites

Hi Dsonesuk!

So, I performed the following, but there was no change.  This was to be expected, however.  The mainpage works fine on the remote server with both versions of PHP.

    $refer_type = 0;
    if (isset($_GET['refer_type']) && filter_var($_GET['refer_type'], FILTER_VALIDATE_INT)) {
        $refer_type = $_GET['refer_type'];
    } else {
        $refer_type = 0;
    }

Roddy

Link to post
Share on other sites

I will try adding the server name to the httpd.conf file tomorrow, but I fear that it will not make a difference.

I am somewhat desperate at this point.

Roddy

Link to post
Share on other sites

Something is causing the javascript variable to read possibly the opening PHP tag?

Define the variable above its current position

var refer_type;

refer_type = <?php echo $refer_type; ?>;

What is the actual php value echoed out in javascript code.

Are you actually using EasyApache? As referenced in .htaccss file -ea-

Edited by dsonesuk
Link to post
Share on other sites

OK.  This is what I have done:

1) As I am not working with cPanel on my local test server, I eliminated all reference to the EasyApache2 on my local server.  This had no effect.

2) I defined the Javascript variable refer_type before use.   This had no effect.

3) I tried to discover the value of refer_type but was unable.  Please see the code below.

		var refer_type;
		var refer_type = <?php echo $refer_type; ?>;
		console.log('refer_type: ' + refer_type);

I have not yet added the server name in the httpd.conf file, as I an expecting to create a number of integrated virtual test servers in the future.  In the meantime I am looking for other problems on my local server that may be created by my dependency on cPanel on my remote server.

Please advise further.

Roddy

 

Link to post
Share on other sites

Remove var from second line, without php add 0 to see if error still persists, if not, then the php is not providing a value for it to work. It would seem that html file with php is not being processed on the server. If it is not being processed i would expect on looking at source the php code would still be visible.

Link to post
Share on other sites

Alright, I have performed what you suggested, and the complaint disappeared and then reappeared in a similarly constructed line just below. The following variable assignment is being rejected. 

<?php echo "'" . $some_php_variable . "'";?>;

As you suggest, something appears to be preventing PHP from doing its job.  As PHP works in other folders in the same /Sites folder to which Apache points, the problem must lie within the configuration settings unique to the grammarcaptive.com folder.  I am beginning to understand.

Besides the .htaccess files can you think of any other sources that might create a conflict?

Roddy

ps.  I apologize for not having removed the second appearance of var.  It has been some time since I have coded, and I overlooked the duplication.

Edited by iwato
Link to post
Share on other sites

Here is the relevant code to which I referred above.

		var refer_type;
// 		refer_type = <?php echo $refer_type; ?>;
		refer_type = 0;
		console.log('refer_type: ' + refer_type);
		var panelType = <?php echo "'" . $panel_type . "'";?>;
		var langType = <?php echo "'" . $lang_type . "'";?>;
		var navtype = Boolean(1);

The new complaint is panel_type.

But, now I am confused about the use of the console.log( ) function. The complaint about refer_type not having a value has disappeared, but nothing appears in the Web Console.  Is this because all of the Javascript must work before the console.log( ) result is displayed?

Roddy

Link to post
Share on other sites

Having cleaned up the .htaccess file so that it would be better configured for my own operating system I returned to the Apache error log to see, if there had been any change.  The change suggests that the problem is not unique to the grammarcaptive.com folder; rather it is a problem of all folders that must connect to the internet.  Here is what I found in two steps:  first in the Apache error log and then in Terminal with the Apache path and command provided in the error code.

Apache Error Log

[Sun May 03 15:30:07.298098 2020] [mpm_prefork:notice] [pid 1357] AH00163: Apache/2.4.41 (Unix) PHP/7.3.11 mod_perl/2.0.9 Perl/v5.18.4 configured -- resuming normal operations
[Sun May 03 15:30:07.298156 2020] [core:notice] [pid 1357] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'

Terminal

% /usr/sbin/httpd -D FOREGROUND

			AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using jupiter.local. Set the 'ServerName' directive globally to suppress this message
			(48)Address already in use: AH00072: make_sock: could not bind to address [::]:80
			(48)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
			no listening sockets available, shutting down
			AH00015: Unable to open logs

What I did differently from anything I have found on the internet was to change both the User and Group directives from _www to the same values of my /Sites folder.  Only in this way was I able to get both Apache and PHP to access the files and folders of my /Sites folder.

Any suggestions on how to proceed?

Roddy

 

 

Link to post
Share on other sites

Well, yeah,  a myriad of solutions with few explanations as to why. A lot of guesswork with no real understanding as to outcome.  If it works takes it, and be happy that it works.  Are there secondary outcomes for which you may be sorry later.  Who knows?

My hope was that there was someone knowledgeable about Apple MacOS 10.15.4 and Apache 2.4.41.

Thanks, anyway. You did teach me a little about trouble shooting my Javascript.

Roddy

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...