> ## Documentation Index
> Fetch the complete documentation index at: https://sol.advantagelearn.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Linux

# 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](https://code.visualstudio.com/download)
* Install the Settings Sync extension
* Ask a member of the dev team to upload their settings as a public gist
* Press S*hift + 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

```bash theme={null}
# 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

```bash theme={null}
sudo apt install curl
```

#### Composer

To install Composer globally, first run the following commands from your terminal:

```bash theme={null}
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:

```bash theme={null}
echo "export PATH=$PATH:$HOME/.config/composer/vendor/bin" >> ~/.bashrc
source ~/.bashrc
```

#### Git

```bash theme={null}
sudo apt install git
```

#### MySQL

Install MySQL server:

```bash theme={null}
sudo apt install mysql-server
```

Before you can use MySQL, you will need to set up authentication. First run:

```bash theme={null}
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:

```bash theme={null}
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:

```sql theme={null}
CREATE USER 'admin'@'localhost' IDENTIFIED BY 'admin123'
```

To grant all necessary privileges to your admin user, run:

```sql theme={null}
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:

```bash theme={null}
# 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.

<aside>
  💡 Make sure you have php-mysql extension installed, or else you will not be able to connect to the database from your Laravel application
</aside>

#### Node.js

You can install the latest version of Node.js by running:

```bash theme={null}
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](https://github.com/nvm-sh/nvm) using this script:

```bash theme={null}
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 theme={null}
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:

```bash theme={null}
nvm install node
```

You can install a specific version by running

```bash theme={null}
# 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:

```bash theme={null}
sudo apt install npm
```

#### Other required PHP extensions

You will need to manually install some PHP extensions by running the following command:

```bash theme={null}
# 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:

```bash theme={null}
sudo apt install redis-server
```

You can tell if redis is working by pinging it:

```bash theme={null}
redis-server ping
```

You should see "PONG" returned in the terminal if all worked out correctly.

#### Valet

[Valet](https://laravel.com/docs/8.x/valet) is a Laravel development environment for macOS. However, there is a fork of it which was created for Linux - [Valet Linux](https://cpriego.github.io/valet-linux/). To install Valet with Composer, run:

```php theme={null}
composer global require cpriego/valet-linux
```

You can then install it with:

```bash theme={null}
valet install
```

##### Missing Valet requirements

If you get a message about missing Valet requirements, [consult this documentation page](https://cpriego.github.io/valet-linux/requirements) for more info. On my system, I needed to run the following before running **valet install** again:

```bash theme={null}
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`
