Product
Pricing
arrow
Get Proxies
arrow
Use Cases
arrow
Locations
arrow
Help Center
arrow
Program
arrow
Email
Enterprise Service
menu
Email
Enterprise Service
Submit
Basic information
Waiting for a reply
Your form has been submitted. We'll contact you in 24 hours.
Close
Home/ Blog/ One step to completion: Use mkcert to generate trusted HTTPS certificates for local development services

One step to completion: Use mkcert to generate trusted HTTPS certificates for local development services

PYPROXY PYPROXY · Jun 05, 2025

In today's web development landscape, securing connections is paramount, even for local environments. Using HTTPS ensures encrypted data transmission, preventing potential attacks and data leaks. While HTTPS is widely used in production, developers often face challenges generating trusted certificates for local development. mkcert is a simple and effective tool designed to help developers create locally trusted HTTPS certificates, without the complexities of dealing with certificate authorities or manually modifying system settings. This guide will walk you through the process of generating these certificates for your local services, providing a seamless development experience that mirrors production environments. By the end, you'll have a fully functional HTTPS setup that is both secure and easy to implement.

Understanding the Need for HTTPS in Local Development

When developing web applications locally, many developers choose to work with HTTP rather than HTTPS, as it's simpler to set up and doesn't require certificates. However, this can introduce security risks, especially if sensitive data is involved, or if the application relies on features that require HTTPS, like service workers or secure cookies. Without HTTPS, sensitive information such as passwords and session tokens are transmitted in plaintext, potentially exposing them to interception.

As web development practices evolve, more browsers and tools are requiring HTTPS even for local development. For instance, Google Chrome now restricts certain features (like geolocation and camera access) to HTTPS sites only. Additionally, many APIs and third-party services require secure connections. Therefore, having HTTPS enabled in your local development environment ensures that your application is fully compliant with modern web standards and ready for production deployment.

What is mkcert?

mkcert is a simple tool designed to generate locally trusted development certificates. It automatically creates a Certificate Authority (CA) that is trusted by your operating system and browsers. Unlike other methods, mkcert does not require manual intervention or complex configurations. It's an open-source tool and is supported on various operating systems, including macOS, Linux, and Windows. By using mkcert, developers can easily set up HTTPS for their local development environments with minimal effort and without the need for expensive or complex certificates from official certificate authorities.

Step-by-Step Guide to Using mkcert for Local HTTPS

Step 1: Install mkcert

The first step is to install mkcert. Installation varies slightly depending on your operating system:

- macOS: Use Homebrew to install mkcert. Simply run the command:

```

brew install mkcert

```

- Linux: Depending on your distribution, you can use the package manager. For instance, on Ubuntu, you would run:

```

sudo apt install mkcert

```

- Windows: On Windows, you can download the precompiled binaries from mkcert’s repository or install it using a package manager like Chocolatey:

```

choco install mkcert

```

Once mkcert is installed, you may need to install the local CA (Certificate Authority) to enable it to generate certificates. You can do so by running:

```

mkcert -install

```

This step ensures that the local CA is trusted by your operating system and browsers.

Step 2: Generate the HTTPS Certificates

Now that mkcert is installed, generating the certificates for your local development environment is straightforward. Navigate to the folder where you want to store the certificates and run the following command:

```

mkcert localhost

```

This command will generate two files in the directory: `localhost.pem` (the certificate) and `localhost-key.pem` (the private key). These files will be used to configure your local server to use HTTPS.

You can also generate certificates for other custom domain names (such as `dev.local` or `myapp.local`) by specifying the name when running mkcert:

```

mkcert dev.local

```

Step 3: Configure Your Local Server to Use HTTPS

Once you have generated the certificate and private key files, the next step is to configure your local development server to use HTTPS. Most modern web servers support SSL/TLS configuration, including Node.js, Apache, and Nginx.

For instance, in a Node.js application, you can use the `https` module to enable HTTPS. Here’s an example of how to configure it with the generated certificates:

```javascript

const https = require('https');

const fs = require('fs');

const express = require('express');

const app = express();

const options = {

key: fs.readFileSync('localhost-key.pem'),

cert: fs.readFileSync('localhost.pem')

};

https.createServer(options, app).listen(3000, () => {

console.log('HTTPS server running on https://localhost:3000');

});

```

Ensure that the file paths to the `localhost.pem` and `localhost-key.pem` match the location where you generated the certificates. After this setup, your local server will serve content over HTTPS.

Step 4: Trusting the Certificates in Your Browser

While mkcert automatically installs a trusted local CA, you may need to restart your browser for the changes to take effect. This step ensures that the certificates are trusted by your browser, and you won’t see any SSL errors when navigating to your local development environment.

For most browsers, mkcert ensures that they automatically trust the certificates generated by your local CA. However, if you encounter issues, you can manually add the generated certificates to your browser’s certificate store.

Step 5: Test Your Setup

To confirm that your local development environment is using HTTPS, open your browser and navigate to the local server (for example, `https://localhost:3000`). You should see the padlock icon in the browser’s address bar, indicating that the connection is secure.

If you don’t see this, double-check the server configuration and ensure that the paths to your certificate files are correct. Additionally, check that your browser is not blocking the certificate.

Benefits of Using mkcert for Local HTTPS

Using mkcert for local HTTPS development offers several key benefits:

- Ease of Use: mkcert simplifies the process of generating trusted HTTPS certificates for local development without requiring complex configuration.

- Security: By using HTTPS locally, you ensure that sensitive data is encrypted, even in development environments, which mimics production conditions.

- Compliance: With the increasing demand for secure connections, especially for Progressive Web Apps (PWAs) and service workers, mkcert helps ensure compliance with modern web standards.

- Realistic Development Environment: Testing your application with HTTPS locally gives you a more accurate reflection of how it will behave in production, reducing potential issues down the line.

mkcert provides an easy, reliable way to enable HTTPS in your local development environment. By following the steps outlined above, you can generate trusted certificates and configure your local server to serve content securely. This not only improves the security of your local applications but also ensures they are ready for production deployment, where HTTPS is the standard. With mkcert, you eliminate the complexity of handling certificates and can focus more on building your application with confidence, knowing that the communication between the client and server is secure.

Related Posts

Clicky