Skip to main content

Linux

Setting up a linux development machine

The following instructions will work on Ubuntu or closely related distros like Pop OS. They will also mostly work on Debian-based distros with some slight tweaks.

Install Visual Studio Code

  • Download from software store or from vs code website
  • Install the Settings Sync extension
  • Ask a member of the dev team to upload their settings as a public gist
  • Press Shift + Alt + D
  • From the menu that appears, click ‘download public gist’
  • Enter the gist ID given to you by the dev team member
  • Wait for all settings and extensions to be installed

Install required tools, packages and languages

PHP

# Add the Ondrej PPA:

$ sudo add-apt-repository ppa:ondrej/php
$ sudo add-apt-repository ppa:ondrej/nginx

# Assuming you are using nginx, install php fpm for the current version of PHP you are working on
sudo apt install php8.0-fpm

Curl

sudo apt install curl

Composer

To install Composer globally, first run the following commands from your terminal:
cd ~
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=composersudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
Add composer to your path:
echo "export PATH=$PATH:$HOME/.config/composer/vendor/bin" >> ~/.bashrc
source ~/.bashrc

Git

sudo apt install git

MySQL

Install MySQL server:
sudo apt install mysql-server
Before you can use MySQL, you will need to set up authentication. First run:
sudo mysql_secure_installation
Follow the steps to set up your root user. How secure you want this to be is to up to you - I set it to lowest as my local databases do not store any critical info. It’s better to create a new user and grant it all permissions and use the new user to manage your databases instead. To do so, login to the MySQL terminal with:
sudo mysql -u root -p
Then enter your system password if not yet authenticated in the current terminal session followed by the password you set up for your root user. To create a user called ‘admin’ with a password of ‘admin123’ for example, run the following command:
CREATE USER 'admin'@'localhost' IDENTIFIED BY 'admin123'
To grant all necessary privileges to your admin user, run:
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;

Table Plus

You can use any application you like to manage your MySQL databases, but this is currently our preferred option. To install Table Plus on Linux, follow these steps:
# Add TablePlus gpg key
wget -O - -q http://deb.tableplus.com/apt.tableplus.com.gpg.key | sudo apt-key add -

# Add TablePlus repo
sudo add-apt-repository "deb [arch=amd64] https://deb.tableplus.com/debian tableplus main"

# Install
sudo apt install tableplus
Table Plus should then be accessible in your list of installed applications.

Node.js

You can install the latest version of Node.js by running:
sudo apt install nodejs
However, you will not be able to easily switch between Node versions using this method. An alternative is to use NVM (Node.js Version Manager) which will allow you to run multiple isolated versions of Node.js. You can download nvm from the project’s GitHub page using this script:
curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.37.2/install.sh -o install_nvm.sh
Take note of the version number on the GitHub page - it will likely be different to what’s shown above, so replace the version number in the script with the latest version. To install, run:
bash install_nvm.sh
Close and re-open your terminal, you should now be able to access nvm by typing nvm into the terminal. You can install the latest version of node by running:
nvm install node
You can install a specific version by running
# Replace 8.0.0 with the version you are wanting to install
nvm install 8.0.0

# Run this command to change the active version of node to the version you just installed
nvm use 8.0.0

Node package manager

You will also need npm to install and manage packages as well as to run scripts. You can install this by running:
sudo apt install npm

Other required PHP extensions

You will need to manually install some PHP extensions by running the following command:
# Replace [extname] with the name of the extension
sudo apt install php-[extname]
Here are some extensions you might need to install:
  • bcmath
  • ctype
  • curl
  • fileinfo
  • gd
  • json
  • mbstring
  • mysql
  • pdo
  • sqlite-3
  • tokenizer
  • xml
  • zip

Redis

To install Redis, run the following command:
sudo apt install redis-server
You can tell if redis is working by pinging it:
redis-server ping
You should see “PONG” returned in the terminal if all worked out correctly.

Valet

Valet is a Laravel development environment for macOS. However, there is a fork of it which was created for Linux - Valet Linux. To install Valet with Composer, run:
composer global require cpriego/valet-linux
You can then install it with:
valet install
Missing Valet requirements
If you get a message about missing Valet requirements, consult this documentation page for more info. On my system, I needed to run the following before running valet install again:
sudo apt-get install network-manager libnss3-tools jq xsel

Issues with Nginx

If you have a 502 gateway error with any of the applications that you’re developing, open the nginx config of your site: i.e. For ptchub.test you’ll find the config at ~/.config/valet/Nginx/ptc-hub.test
  • Within the second server block, copy the following before the closing curl bracket
fastcgi_connect_timeout 75;
fastcgi_send_timeout 600;
fastcgi_read_timeout 600;
fastcgi_buffers 32 256k;
fastcgi_buffer_size 512k;
  • Restart valet sudo valet restart