By Al Sargent
There’s a great guide on how to set up a WordPress droplet on Digitalocean:
… but it stops short of indicating how to set up a subdomain that points to that WordPress instance.
What I’d like to do is set up a subdomain, blog.mydomain.com, which points to the home page (index.html) of that WordPress instance.
Yes, there’s an article on how to set up a subdomain to a domain, but it’s unclear what modifications (if any) to this process are required when working specifically with WordPress:
https://docs.digitalocean.com/products/networking/dns/how-to/add-subdomain/
Thanks for any help you can provide. And apologies in advance if this my question is already answered somewhere.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hey @alsargent,
First, as you mentioned you need to create a DNS record for your subdomain. Depending on where your DNS is managed at, go there and create two A records. One for blog.mydomain.com and another for www.blog.mydomain.com. Both records should be pointing to your Droplet.
Once that is done, SSH to your Droplet. I’ll assume you’re using Apache or NGINX, as they are the most common web servers. Here are some basic steps for both.
subdomain.example.com.conf:<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName subdomain.example.com
DocumentRoot /var/www/subdomain
<Directory /var/www/subdomain/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
In this case, the WordPress files should be located in /var/www/subdomain.
Please also note, you’ll need to update the settings inside accordingly to your domain.
sudo a2ensite subdomain.example.com
sudo systemctl reload apache2
subdomain.example.com:server {
listen 80;
server_name subdomain.example.com;
root /var/www/subdomain;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
sudo ln -s /etc/nginx/sites-available/subdomain.example.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
In both cases, don’t forget to adjust the paths, domain names and PHP versions according to your environment. Also remember to configure DNS for your subdomain to point to the correct server.
Before you start, make sure you have a backup of your server, or at least your current configurations. If something goes wrong, you can always revert to the previous state.
Next, you’ll just need to install WordPress in the directory you have configured in your webservice.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.