I have setup an EC2 instance with the Amazon Linux image and installed LAMP and Wordpress as per the Amazon docs.

It works fine, serves the default Wordpress page, but as soon as the instance is rebooted the web server no longer appears to work. The index page is no longer served. Curling localhost returns empty.

I'm not sure what config is lost on reboot. Apache and MYSQL are running and are setup to run on boot.

When I try and curl http://localhost and I look at the apache access log I see:

::1 - - [17/Jun/2017:00:56:26 +0000] "GET / HTTP/1.1" 301 350 "-" "curl/7.35.0"
::1 - - [17/Jun/2017:00:59:19 +0000] "GET / HTTP/1.1" 301 350 "-" "curl/7.35.0"
::1 - - [17/Jun/2017:00:59:21 +0000] "GET / HTTP/1.1" 301 350 "-" "curl/7.35.0"

Here is my httpd.conf

ServerRoot "/etc/httpd"
Listen 80

Include conf.modules.d/*.conf

User apache
Group apache

ServerAdmin root@localhost

<Directory />
    AllowOverride none
    Require all denied

DocumentRoot "/var/www/html"

<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted

# Further relax access to the default document root:
<Directory "/var/www/html">
    Options Indexes FollowSymLinks

    AllowOverride All

    Require all granted

<IfModule dir_module>
    DirectoryIndex index.html

<Files ".ht*">
    Require all denied

ErrorLog "logs/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

    CustomLog "logs/access_log" combined

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"


<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted

<IfModule mime_module>
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml

AddDefaultCharset UTF-8

<IfModule mime_magic_module>
    MIMEMagicFile conf/magic

EnableSendfile on

IncludeOptional conf.d/*.conf

Response Headers from curl -v

[ec2-user@ip-x-x-x-x ~]$ curl -v localhost
* Rebuilt URL to: localhost/
*   Trying
* Connected to localhost ( port 80 (#0)
> GET / HTTP/1.1
> Host: localhost
> User-Agent: curl/7.51.0
> Accept: */*
< HTTP/1.1 301 Moved Permanently
< Date: Sat, 17 Jun 2017 23:46:00 GMT
< Server: Apache/2.4.7 (Ubuntu)
< X-Powered-By: PHP/5.5.9-1ubuntu4.21
< X-Pingback: http://ec2-x-x-x-x.x-x-2.x.amazonaws.com/xmlrpc.php
< Location: http://ec2-x-x-x-x.x-x-2.x.amazonaws.com
< Content-Length: 0
< Content-Type: text/html; charset=UTF-8
* Curl_http_done: called premature == 0
* Connection #0 to host localhost left intact
  • When you curl ..., what are the response headers (and body)?
    – MrWhite
    Jun 17, 2017 at 20:54
  • 1
    Have you gotten it working multiple times? If so, what do you you do to get it working again? Jun 17, 2017 at 21:34
  • @user82217 Just added the response headers and body Jun 17, 2017 at 23:51
  • @StephenOstermiller I am only able to get it working when I build the instance initially. As soon the instance reboots I get this response from curl. Feels like something is redirecting my requests? Jun 17, 2017 at 23:53

2 Answers 2


I figured out the issue. When an AWS instance is rebooted, the DNS address changes. As I am using Wordpress, I need to update the siteurl and home url in the MySQL Database for the wordpress site to the new DNS address.

In the pictures below for example localhost should be replaced with the DNS address of the instance. When the instance reboots, this will need to be replaced again with the new DNS address and so on, every time the instance reboots. Really I should have used a static DNS address to save me the pain of this issue :)

site url in WP Database home url in WP Database

  • 2
    "When an AWS instance is rebooted, the DNS address changes." Not when it is rebooted, no... but this does happen if it is stopped and started, unless you've attached an elastic IP address and the instance is in a VPC. Jun 18, 2017 at 1:43
  • @Michael-sqlbot thanks for clarifying, that makes sense as initially I stopped the instance because it was unresponsive. When I started it again thats when the issue started Jun 18, 2017 at 18:49
  • 3
    That sounds right. See also Stop and Start Your Instance: Overview. Jun 18, 2017 at 19:04

I got exactly same problem when deploy HA Wordpress on EC2 Apache web server under auto scaling group when spin up new EC2 Apache web server.

1. At first I think there are problem with apache web server:

sudo vim /var/log/httpd/error_log

[Tue Nov 05 ] [core:notice] [pid 2914] AH00094: Command line: '/usr/sbin/httpd'
[Tue Nov 05 ] [mpm_prefork:notice] [pid 2914] AH00169: caught SIGTERM, shutting down
[Tue Nov 05 ] [suexec:notice] [pid 3012] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Tue Nov 05 ] [http2:warn] [pid 3013] AH10034: The mpm module (prefork.c) is not supported by mod_http2. The mpm determines how things are processed in your server. HTTP/2 has more demands in this regard and the currently selected mpm will just not do. This is an advisory warning. Your server will continue to work, but the HTTP/2 protocol will be inactive.
[Tue Nov 05 ] [http2:warn] [pid 3013] AH02951: mod_ssl does not seem to be enabled
[Tue Nov 05 14:52:14.233364 2019] [lbmethod_heartbeat:notice] [pid 3013] AH02282: No slotmem from mod_heartmonitor
[Tue Nov 05 ] [mpm_prefork:notice] [pid 3013] AH00163: Apache/2.4.41 (Amazon) PHP/7.2.24 configured -- resuming normal operations
[Tue Nov 05 ] [core:notice] [pid 3013] AH00094: Command line: '/usr/sbin/httpd'

At first I think apache web server was down but when checking with curl it show there are too many redirect:

[ec2-user@ip-ec2 ~]$ curl -v localhost:80
* Rebuilt URL to: localhost:80/
*   Trying
* Connected to localhost ( port 80 (#0)
> GET / HTTP/1.1
> Host: localhost
> User-Agent: curl/7.61.1
> Accept: */*
< HTTP/1.1 301 Moved Permanently
< Date: Tue, 05 Nov 2019 15:40:39 GMT
< Server: Apache/2.4.41 (Amazon) PHP/7.2.24
< X-Powered-By: PHP/7.2.24
< X-Pingback: http://ec2.us-2.compute.amazonaws.com/xmlrpc.php
< X-Redirect-By: WordPress
< Location: ec2.us-2.compute.amazonaws.com/
< Content-Length: 0
< Content-Type: text/html; charset=UTF-8
* Connection #0 to host localhost left intact
  1. Then 301 wordpress, ec2 lead me here after nearly 9 hours of debugging

In my case siteurl and home point to old ec2 web server instance, we can verify it by:

SELECT * FROM wp_options WHERE option_name='siteurl';
SELECT * FROM wp_options WHERE option_name='home';

Then follow @Brien Crean to update siteurl and home to ELB url then it work

UPDATE wp_options SET option_value = replace(option_value, 'old-ec2-url', 'fixed-elb-url') WHERE option_name = 'home' OR option_name = 'siteurl';

Note: You may try to clear browser cache and flush dns also

Reference: Apache not working on AWS Linux after reboot - 301 Response code


Getting a redirect to ugly beanstalk URL rather than seeing my domain name on my WordPress site, despite setting Route53 alias record

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.