Migrating site broke frontend

I have built a site locally and everything looks and functions great. When migrating to an existing how to show to client, things still work fine. The issue comes into play when migrating to client site.

If you take a look at http://aqpconstruction.cosmicstrawberry.com/ everything works as expected.
But when migrating to a new server. http://dev1.aqpconstruction.com/ I get all sorts of errors.

Call to a member function url() on a non-object

<a href="<?= $item->url(); ?>" <? e( $item->isOpen(), ' class="active"' ); ?>><?= $item->title()->html(); ?></a>

While the issue makes sense, it does not make sense in this situation. I can guarantee there is a child called $item and I can guarantee that it has url. The versions on both servers are exactly the same. ( I am not a server guy ) From what I can tell the systems are identical. Both running Linux, cPanel, Apache, and everything is to spec, from the information we could find.

So my questions are.

  1. What are the requirement for a server on Linux? I can only seem to find Windows and Mac install.
  2. Any idea why the panel would read the system just fine but the front end throw the errors?
  3. Has anyone else run into this issue of admin working but front end not or visa versa?

The first thing that comes to mind is that you are using short tags <? which you should not do apart from the echo short tag <?=.

This doesn’t seem to be the problem. Well entirely at least. I converted all the syntax to be <?php and <?php echo just to be safe. Now I get a totally new error.

syntax error, unexpected 'endif' (T_ENDIF)

</ul> <?php endif; ?>

Which I can assure that it is needed, as it works on my local and dev server.

Well, something must be wrong, but as I lost my crystal ball, I can’t do anything without your code :wink: and the line the error message refers to…

Below is the code that is producing the error. But again, not sure if this is really a cause or symptom of something else.

Is there documentation on what the server setup needs to be? Like what apache modules need to be active or inactive.
I wonder if there is something else that could be causing the overall issue.

(btw… I appreciate your help, this issue is driving me crazy. It works locally and I don’t have access to the server logs to see if there are any other issues that could be lingering )

<html lang="en">
<head>
  <meta charset="utf-8"/>
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <title><?php echo $site->title()->html() . ' | ' . $page->title()->html(); ?></title>
  <link rel="stylesheet" href="<?php echo url( 'assets/styles/styles.css' ) ?>">
</head>
<body>

<header class="wrapper wrapper--nav">
	<?
		$items = $pages->visible();
		if ( $items->count() ): ?>
      <ul class="main-nav">

				<?php foreach ( $items as $item ): ?>
          <li class="nav__item">
            <a
              href="<?php echo $item->url(); ?>" <?php e( $item->isOpen(), ' class="active"' ); ?>><?php echo $item->title()->html(); ?></a>

						<?php if ( $item->children()->visible()->count() ): ?>
              <ul class="sub-nav">

								<?php foreach ( $item->children()->visible() as $subitem ) : ?>
                  <li class="sub-nav__item">
                    <a href="<?php echo $subitem->url(); ?>"><?php echo $subitem->title()->html(); ?></a>

										<?php if ( $subitem->children()->visible()->count() ): ?>
                      <ul class="sub-nav">

												<?php foreach ( $subitem->children()->visible() as $sub ) : ?>
                          <li class="sub-nav__item">
                            <a href="<?php echo $sub->url(); ?>"><?php echo $sub->title()->html(); ?></a>


														<?php if ( $sub->children()->visible()->count() ): ?>
                              <ul class="sub-nav">
																<?php foreach ( $sub->children()->visible() as $s ) : ?>
                                  <li class="sub-nav__item">
                                    <a href="<?php echo $s->url(); ?>"><?php echo $s->title()->html(); ?></a>
                                  </li>
																<?php endforeach; ?>

                              </ul>
														<?php endif; ?>

                          </li>
												<?php endforeach; ?>

                      </ul>
										<?php endif; ?>

                  </li>
								<?php endforeach; ?>

              </ul>
						<?php endif; ?>

          </li>
				<?php endforeach; ?>
        <li class="nav__item">
          <a href="http://docs.aqpconstruction.com/" target="_blank">Client Portal</a>
        </li>

      </ul>
		<?php endif; ?>
</header>

There’s still a short open tag in line 11, right after the opening header element. Unless you enable short open tags in your php.ini, this will likely be the cause of the error message. It is not advisable to use short open tags apart from the short echo tag, though.

So avoid this:

<? if($a == $b) { //do this; } ?>

Use this:

<?= $page->title(); ?>

…you are using short tags <? which you should not do apart from the echo short tag <?=.

@texnixe I’m just curious, what’s the reason for this? Why shouldn’t they be used if your server is configured to use them?

@HYR Please see this thread: To PHP Short Tag or not to PHP Short Tag?

You can of course use short open tags, if your server is configured to use them, but in most cases, it is not advisable (as proven by the issue above)

@texnixe Ah I see… thanks for the link! :slight_smile:

Well that was the issue. <? is not configured on the new server thus breaking everything.

After taking a more thorough look through all my code, I have successfully take all from <? to <?php

Does anyone know what the server setting is for that? Because I have 2 instances where the short had works. And honestly, this has not been an issue up until this install. ( Which is why I didn’t think of that. )

Thank you everyone for your help!

It’s a php.ini setting:

short_open_tag = On

But as explained in the post I linked to above, there are good reasons not to use short open tags.