Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Last active January 2, 2024 18:42
Show Gist options
  • Save Shelob9/f981e8fee4e80aec383442df7838de7e to your computer and use it in GitHub Desktop.
Save Shelob9/f981e8fee4e80aec383442df7838de7e to your computer and use it in GitHub Desktop.

Install PHP 8.1, node 16 and Docker in Ubuntu.

These scripts can be run with the following commands, by a super user. This installs a lot of stuff, read first.

You can add -s -- --dry-run to then end to do a dry run first.

These are tested on an ec2 instance running vscode remote

Usage

  • Set up vscode remote
  • Run all these scripts
  • Reboot instance
  • git clone ...
  • docker-compose up -d should work now
    • Also PHP, node, git, ssh.

Scripts

PHP 8.1 And Composer

This installs PHP 8.1, extensions and composer. It should output composer's help.

curl -fsSL https://gist.githubusercontent.com/Shelob9/f981e8fee4e80aec383442df7838de7e/raw/427f097ae2b4c66e7ad013407ae8fe858bb849e6/php81.sh | sh

Node 20, with nvm. Also, npm and yarn.

curl https://gist.githubusercontent.com/Shelob9/f981e8fee4e80aec383442df7838de7e/raw/c799942bca5ab2bc5f2167dfdd49e00278ab5f9c/nvm20.sh -fsSL  | sh

Docker

curl -fsSL  https://gist.githubusercontent.com/Shelob9/f981e8fee4e80aec383442df7838de7e/raw/b4359b698c6be584d259dac68ae348d4e6e9bf8a/docker.sh | sh

Set permissions for Docker

If you try and run docker-compose up or whatever now, you will likely run into a Docker permissions error, code 13.

This will make the user ubuntu a super user. That is the user that is running Docker.

curl -fsSL  https://gist.githubusercontent.com/Shelob9/f981e8fee4e80aec383442df7838de7e/raw/b4359b698c6be584d259dac68ae348d4e6e9bf8a/fix-docker-permissions.sh | sh

Expected output: Adding user ubuntu to group docker

git and ssh

This sets up git and creates and SSH key pair. It outputs the public key

Make sure to change email@email.email to your email and to your name. Keep the double quotes around each.

curl -fsSL https://gist.githubusercontent.com/Shelob9/f981e8fee4e80aec383442df7838de7e/raw/b4359b698c6be584d259dac68ae348d4e6e9bf8a/git.sh | bash -s "<email@email.email>" "<name>"

Expected output is the ssh public key, copy that and then add a new ssh key on Github.

#https://www.simplilearn.com/tutorials/docker-tutorial/how-to-install-docker-on-ubuntu
sudo apt -y update
sudo apt -y install docker.io
sudo snap install docker
docker --version
#https://exerror.com/docker-errors-dockerexception-error-while-fetching-server-api-version-connection-aborted-connectionrefusederror61-connection-refused/
sudo gpasswd -a $USER docker
newgrp docker
sudo su $USER
#!/bin/bash
EMAIL=$1
NAME=$2
#ssh-keygen
#https://stackoverflow.com/a/43235320/1469799
ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa <<< y
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
git config --global user.name $NAME
git config --global user.email $EMAIL
git config --global core.autocrlf false
cat ~/.ssh/id_rsa.pub
echo "https://github.com/settings/ssh/new"
#!/bin/bash
# Setup Node 16 with nvm, so you can switch to other versions
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install 16
node -v
npm install --global yarn
npm -v
yarn -v
#!/bin/bash
# Setup Node 20 with nvm, so you can switch to other versions
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install 20
node -v
npm install --global yarn
npm -v
yarn -v
#!/bin/bash
# PHP 8.1
sudo apt -y update
sudo apt install -y --no-install-recommends php8.1
php -v
sudo apt-get install -y php8.1-cli php8.1-common php8.1-mysql php8.1-zip php8.1-gd php8.1-mbstring php8.1-curl php8.1-xml php8.1-bcmath
sudo apt-get install -y php8.1-curl php8.1-zip php8.1-simplexml
# Composer
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
HASH=`curl -sS https://composer.github.io/installer.sig`
php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
composer
sudo apt-get install -y php8.2-cli php8.2-common php8.2-mysql php8.2-zip php8.2-gd php8.2-mbstring php8.2-curl php8.2-xml php8.2-bcmath
sudo apt-get install -y php8.2-curl php8.2-zip php8.2-simplexml
sudo apt -y update
sudo apt -y install postgresql postgresql-contrib
sudo systemctl start postgresql.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment