EC2 Wordpress Only Showing Apache Test Page After It Was Up For A Week

I woke up this morning and my AWS Linux EC2 instance running Wordpress is showing just the Apache test page. I have Wordpress installed on this site and it's been up and running for about a week or so.

Here's a few things I've done to resolve this:

  • Restarted Apache
  • Confirmed MySQL is running
  • Restarted the EC2 Instance from the AWS Management Console

Anything I missed? I'd love to save my work and show it to the world.

The URL is http://coparent-coach.com

Thank you for your assistance.

....
TessandoIT AdministratorAsked:
Who is Participating?
 
gr8gonzoConsultantCommented:
Ah, that's good information (the guide you used before). So if you followed that guide, you should end up with PHP 7, not PHP 5...

Now, I wouldn't suggest the 2nd LAMP stack. There's a very good chance that this is a REALLY quick fix, so building a second LAMP stack is like moving to a new home because you couldn't find the light switch in your old home.

So first, if you followed that guide, then you likely have PHP installed via the yum package manager, so let's confirm what version of PHP you really have installed. First do this:

sudo yum list installed | grep -i "php"

That should show you any packages installed that have the word "php" in them.

Normally, these packages should correspond to RPM packages, so you can double-check by doing this:

sudo rpm -qa | grep -i "php"

You should see a package in that list that looks something like this:

php70-7.0.16

(the numbers might be different and there may be some extra text afterwards)

Take that line and instead of "rpm - qa", do "rpm -ql" and pass the package name to it, like this:

sudo rpm -ql <the full package name> | grep -i "\.so"

That command will list the files that come from that RPM package and the | grep -i "\.so" part will filter the output only to the lines that have ".so" in them (the .so is a Shared Object library, which is what you usually have to plug into Apache).

Ideally, you'll see something like (again, paths could be different):
/usr/lib/libphp7.so
or
/usr/lib/libphp5.so

Whatever comes back, just double-check to make sure that file still exists (it should), by listing it:

ls /usr/lib/libphp7.so (or whatever the file / path is)

If it exists, then go into your Apache config, and find the section where all the modules are loaded. It should be a big section near the beginning that has a bunch of lines that look like:

LoadModule modulenamehere modules/somefile.so

At the bottom of that list, add this line if you have PHP 7:
LoadModule php7_module /usr/lib/libphp7.so (or whatever the file/path is)

...or if you have PHP 5:
LoadModule php5_module /usr/lib/libphp5.so (or whatever the file/path is)

Save and restart Apache and try accessing a PHP file again via the URL.

If it's still showing code, then send me a private message and we can see if there's any chance we can knock it out in 1:1 chat (hopefully within the first 5 free minutes).

To answer your overall question about what the problem is, it's DEFINITELY not a code problem, nor a Wordpress problem, nor a database problem. Whenever you ask Apache for a PHP file and you see the PHP code contents instead, it means that Apache is treating that file like any other file and just sending you the raw contents instead of invoking the PHP engine to process the code and returning the results from that PHP engine. So it's almost guaranteed to be a matter of just telling Apache where to find PHP.
0
 
gr8gonzoConsultantCommented:
Have you validated the WP files still exist and that MySQL has your data?

If so, it could be that your Apache config isn't set up to listen to incoming requests for that domain (or on a specific IP that changed).
0
 
shalomcCTOCommented:
Try going to http://coparent-coach.com/wordpress
What you see is the result of an Apache misconfiguration. If you dig into the server logs or into your memory, you will find that someone did something.
Looks like php is not recognized as the script processor, and looks like your .htaccess is fubar.
0
WEBINAR: 10 Easy Ways to Lose a Password

Join us on June 27th at 8 am PDT to learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees. We'll cover the importance of multi-factor authentication and how these solutions can better protect your business!

 
Prabhin MPEngineer-TechOPSCommented:
Hi,
1) your document root folder is correct.
2) Php is not properly installed or dependency issue with webserver and php files

