Skip to content

Commit eb36935

Browse files
authored
Merge pull request #845 from humanmade/backport-843-to-v23-branch
[Backport v23-branch] Always install the local CA in the system trust store
2 parents 2ea7c46 + 7469b65 commit eb36935

File tree

2 files changed

+68
-61
lines changed

2 files changed

+68
-61
lines changed

docs/README.md

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ The subdomain / domain *optional* config options can be configured as follows:
5555
}
5656
```
5757

58-
* `name` - Project name, used as the subdomain of the primary site, e.g. `my-project`
59-
* `tld` - TLD of the project, e.g. `my-company.local`
60-
* `domains` - Custom domains used by the project, either for main or sub sites.
58+
- `name` - Project name, used as the subdomain of the primary site, e.g. `my-project`
59+
- `tld` - TLD of the project, e.g. `my-company.local`
60+
- `domains` - Custom domains used by the project, either for main or sub sites.
6161

6262
Note: Altis does not manage the host entries for subdomains or custom domains, you'll need to manage those manually, via
6363
editing `/etc/hosts` in Linux / macOS, or `C:\Windows\System32\Drivers\etc\hosts` in Windows. Altis however tries to detect if those
@@ -88,46 +88,45 @@ started!
8888
### Multisite Subdomains / Custom domains support
8989

9090
Altis v12 introduced experimental support for multisite subdomains and custom domains. In order to support custom (sub)domains,
91-
Altis is using [`mkcert`](https://github.com/FiloSottile/mkcert) to generate SSL certificates based on a custom generated Root
92-
Certificate Authority that is uniquely-generated and trusted on the host machine upon installation. This allows Altis local-server
93-
to generate local SSL certificates that is automatically trusted, which provides a convenient and seamless local development
94-
experience.
91+
Altis uses [`mkcert`](https://github.com/FiloSottile/mkcert) to generate SSL certificates based on a generated Root
92+
Certificate Authority (CA) that is uniquely-generated and trusted on the host machine upon installation. This allows Altis
93+
local-server to generate local SSL certificates that is automatically trusted, which provides a convenient and seamless local
94+
development experience.
9595

9696
Note: Altis local-server automatically collects domains names to issue the SSL certificate for, based on Altis configuration
9797
in `composer.json`, namely the `altis.modules.local-server` tree, specifically the `name`, `tld`, and `domains` config parameters.
9898

9999
## Available Commands
100100

101-
* `composer server start [--xdebug=<mode>] [--mutagen]` - Starts the containers.
102-
* `--xdebug=<mode>` will enable Xdebug. The `mode` is optional and defaults to `debug`. Available values
101+
- `composer server start [--xdebug=<mode>] [--mutagen]` - Starts the containers.
102+
- `--xdebug=<mode>` will enable Xdebug. The `mode` is optional and defaults to `debug`. Available values
103103
are `off`, `develop`, `debug`, `profile`, `coverage`, `gcstats` and `trace`.
104-
* `--mutagen` will enable Mutagen for container file sharing.
105-
* `composer server stop [<service>] [--clean]` - Stops the containers or specified service.
106-
* `--clean` will also stop the proxy container if no service is specified, only use this if you have no other instances of Local
104+
- `--mutagen` will enable Mutagen for container file sharing.
105+
- `composer server stop [<service>] [--clean]` - Stops the containers or specified service.
106+
- `--clean` will also stop the proxy container if no service is specified, only use this if you have no other instances of Local
107107
Server
108-
* `--tmp` will mount the PHP container's `/tmp` directory to `.tmp` in your project root. This is useful for debugging
108+
- `--tmp` will mount the PHP container's `/tmp` directory to `.tmp` in your project root. This is useful for debugging
109109
with `--xdebug=profile` as the Cachegrind files are easily available
110-
* `composer server restart [<service>]` - Restart a given container, or all containers if none is provided. Available values
110+
- `composer server restart [<service>]` - Restart a given container, or all containers if none is provided. Available values
111111
are `nginx`, `php`, `db`, `redis`, `cavalcade`, `tachyon`, `s3` and `elasticsearch`.
112-
* `composer server destroy [--clean]` - Stops and destroys all containers.
113-
* `--clean` will also destroy the proxy container, only use this if you have no other instances of Local Server
114-
* `composer server status` - Displays the status of all containers.
115-
* `composer server ssl` - Shows the status of local-server SSL certificate.
116-
* `composer server ssl install` - Install `mkcert` locally and set it up to prepare for SSL generation.
117-
* `composer server ssl generate custom-domain.com` - (re)generates the local-server SSL certificate
112+
- `composer server destroy [--clean]` - Stops and destroys all containers.
113+
- `--clean` will also destroy the proxy container, only use this if you have no other instances of Local Server
114+
- `composer server status` - Displays the status of all containers.
115+
- `composer server ssl` - Shows the status of local-server SSL certificate.
116+
- `composer server ssl install` - Install `mkcert` locally and set it up to prepare for SSL generation.
117+
- `composer server ssl generate custom-domain.com` - (re)generates the local-server SSL certificate
118118
including `custom-domain.com`
119-
* `composer server ssl exec -- [<command>]` - Execute custom `mkcert` commands, e.g. `-uninstall` to revoke the root CA
120-
* `composer server logs <service>` - Tail the logs from a given service, defaults to `php`, available options
119+
- `composer server ssl exec -- [<command>]` - Execute custom `mkcert` commands, e.g. `-uninstall` to revoke the root CA
120+
- `composer server logs <service>` - Tail the logs from a given service, defaults to `php`, available options
121121
are `nginx`, `php`, `db|mysql|sql`, `redis`, `cavalcade`, `tachyon`, `s3` and `elasticsearch`.
122-
* `composer server shell` - Logs in to the PHP container.
123-
* `composer server cli|wp -- <command>` - Runs a WP CLI command. Use either `cli` or `wp`. For example,
122+
- `composer server shell` - Logs in to the PHP container.
123+
- `composer server cli|wp -- <command>` - Runs a WP CLI command. Use either `cli` or `wp`. For example,
124124
`composer server cli -- info` or `composer server wp -- info`. Do not include `wp` in `<command>`.
125-
* `composer server cli -- db import database.sql` - Imports a database file located in the project root.
126-
* `composer server create-alias` - Create a WP CLI alias. Useful if you have WP CLI installed locally.
127-
* `composer server exec -- <command>` - Runs any command on the PHP container.
128-
* `composer server db` - Logs into MySQL on the DB container.
129-
* `composer server db info` - Print MySQL connection details.
130-
* `composer server db (sequel|spf)` - Opens a connection to the database in [Sequel Pro](https://sequelpro.com)
131-
or [Sequel Ace](https://sequel-ace.com/).
132-
* `composer server db (tableplus|tbp)` - Opens a connection to the database in [Table Plus](https://tableplus.com/).
133-
* `composer server import-uploads` - Syncs files from `content/uploads` to the S3 container.
125+
- `composer server cli -- db import database.sql` - Imports a database file located in the project root.
126+
- `composer server create-alias` - Create a WP CLI alias. Useful if you have WP CLI installed locally.
127+
- `composer server exec -- <command>` - Runs any command on the PHP container.
128+
- `composer server db` - Logs into MySQL on the DB container.
129+
- `composer server db info` - Print MySQL connection details.
130+
- `composer server db (sequel|spf)` - Opens a connection to the database in [Sequel Ace](https://sequel-ace.com/).
131+
- `composer server db (tableplus|tbp)` - Opens a connection to the database in [Table Plus](https://tableplus.com/).
132+
- `composer server import-uploads` - Syncs files from `content/uploads` to the S3 container.

inc/composer/class-command.php

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -853,50 +853,57 @@ protected function ssl( InputInterface $input, OutputInterface $output ) {
853853
break;
854854
}
855855

856-
// If couldn't detect a support architecture, ask the user to install mkcert manually.
856+
// If we couldn't detect a support architecture, ask the user to install mkcert manually.
857857
if ( ! $binary_arch ) {
858858
$output->writeln( '<error>`composer server ssl install` is only supported on macOS, Linux, and Windows x64, install `mkcert` manually for other systems.</error>' );
859859
$output->writeln( '<error>Download and setup `mkcert` from https://github.com/FiloSottile/mkcert </error>' );
860+
860861
return 1;
861862
}
862863

863864
$binary = "mkcert-$mkcert_version-$binary_arch";
864-
$mkcert = 'vendor/mkcert';
865+
$mkcert = 'mkcert';
865866

866-
// Check if mkcert is installed globally already, bail if so.
867-
$version = trim( shell_exec( 'mkcert -version' ) ?: '' );
867+
// Check if mkcert is installed globally already.
868+
$version = trim( shell_exec( "$mkcert -version" ) ?: '' );
868869
if ( $version ) {
869870
$output->writeln( "<info>mkcert $version is already installed globally</>" );
870-
return 0;
871-
}
872871

873-
// Check if mkcert is installed locally already, bail if so.
874-
$version = trim( shell_exec( "$mkcert -version" ) ?: '' );
875-
if ( $version ) {
876-
$output->writeln( "<info>mkcert $version is already installed to vendor/mkcert</>" );
877-
return 0;
878-
}
872+
} else {
879873

880-
$output->writeln( "Detected system architecture to be $os $arch" );
881-
$output->writeln( "Downloading https://github.com/FiloSottile/mkcert/releases/download/$mkcert_version/$binary to $mkcert ..." );
882-
exec( "curl -o $mkcert -L https://github.com/FiloSottile/mkcert/releases/download/$mkcert_version/$binary", $dummy, $result );
883-
if ( $result ) {
884-
$output->writeln( '<error>Could not download mkcert binary, try using sudo or manually installing mkcert.</error>' );
885-
$output->writeln( '<error>Download and setup `mkcert` from https://github.com/FiloSottile/mkcert </error>' );
886-
return 1;
887-
}
874+
// Check if mkcert is installed locally already.
875+
$mkcert = 'vendor/mkcert';
876+
$version = trim( shell_exec( "$mkcert -version" ) ?: '' );
877+
if ( $version ) {
878+
$output->writeln( "<info>mkcert $version is already installed to vendor/mkcert</>" );
888879

889-
$output->writeln( "<info>mkcert $mkcert_version was downloaded.</info>" );
880+
} else {
890881

891-
chmod( $mkcert, 0755 );
882+
// We need to install it locally.
883+
$output->writeln( "Detected system architecture to be $os $arch" );
884+
$output->writeln( "Downloading https://github.com/FiloSottile/mkcert/releases/download/$mkcert_version/$binary to $mkcert ..." );
885+
exec( "curl -o $mkcert -L https://github.com/FiloSottile/mkcert/releases/download/$mkcert_version/$binary", $dummy, $result );
886+
if ( $result ) {
887+
$output->writeln( '<error>Could not download mkcert binary, try using sudo or manually installing mkcert.</error>' );
888+
$output->writeln( '<error>Download and setup `mkcert` from https://github.com/FiloSottile/mkcert </error>' );
892889

893-
exec( "$mkcert -version", $dummy, $result );
894-
if ( $result ) {
895-
$output->writeln( '<error>Could not launch mkcert binary, try manually installing mkcert.</error>' );
896-
$output->writeln( '<error>Download and setup `mkcert` from https://github.com/FiloSottile/mkcert </error>' );
897-
return 1;
890+
return 1;
891+
}
892+
893+
$output->writeln( "<info>mkcert $mkcert_version was downloaded.</info>" );
894+
895+
chmod( $mkcert, 0755 );
896+
897+
exec( "$mkcert -version", $dummy, $result );
898+
if ( $result ) {
899+
$output->writeln( '<error>Could not launch mkcert binary, try manually installing mkcert.</error>' );
900+
$output->writeln( '<error>Download and setup `mkcert` from https://github.com/FiloSottile/mkcert </error>' );
901+
902+
return 1;
903+
}
904+
$output->writeln( "<info>mkcert $mkcert_version was installed.</info>" );
905+
}
898906
}
899-
$output->writeln( "<info>mkcert $mkcert_version was installed.</info>" );
900907

901908
// Setup and accept the root certificate.
902909
exec( "$mkcert -install", $dummy, $result );
@@ -908,6 +915,7 @@ protected function ssl( InputInterface $input, OutputInterface $output ) {
908915

909916
$output->writeln( '<info>mkcert root CA was installed and accepted successfully.</info>' );
910917
break;
918+
911919
case 'generate':
912920
$config = $this->get_composer_config();
913921

0 commit comments

Comments
 (0)