Installing AMP and Wordpress together

This page was contributed by a member of the AMP community

Purpose of the guide

This is a small guide to showcase how AMP and Wordpress can coexist on the same system. This guide is based on a debian 10 (buster) system, so some of the configs may vary a little if you use another distribution.

At the end of this guide you should have a webserver where AMP resides on a subdomain, and your Wordpress is on your main domain. Both which will be on HTTPS, with any connection to HTTP redirected to HTTPS.

Prerequisites:

  1. A clean debian 10 system
  2. Basic knowledge of linux (usage of vi/nano)
  3. Access to domain controls, and knowledge about adding CNAMES.
  4. Knowledge of how to setup Wordpress

Domain config

Be sure to add CNAMES for your domain, in this guide we will use: amp.domain.com, www.domain.com and domain.com

Installation of AMP + Wordpress

  1. Install AMP - https://cubecoders.com/AMPInstall

IMPORTANT NOTES:

  • During the install of AMP, its important that when it asks for a domain, that you type in the subdomain you want to use for AMP fx. amp.domain.com
  • When it asks if it should be installed as HTTPS/SSL, say yes.
  • If Certbot asks if it should redirect all HTTP connections to HTTPS hit no
  1. Install Wordpress - I can recommend this guide to install it: Installing Wordpress

IMPORTANT NOTES:

  1. Rerunning certbot to obtain certificates for all domains.
    This will add the extra domains to your certificates, so they can all run on SSL
  • Command will look something like this: sudo certbot -d amp.domain.com -d www.domain.com -d domain.com
  • If certbot asks if it should redirect all HTTP to HTTPS, say no!

Sample configs for nginx for both wordpress and AMP

These samples are taken directly from a working production envirenment, so they should work right out of the box, with minor changes to web root, and ofc the server_names.

Do not just copy/paste these configs, but compare them to your own. You might only need to change a line or two, so it’ll be more work if you copy/paste the configs.

Wordpress nginx config: (should be located in /etc/nginx/sites-available/wordpress.conf)

        root /var/www/html/wordpress;
        index index.php index.html index.htm;
        server_name domain.com www.domain.com;

        access_log /var/log/nginx/wordpress_access.log;
        error_log /var/log/nginx/wordpress_error.log;

        client_max_body_size 64M;

        location / {
                try_files $uri $uri/ /index.php?$args;
                }

        location ~ \.php$ {
                try_files $uri =404;
                include /etc/nginx/fastcgi_params;
                fastcgi_read_timeout 3600s;
                fastcgi_buffer_size 128k;
                fastcgi_buffers 4 128k;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_pass unix:/run/php/php7.3-fpm.sock;
                fastcgi_index index.php;
                        }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/amp.domain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/amp.domain.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}
server {
    if ($host = domain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = www.domain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80 default_server;
        server_name domain.com www.domain.com;
    return 301 https://$host$request_uri; # managed by Certbot
} 

AMP nginx config: (should be located in /etc/nginx/conf.d/amp.domain.com.conf)

#Generated by CubeCoders AMP for ADS
server {
    server_name amp.domain.com;

    location / {
        proxy_pass http://localhost:8080;
        proxy_set_header        Host $host;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        Upgrade $http_upgrade;
        proxy_set_header        Connection "Upgrade";
        proxy_set_header        X-AMP-Scheme $scheme;
        proxy_read_timeout      86400s;
        proxy_send_timeout      86400s;
        proxy_http_version      1.1;
        proxy_redirect          off;
        proxy_buffering         off;
        client_max_body_size    10240M;
        error_page 502 /NotRunning.html;

        location = /NotRunning.html {
            root /opt/cubecoders/amp/shared/WebRoot;
            internal;
        }

        location /shared/ {
            alias /opt/cubecoders/amp/shared/WebRoot/;
        }
    }

    listen [::]:443 ssl http2 ipv6only=on; # managed by Certbot
    listen 443 ssl http2; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/amp.domain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/amp.domain.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = amp.domain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    listen [::]:80;
    server_name amp.domain.com;
    return 404; # managed by Certbot
}

Last steps

  1. Restart your nginx, and see if things work as intended.

http://amp.domain.com and https://amp.domain.com should reach your AMP.

http://domain.com and https://domain.com should reach your Wordpress.

  1. Remember to change your wordpress settings to https://domain.com in your general settings.

Final Thoughts

This is meant as a showcase on a clean system, if you attempt this on an already configured nginx with other subdomains, you need to take those into account aswell.

1 Like