Configure domain in Digital Ocean (Apache + PHP)

Author
By Darío Rivera
Posted On in Digital Ocean

We have already seen in a previous post what I consider the first steps with digital ocean. Today, we will see how to configure your domain previously acquired with a provider like GoDaddy, so you can easily publish your projects with digital ocean.

Before we begin, we are going to make some observations. We are going to assume that the droplet you have created is in a Linux distribution like Debian, or based on Debian like Ubuntu and that you have also installed Apache with PHP. You can check our post for Installing Apache, PHP and MySQL on Debian 10 (Buster).

Step 1 - Hosts file

In a newly created droplet, you must enter by SSH and modify the file /etc/hosts adding a record for your domain. For example.

# My domain
127.0.0.1 example.org

Step 2 - Virtual host configuration

The next step is to configure a virtual host for your domain. This step can be done in several ways depending on the apache configuration you have. Let's assume that in the apache configuration file apache2.conf or httpd.conf you have enabled the configuration load from mods-enabled. You can verify this if there is a line like the following in the configuration.

IncludeOptional mods-enabled/*.conf

This means that all files within mods-enabled with the .conf extension will be loaded as virtual hosts. Generally, the files are in mods-available and in mods-enabled there are only symbolic links. That said, simply create a file like the following mods-available/example.org.conf and add the necessary content, for example.

<VirtualHost *:80>
    ServerName   example.org
    DocumentRoot "/var/www/html/example.org/public/"
    ErrorLog     "/var/www/html/example.org/storage/logs/error.log"
    CustomLog    "/var/www/html/example.org/storage/logs/access.log" combined
</VirtualHost>

Step 3 - Create your project

The previous configuration implies that you must create a folder called example.org in your HTML files folder. There you will place your project. If you use composer, you will need to install those dependencies. At this point, you may need to configure some aspects of PHP such as extensions. Don't forget to check our post Installing PHP extensions on Debian.

Step 5 - Verify Apache configuration

Before restarting the apache server, verify that everything is correct with the following command.

$ sudo apachectl configtest
Syntax OK

After this, you can restart the Apache server with the following command.

service apache2 restart

Step 6 - DDNS service for your domain

The last step is to configure a DDNS service for your domain. DDNS services have the fundamental task of associating an IP address to a domain, in this case it would be to associate the IP address of your droplet with the name of your domain. We will see this configuration in an upcoming post. Until next time.


Acerca de Darío Rivera

Author

Application Architect at Elentra Corp . Quality developer and passionate learner with 10+ years of experience in web technologies. Creator of EasyHttp , an standard way to consume HTTP Clients.

LinkedIn Twitter Instagram

Sólo aquellos que han alcanzado el éxito saben que siempre estuvo a un paso del momento en que pensaron renunciar.