ServerHandbook live check: run log ------------------------------------------------------------------------------ Article https://serverhandbook.com/kb/port-already-in-use-ubuntu Check scripts/live/checks/port-already-in-use-ubuntu.mjs (sha256 8784e533c89083ed962727bc8ad7e3d81c5258d9a4268e420fca2caa1545f000) Ran at 2026-11-19T09:11:27Z (248 s) Result PASS, all 22 claims held Tested on System Ubuntu 26.04.1 LTS Kernel 7.0.0-30-generic Package nginx 1.28.3-2ubuntu1.12 Package apache2 2.4.66-2ubuntu2.8 Package iproute2 6.19.0-1ubuntu1.1 Package lsof 4.99.4+dfsg-2build2 Package psmisc 23.7-2ubuntu2 Setup A fresh Ubuntu 26.04 server (a rented cloud server, rebuilt to the provider’s stock image) with Apache already installed and running on port 80, reached over SSH as the sudo user deploy. Nginx is then installed on the same server. Every version above was read from the server at run time. Passwords used on the throwaway test server are shown as [password]. How we test: https://serverhandbook.com/how-we-test ------------------------------------------------------------------------------ What the steps changed on the server (recorded before the first step and after the last) Packages added (2) nginx 1.28.3-2ubuntu1.12 nginx-common 1.28.3-2ubuntu1.12 Packages upgraded (0) Packages removed (0) Services enabled at boot (1) nginx.service Services disabled (1) apache2.service Listening sockets opened (2) tcp 0.0.0.0:80 nginx tcp [::]:80 nginx Listening sockets closed (1) tcp *:80 apache2 Files added in /etc (30) /etc/default/nginx /etc/init.d/nginx /etc/logrotate.d/nginx /etc/nginx/fastcgi.conf /etc/nginx/fastcgi_params /etc/nginx/koi-utf /etc/nginx/koi-win /etc/nginx/mime.types /etc/nginx/nginx.conf /etc/nginx/proxy_params /etc/nginx/scgi_params /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default /etc/nginx/snippets/fastcgi-php.conf /etc/nginx/snippets/snakeoil.conf /etc/nginx/uwsgi_params /etc/nginx/win-utf /etc/rc0.d/K01nginx /etc/rc1.d/K01nginx /etc/rc2.d/K01apache2 /etc/rc2.d/S01nginx /etc/rc3.d/K01apache2 /etc/rc3.d/S01nginx /etc/rc4.d/K01apache2 /etc/rc4.d/S01nginx /etc/rc5.d/K01apache2 /etc/rc5.d/S01nginx /etc/rc6.d/K01nginx /etc/systemd/system/multi-user.target.wants/nginx.service /etc/ufw/applications.d/nginx Files changed in /etc (0) Files removed from /etc (5) /etc/rc2.d/S01apache2 /etc/rc3.d/S01apache2 /etc/rc4.d/S01apache2 /etc/rc5.d/S01apache2 /etc/systemd/system/multi-user.target.wants/apache2.service Disk used on / (includes logs written during the run): +2.7 MB ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Check-your-server script (2 items): https://cdn.serverhandbook.com/check/port-already-in-use-ubuntu/ubuntu-26.04.1-20261119t091127z.sh SHA-256 709d876678ed64c4e5bc11508dce360c2905cce0d013dcbe9b6fc42292a18400 ------------------------------------------------------------------------------ On the stock server, before the first step: FAIL nginx is running FAIL Apache is not set to start at boot (it would take port 80 again) After the last step: PASS nginx is running PASS Apache is not set to start at boot (it would take port 80 again) ------------------------------------------------------------------------------ Claims (22), each with what the run saw ------------------------------------------------------------------------------ 1. ok a bare Ubuntu 26.04 server box (web-server) starts 2. ok (setup) Apache is installed and running | active 3. ok the install prints "Failed to start NGINX in postinst script" in the middle, then carries on | Reading package lists... Done | Building dependency tree... Done | Reading state information... Done | Solving dependencies... Done | The following additional packages will be installed: | nginx-common | Suggested packages: | fcgiwrap nginx-doc | The following NEW packages will be installed: | nginx nginx-common | 0 upgraded, 2 newly installed, 0 to remove and 159 not upgraded. | Need to get 656 kB of archives. | After this operation, 1,864 kB of additional disk space will be used. | Get:1 https://mirror.hetzner.com/ubuntu/packages resolute-updates/main amd64 nginx-common all 1.28.3-2ubuntu1.12 [38.2 kB] | Get:2 https://mirror.hetzner.com/ubuntu/packages resolute-updates/main amd64 nginx amd64 1.28.3-2ubuntu1.12 [618 kB] | Fetched 656 kB in 0s (1,948 kB/s) | Preconfiguring packages ... | Selecting previously unselected package nginx-common. | (Reading database… 52844 files and directories currently installed.) | Preparing to unpack …/nginx-common_1.28.3-2ubuntu1.12_all.deb… | Unpacking nginx-common (1.28.3-2ubuntu1.12)… | Selecting previously unselected package nginx. | Preparing to unpack …/nginx_1.28.3-2ubuntu1.12_amd64.deb… | Unpacking nginx (1.28.3-2ubuntu1.12)… | Setting up nginx-common (1.28.3-2ubuntu1.12)… | Created symlink '/etc/systemd/system/multi-user.target.wants/nginx.service' → '/usr/lib/systemd/system/nginx.service'. | Could not execute systemctl: at /usr/bin/deb-systemd-invoke line 148. | Setting up nginx (1.28.3-2ubuntu1.12)… | Job for nginx.service failed because the control process exited with error code. | See "systemctl status nginx.service" and "journalctl -xeu nginx.service" for details. | invoke-rc.d: initscript nginx, action "start" failed. | × nginx.service - A high performance web server and a reverse proxy server | Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: enabled) | Active: failed (Result: exit-code) since Thu 2026-11-19 09:13:00 UTC; 12ms ago | Invocation: 293d76a7e3eb437c993bf8450a53d2dc | Docs: man:nginx(8) | Process: 3665 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS) | Process: 3667 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE) | Mem peak: 2M | CPU: 31ms | | Nov 19 09:12:59 web-server nginx[3667]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) | Nov 19 09:12:59 web-server nginx[3667]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) | Nov 19 09:12:59 web-server nginx[3667]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) | Nov 19 09:12:59 web-server nginx[3667]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) | Nov 19 09:13:00 web-server nginx[3667]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) | Nov 19 09:13:00 web-server nginx[3667]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) | Nov 19 09:13:00 web-server nginx[3667]: nginx: [emerg] still could not bind() | Nov 19 09:13:00 web-server systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE | Nov 19 09:13:00 web-server systemd[1]: [0;1;38:5:185m[0;1;38:5:185mnginx.service: Failed with result 'exit-code'. | Nov 19 09:13:00 web-server systemd[1]: Failed to start nginx.service - A high performance web server and a reverse proxy server. | Failed to start NGINX in postinst script, please check the logs | Processing triggers for man-db (2.13.1-1build1)… | Processing triggers for ufw (0.36.2-9build1)… | Scanning processes... | Scanning linux images... | | Running kernel seems to be up-to-date. | | No services need to be restarted. | | No containers need to be restarted. | | No user sessions are running outdated binaries. | | No VM guests are running outdated hypervisor (qemu) binaries on this host. 4. ok apt itself still exits 0: nothing at the end says it failed | 0 5. ok systemctl is-active nginx: failed | failed 6. ok the journal: bind() to 0.0.0.0:80 failed (98: Address already in use) | Nov 19 09:12:57 web-server nginx[3652]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) | Nov 19 09:12:58 web-server nginx[3667]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 7. ok ss without sudo: the port is LISTEN but no process is named | State Recv-Q Send-Q Local Address:Port Peer Address:Port Process | LISTEN 0 511 *:80 *:* 8. ok sudo ss: users:(("apache2",pid=…)) on port 80 | State Recv-Q Send-Q Local Address:Port Peer Address:Port Process | LISTEN 0 511 *:80 *:* users:(("apache2",pid=2581,fd=4),("apache2",pid=2580,fd=4),("apache2",pid=2564,fd=4)) 9. ok lsof names apache2 listening on *:80 | COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME | apache2 2564 root 4u IPv6 17744 0t0 TCP *:80 (LISTEN) | apache2 2580 www-data 4u IPv6 17744 0t0 TCP *:80 (LISTEN) | apache2 2581 www-data 4u IPv6 17744 0t0 TCP *:80 (LISTEN) 10. ok fuser -v lists apache2 on 80/tcp | USER PID ACCESS COMMAND | 80/tcp: root 2564 F.... apache2 | www-data 2580 F.... apache2 | www-data 2581 F.... apache2 11. ok the process belongs to the apache2 service: active (running) | ● apache2.service - The Apache HTTP Server | Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled) | Active: active (running) since Thu 2026-11-19 09:12:05 UTC; 1min 34s ago 12. ok disable --now stops Apache and removes it from boot | Synchronizing state of apache2.service with SysV service script with /usr/lib/systemd/systemd-sysv-install. | Executing: /usr/lib/systemd/systemd-sysv-install disable apache2 | Removed '/etc/systemd/system/multi-user.target.wants/apache2.service'. 13. ok port 80 is free: ss prints only its header | State Recv-Q Send-Q Local Address:Port Peer Address:Port Process 14. ok nginx is active | active 15. ok sudo ss: nginx now holds port 80 (IPv4 and IPv6) | State Recv-Q Send-Q Local Address:Port Peer Address:Port Process | LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=4586,fd=5),("nginx",pid=4585,fd=5),("nginx",pid=4584,fd=5)) | LISTEN 0 511 [::]:80 [::]:* users:(("nginx",pid=4586,fd=6),("nginx",pid=4585,fd=6),("nginx",pid=4584,fd=6)) 16. ok curl: Server: nginx | Server: nginx/1.28.3 (Ubuntu) 17. ok port 22 lists "systemd" pid=1 as well as sshd: socket activation (ssh.socket) | State Recv-Q Send-Q Local Address:Port Peer Address:Port Process | LISTEN 0 4096 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=1295,fd=3),("systemd",pid=1,fd=154)) | LISTEN 0 4096 [::]:22 [::]:* users:(("sshd",pid=1295,fd=4),("systemd",pid=1,fd=155)) 18. ok systemctl list-sockets: ssh.socket listens on port 22 | 0.0.0.0:22 ssh.socket ssh.service | [::]:22 ssh.socket ssh.service | /run/ssh-unix-local/socket sshd-unix-local.socket - 19. ok (nginx is running at the end of the steps) | active 20. ok (Apache is not set to start at boot at the end of the steps) | disabled 21. ok (tested on) the box reports its OS, kernel and the version of 5 package(s) | PRETTY_NAME="Ubuntu 26.04.1 LTS" | VIRT=none | KERNEL=7.0.0-30-generic | PKG apache2 2.4.66-2ubuntu2.8 | PKG iproute2 6.19.0-1ubuntu1.1 | PKG lsof 4.99.4+dfsg-2build2 | PKG nginx 1.28.3-2ubuntu1.12 | PKG psmisc 23.7-2ubuntu2 22. ok undo: Apache holds port 80 again | Synchronizing state of apache2.service with SysV service script with /usr/lib/systemd/systemd-sysv-install. | Executing: /usr/lib/systemd/systemd-sysv-install enable apache2 | Created symlink '/etc/systemd/system/multi-user.target.wants/apache2.service' → '/usr/lib/systemd/system/apache2.service'. | State Recv-Q Send-Q Local Address:Port Peer Address:Port Process | LISTEN 0 511 *:80 *:* users:(("apache2",pid=5797,fd=4),("apache2",pid=5796,fd=4),("apache2",pid=5793,fd=4)) ------------------------------------------------------------------------------ Commands and what they printed (17) ------------------------------------------------------------------------------ $ sudo DEBIAN_FRONTEND=noninteractive apt-get install -y nginx Reading package lists... Done Building dependency tree... Done Reading state information... Done Solving dependencies... Done The following additional packages will be installed: nginx-common Suggested packages: fcgiwrap nginx-doc The following NEW packages will be installed: nginx nginx-common 0 upgraded, 2 newly installed, 0 to remove and 159 not upgraded. Need to get 656 kB of archives. After this operation, 1,864 kB of additional disk space will be used. Get:1 https://mirror.hetzner.com/ubuntu/packages resolute-updates/main amd64 nginx-common all 1.28.3-2ubuntu1.12 [38.2 kB] Get:2 https://mirror.hetzner.com/ubuntu/packages resolute-updates/main amd64 nginx amd64 1.28.3-2ubuntu1.12 [618 kB] Fetched 656 kB in 0s (1,948 kB/s) Preconfiguring packages ... Selecting previously unselected package nginx-common. (Reading database… 52844 files and directories currently installed.) Preparing to unpack …/nginx-common_1.28.3-2ubuntu1.12_all.deb… Unpacking nginx-common (1.28.3-2ubuntu1.12)… Selecting previously unselected package nginx. Preparing to unpack …/nginx_1.28.3-2ubuntu1.12_amd64.deb… Unpacking nginx (1.28.3-2ubuntu1.12)… Setting up nginx-common (1.28.3-2ubuntu1.12)… Created symlink '/etc/systemd/system/multi-user.target.wants/nginx.service' → '/usr/lib/systemd/system/nginx.service'. Could not execute systemctl: at /usr/bin/deb-systemd-invoke line 148. Setting up nginx (1.28.3-2ubuntu1.12)… Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xeu nginx.service" for details. invoke-rc.d: initscript nginx, action "start" failed. × nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: enabled) Active: failed (Result: exit-code) since Thu 2026-11-19 09:13:00 UTC; 12ms ago Invocation: 293d76a7e3eb437c993bf8450a53d2dc Docs: man:nginx(8) Process: 3665 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 3667 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE) Mem peak: 2M CPU: 31ms Nov 19 09:12:59 web-server nginx[3667]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) Nov 19 09:12:59 web-server nginx[3667]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) Nov 19 09:12:59 web-server nginx[3667]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) Nov 19 09:12:59 web-server nginx[3667]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) Nov 19 09:13:00 web-server nginx[3667]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) Nov 19 09:13:00 web-server nginx[3667]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) Nov 19 09:13:00 web-server nginx[3667]: nginx: [emerg] still could not bind() Nov 19 09:13:00 web-server systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE Nov 19 09:13:00 web-server systemd[1]: [0;1;38:5:185m[0;1;38:5:185mnginx.service: Failed with result 'exit-code'. Nov 19 09:13:00 web-server systemd[1]: Failed to start nginx.service - A high performance web server and a reverse proxy server. Failed to start NGINX in postinst script, please check the logs Processing triggers for man-db (2.13.1-1build1)… Processing triggers for ufw (0.36.2-9build1)… Scanning processes... Scanning linux images... Running kernel seems to be up-to-date. No services need to be restarted. No containers need to be restarted. No user sessions are running outdated binaries. No VM guests are running outdated hypervisor (qemu) binaries on this host. $ systemctl is-active nginx failed $ sudo journalctl -u nginx --no-pager -n 20 | grep -m 2 "Address already in use" Nov 19 09:12:57 web-server nginx[3652]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) Nov 19 09:12:58 web-server nginx[3667]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) $ ss -tlnp 'sport = :80' State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 511 *:80 *:* $ sudo ss -tlnp 'sport = :80' State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 511 *:80 *:* users:(("apache2",pid=2581,fd=4),("apache2",pid=2580,fd=4),("apache2",pid=2564,fd=4)) $ sudo lsof -nP -iTCP:80 -sTCP:LISTEN COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME apache2 2564 root 4u IPv6 17744 0t0 TCP *:80 (LISTEN) apache2 2580 www-data 4u IPv6 17744 0t0 TCP *:80 (LISTEN) apache2 2581 www-data 4u IPv6 17744 0t0 TCP *:80 (LISTEN) $ sudo fuser -v 80/tcp USER PID ACCESS COMMAND 80/tcp: root 2564 F.... apache2 www-data 2580 F.... apache2 www-data 2581 F.... apache2 $ systemctl status apache2 --no-pager | head -n 3 ● apache2.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled) Active: active (running) since Thu 2026-11-19 09:12:05 UTC; 1min 34s ago $ sudo systemctl disable --now apache2 Synchronizing state of apache2.service with SysV service script with /usr/lib/systemd/systemd-sysv-install. Executing: /usr/lib/systemd/systemd-sysv-install disable apache2 Removed '/etc/systemd/system/multi-user.target.wants/apache2.service'. $ sudo ss -tlnp 'sport = :80' State Recv-Q Send-Q Local Address:Port Peer Address:Port Process $ sudo systemctl start nginx $ systemctl is-active nginx active $ sudo ss -tlnp 'sport = :80' State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=4586,fd=5),("nginx",pid=4585,fd=5),("nginx",pid=4584,fd=5)) LISTEN 0 511 [::]:80 [::]:* users:(("nginx",pid=4586,fd=6),("nginx",pid=4585,fd=6),("nginx",pid=4584,fd=6)) $ curl -sI http://localhost | grep -i "^server" Server: nginx/1.28.3 (Ubuntu) $ sudo ss -tlnp 'sport = :22' State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 4096 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=1295,fd=3),("systemd",pid=1,fd=154)) LISTEN 0 4096 [::]:22 [::]:* users:(("sshd",pid=1295,fd=4),("systemd",pid=1,fd=155)) $ systemctl list-sockets --no-pager | grep ssh 0.0.0.0:22 ssh.socket ssh.service [::]:22 ssh.socket ssh.service /run/ssh-unix-local/socket sshd-unix-local.socket - $ sudo systemctl stop nginx && sudo systemctl enable --now apache2 Synchronizing state of apache2.service with SysV service script with /usr/lib/systemd/systemd-sysv-install. Executing: /usr/lib/systemd/systemd-sysv-install enable apache2 Created symlink '/etc/systemd/system/multi-user.target.wants/apache2.service' → '/usr/lib/systemd/system/apache2.service'. ------------------------------------------------------------------------------ The check-your-server script, its full screen before the steps ------------------------------------------------------------------------------ ServerHandbook check, port-already-in-use-ubuntu (proved 2026-11-19) FAIL nginx is running fix: https://serverhandbook.com/kb/port-already-in-use-ubuntu#free-the-port FAIL Apache is not set to start at boot (it would take port 80 again) fix: https://serverhandbook.com/kb/port-already-in-use-ubuntu#free-the-port 0 passed, 2 failed To fix a FAIL, follow the steps in https://serverhandbook.com/kb/port-already-in-use-ubuntu ------------------------------------------------------------------------------ The check-your-server script, its full screen after the steps ------------------------------------------------------------------------------ ServerHandbook check, port-already-in-use-ubuntu (proved 2026-11-19) PASS nginx is running PASS Apache is not set to start at boot (it would take port 80 again) 2 passed, 0 failed ------------------------------------------------------------------------------ The check's source (scripts/live/checks/port-already-in-use-ubuntu.mjs) As it ran. ------------------------------------------------------------------------------ /** * KB fix: "Address already in use" / which process is using a port. The real case: Apache already holds port 80 and * Nginx is installed on the same server, so Nginx cannot start ("bind() to 0.0.0.0:80 failed (98: Address already in * use)"). Steps: see the error; find the owner with ss (and why it needs sudo), lsof and fuser; stop the owner the * right way (its systemd service, not kill); prove Nginx now holds the port; the systemd socket case (port 22 owned by * "systemd", ssh.socket). * * Runs on a fresh server; Apache is installed first (hidden) as the stock state the reader starts from. */ import { bareBox, reportBox } from '../lib.mjs' export const meta = { reader: [ { item: 'nginx is running', cmd: 'systemctl is-active nginx', expect: '^active$', step: 'free-the-port' }, { item: 'Apache is not set to start at boot (it would take port 80 again)', cmd: 'systemctl is-enabled apache2 2>&1', expect: '^(disabled|masked)$|not-found|No such file', step: 'free-the-port', }, ], } const RELEASE = process.env.LIVE_BOX_RELEASE || '24.04' const FORCE_V4 = `echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4 >/dev/null` const check = (ctx) => bareBox(ctx, async ({ sudoUser }) => { const { run, L } = sudoUser() // ── hidden: another web server already on port 80 ── L(`${FORCE_V4} && sudo apt-get update -qq && sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apache2 >/dev/null`, 1800000) const a = L('systemctl is-active apache2') ctx.check('(setup) Apache is installed and running', /^active$/m.test(a), a) // ── 1. the error ──────────────────────────────────────────────────────────────────────── const inst = run('sudo DEBIAN_FRONTEND=noninteractive apt-get install -y nginx', { id: 'install', timeout: 900000 }) ctx.check('the install prints "Failed to start NGINX in postinst script" in the middle, then carries on', /Failed to start NGINX in postinst script/.test(inst.out) && /No VM guests are running outdated hypervisor|Processing triggers/.test(inst.out.split('Failed to start NGINX in postinst script')[1] ?? ''), inst.out) ctx.check('apt itself still exits 0: nothing at the end says it failed', inst.exit === 0, String(inst.exit)) const act = run('systemctl is-active nginx', { id: 'is-active' }) ctx.check('systemctl is-active nginx: failed', /^failed$/m.test(act.out), act.out) const j = run('sudo journalctl -u nginx --no-pager -n 20 | grep -m 2 "Address already in use"', { id: 'journal' }) ctx.check('the journal: bind() to 0.0.0.0:80 failed (98: Address already in use)', /bind\(\) to 0\.0\.0\.0:80 failed \(98: Address already in use\)/.test(j.out), j.out) // ── 2. who holds the port ─────────────────────────────────────────────────────────────── const ss1 = run("ss -tlnp 'sport = :80'", { id: 'ss-nosudo' }) ctx.check('ss without sudo: the port is LISTEN but no process is named', /LISTEN/.test(ss1.out) && !/users:/.test(ss1.out), ss1.out) const ss2 = run("sudo ss -tlnp 'sport = :80'", { id: 'ss-sudo' }) ctx.check('sudo ss: users:(("apache2",pid=…)) on port 80', /users:\(\("apache2",pid=\d+/.test(ss2.out), ss2.out) const lsof = run('sudo lsof -nP -iTCP:80 -sTCP:LISTEN', { id: 'lsof' }) ctx.check('lsof names apache2 listening on *:80', /^apache2\s+\d+\s+root\s/m.test(lsof.out) && /\*:80 \(LISTEN\)/.test(lsof.out), lsof.out) const fu = run('sudo fuser -v 80/tcp', { id: 'fuser' }) ctx.check('fuser -v lists apache2 on 80/tcp', /80\/tcp/.test(fu.out) && /apache2/.test(fu.out), fu.out) const sv = run('systemctl status apache2 --no-pager | head -n 3', { id: 'which-service' }) ctx.check('the process belongs to the apache2 service: active (running)', /apache2\.service/.test(sv.out) && /active \(running\)/.test(sv.out), sv.out) // ── 3. free the port the right way, then start Nginx ──────────────────────────────────── const dis = run('sudo systemctl disable --now apache2', { id: 'disable-apache' }) ctx.check('disable --now stops Apache and removes it from boot', /Removed/.test(dis.out) || dis.exit === 0, dis.out) const ss3 = run("sudo ss -tlnp 'sport = :80'", { id: 'ss-free' }) ctx.check('port 80 is free: ss prints only its header', !/LISTEN/.test(ss3.out), ss3.out) run('sudo systemctl start nginx', { id: 'start-nginx' }) const act2 = run('systemctl is-active nginx', { id: 'is-active-after' }) ctx.check('nginx is active', /^active$/m.test(act2.out), act2.out) const ss4 = run("sudo ss -tlnp 'sport = :80'", { id: 'ss-nginx' }) ctx.check('sudo ss: nginx now holds port 80 (IPv4 and IPv6)', /users:\(\("nginx",pid=\d+/.test(ss4.out) && /0\.0\.0\.0:80/.test(ss4.out) && /\[::\]:80/.test(ss4.out), ss4.out) const cu = run('curl -sI http://localhost | grep -i "^server"', { id: 'curl' }) ctx.check('curl: Server: nginx', /^Server: nginx/im.test(cu.out), cu.out) // ── 4. the systemd socket case ────────────────────────────────────────────────────────── const s22 = run("sudo ss -tlnp 'sport = :22'", { id: 'ss-22' }) ctx.check('port 22 lists "systemd" pid=1 as well as sshd: socket activation (ssh.socket)', /"systemd",pid=1,/.test(s22.out), s22.out) const sock = run('systemctl list-sockets --no-pager | grep ssh', { id: 'list-sockets' }) ctx.check('systemctl list-sockets: ssh.socket listens on port 22', /ssh\.socket/.test(sock.out) && /:22\b/.test(sock.out), sock.out) // ── end state ─────────────────────────────────────────────────────────────────────────── const e1 = L('systemctl is-active nginx') ctx.check('(nginx is running at the end of the steps)', /^active$/.test(e1.trim()), e1, { reader: { cmd: 'systemctl is-active nginx', expect: '^active$' }, }) const e2 = L('systemctl is-enabled apache2 2>&1') ctx.check('(Apache is not set to start at boot at the end of the steps)', /^(disabled|masked)$|not-found|No such file/m.test(e2), e2, { reader: { cmd: 'systemctl is-enabled apache2 2>&1', expect: '^(disabled|masked)$|not-found|No such file' }, }) ctx.stepsDone() reportBox( ctx, L, `A fresh Ubuntu ${RELEASE} server (${process.env.LIVE_VPS ? 'a rented cloud server, rebuilt to the provider’s stock image' : 'a VM from Ubuntu’s cloud image'}) with Apache already installed and running on port 80, reached over SSH as the sudo user deploy. Nginx is then installed on the same server.`, ['nginx', 'apache2', 'iproute2', 'lsof', 'psmisc'], ) // ── undo ──────────────────────────────────────────────────────────────────────────────── const un = run('sudo systemctl stop nginx && sudo systemctl enable --now apache2', { id: 'undo' }) const back = L("sudo ss -tlnp 'sport = :80'") ctx.check('undo: Apache holds port 80 again', /"apache2"/.test(back), `${un.out}\n${back}`) }) export default check