if you want more support pls give the access, i can help u on this
0
 
gr8gonzoConsultantCommented:
Just FYI, please do not post any access credentials here. This is a public forum. If you want 1-on-1 paid help from any of us, there is a Live help feature on this site where you're in a private chat session with an expert and can provide them the access within that chat.
1
 
TessandoIT AdministratorAuthor Commented:
Thanks Everyone - I appreciate the quick response. @Prabhin MP - I went to reinstall PHP and it's up to date. Any suggestions of how to check dependency issues with the WebServer or PHP Files?

I ask because this came out of the blue. I spun this up last week, worked on it all week even up until Saturday afternoon. When I checked it on Sunday morning, I get this PHP misconfiguration (or, I should say, the site didn't come up as expected). It's important to mention that I did no server work over the weekend, rather this "just happened". Are there any low-hanging fruit things to check from a configuration perspective? This is a very vanilla installation of Wordpress.

Thank you again.
0
 
TessandoIT AdministratorAuthor Commented:
I replaced my .htaccess folder with the standard out-of-the-box code from Wordpress and this didn't make a difference. (I backed up the .htaccess file before doing so).

# BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Open in new window


Any other suggestions would be helpful. Thank you.
0
 
gr8gonzoConsultantCommented:
Can you find your httpd.conf file on the shell, and then do a grep through the configs for references to PHP?  For example, let's say you have /etc/httpd.conf
and a bunch of additional configs in
/etc/httpd.conf.d

On the shell, do these two commands:
grep -i "php" /etc/httpd.conf
grep -ri "php" /etc/httpd.conf.d/*

If you're not sure where to find the httpd.conf file, try these 2 commands:
updatedb
locate httpd.conf

Note that if you don't have mlocate installed, that command will fail. If you're running CentOS, you can install mlocate with:
yum install mlocate

...and then run your updatedb and locate commands. (The very first time you run updatedb might take a couple minutes)

This will tell us if you have an Apache config file that doesn't have PHP installed properly (and whether or not you have multiple httpd.conf files in case there was a server reboot that happened and it resulted in Apache loading an incorrect default config file).
0
 
TessandoIT AdministratorAuthor Commented:
I found the error logs at /var/log/httpd. Doing a "tail" command (tail -f /var/log/httpd/error_log) I consistently see this coming in when I hit the home page:

[Mon Mar 05 22:43:34.978312 2018] [autoindex:error] [pid 3374] [client 7*.**7.**5.*0:56067] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.html) found, and server-generated directory index forbidden by Options directive

Open in new window


After doing some Google-Fu I found a solution that recommended adding 'index.php' to the httpd.conf file. I entered the following:

<IfModule dir_module>
DirectoryIndex index.html [b]index.php[/b]
</IfModule>

Open in new window


I restarted Apache and this didn't seem to have any change to my sites. Any further suggestions would be greatly appreciated. Thanks!
0
 
TessandoIT AdministratorAuthor Commented:
@gr8gonzo Thanks for you suggestion.

I am using Amazon Linux, so the location of my httpd.conf file is at grep -i "php" /etc/httpd/conf/httpd.conf so I ran the command:

grep -i "php" /etc/httpd/conf/httpd.conf

Open in new window


and the only reference to php is the new entry I described in my last update:

DirectoryIndex index.html index.php

Open in new window


Should there be more references to PHP that you know of?
0
 
gr8gonzoConsultantCommented:
Do you have any lines in your httpd.conf that are included? Example

Include conf/extra.conf

Sometimes different distributions try to separate out different parts of the configuration to different files.

And yes, you should have more references to PHP. There are a few different ways to set up Apache to use PHP, but the more common way is with mod_php.

This is usually done with a LoadModule line, like this:
LoadModule php7_module modules/libphp7.so

NOTE: This is ONLY an example from one of my web servers that is running PHP 7 on Apache 2.4. Your config would have to take the version of PHP into account and the correct path to the PHP module. You can find out the path to your shared module (the .so file) by doing:

locate .so | grep -i "php"

Once that's done, then Apache will know how to load the PHP engine, but it needs to be told WHEN to do it. The simplest way is to use a SetHandler, like this:

<FilesMatch \.php$>
  SetHandler application/x-httpd-php
</FilesMatch>

That tells Apache, "Whenever you come across a file that ends in .php, let it be handled by the PHP engine."

I don't know of any reason why your configuration file would have PHP working for a few days and then suddenly NOT have it without any changes. My first instinct is that you got an Apache or PHP update or something that basically overwrote your old config file with defaults, but that's REALLY strange. Most updates will not touch your config file. Is there any chance someone else is working on the same server and did something without your knowledge?
0
 
Prabhin MPEngineer-TechOPSCommented:
Hi
create file /var/www/html/info.php and add the following lines , let me know the out ,

<?php
phpinfo();
?>
0
 
TessandoIT AdministratorAuthor Commented:
Hey Guys. Thank you so much for your effort.

@gr8gonzo

There are 2 Additional references to ".conf" in the httpd.conf file. For my own sanity I've included the line numbers:
56 Include conf.modules.d/*.conf
353 IncludeOptional conf.d/*.conf


There are 123 references to PHP using the "locate .so | grep -i "php" "command

Added to httpd.conf: (Added at line 58)
<FilesMatch \.php$>
  SetHandler application/x-httpd-php
</FilesMatch>


I restarted Apache and am still getting just PHP code on the site.

@Prabhin MP

I created that file and it only shows the lines you mentioned. This can be found here: http://coparent-coach.com/info.php

In other words, it's still just showing PHP all around and not even giving me the version.

Thanks again. I appreciate all the effort you guys have put into this.
0
 
Prabhin MPEngineer-TechOPSCommented:
hi,
if  info.php showing only the code, then it means the there is dependency issue with the webserver and PHP
can you tell me which version of apache and php you are using?
0
 
TessandoIT AdministratorAuthor Commented:
@Prabhin MP

I'm running Amazon Linux with PHP 5.6.33 and Apache/2.4.27 (Amazon)

Hope this helps. Thank you for your assistance.
0
 
gr8gonzoConsultantCommented:
Personally I would suggest a live session with an expert at this point since you've now been down for a few days. It will likely cost some money (how much depends on the person's rate and how much time it takes them to fix the issue) but it's the quickest solution if you want the site back up asap.

If time / downtime isn't a problem, then you could certainly continue trying to debug it here.
0
 
TessandoIT AdministratorAuthor Commented:
@gr8gonzo - I'm with ya. This isn't mission critical, but I am delaying marketing tests and obviously paying for this server to be running.

What if I created another LAMP Stack (using the same directions I did before: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html), kept the same domain name and migrated the database and Wordpress files (e.g. wp-config, wp-settings, etc). Now, exactly how to do this, I'm not totally confident with but if I find a good recipe I should be able to follow it.

I guess I'm looking for confirmation that (1) this is Server related and not related to Wordpress itself and (2) if I was able to slipstream the databases into a new Server, it's entirely possible to migrate.

Thanks again for your help. You guys have gone above and beyond.
0
 
shalomcCTOCommented:
Hi

There is a fair chance that your apache error logs will have a hint or two.
Look in the /etc/httpd/logs directory for a file called by default error_log. If there is a missing apache module it will be in the logs.
0
 
TessandoIT AdministratorAuthor Commented:
After confirming the version of PHP I was running (per your awesome instructions), I added this line to the Apache configuration file: LoadModule php7_module /usr/lib64/httpd/modules/libphp-7.0.so

After restarting Apache and restarting MySQL, I was back in business. Thank you SO MUCH for your effort. This really had me stumped and you quickly fixed it once we established what the challenge was. Thanks again.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.