DEV Community

Cover image for Elementary OS - Dev Environment Setup
skino
skino

Posted on

Elementary OS - Dev Environment Setup

Overview

So every now and then i see something that catches my eye. Recently that seems to be Linux Distributions, over the last few months i have changed my distribution's a few times to try and find one i'm comfortable with. I moved from my iMac (getting a bit sluggish) to Ubuntu originally and it worked but i didn't "enjoy it", i then tried Manjaro, then Pop!_OS and then finally thought id have a go with Elementary OS.

So far i am really enjoying it! it feels a bit "Mac'ish", Looks nice and feels quick!

But compared to Ubuntu its a little bit different with the Setup of the dev environment, so i thought id write up a little tutorial on setting a Laravel Dev Environment on Elementary OS.

Let's get started!

So as with any tutorial i do with Linux, we start with an update/upgrade.

sudo apt update
sudo apt upgrade

Enter fullscreen mode Exit fullscreen mode

If this is a fresh install you're setting up on, it could take few more mins than usual, Any messages you get for Diskspace just accept them.

After this operation, 36.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Enter fullscreen mode Exit fullscreen mode

Install Git!

Git is something use a lot anyway so its worth installing it. works from the IDE and normal terminals when working so it just helps.

sudo apt install git

Enter fullscreen mode Exit fullscreen mode

When the install is finished type git --version in you're terminal and you should see something like: git version 2.25.1

Boom! GIt is installed!

Time to install ZSH

This is a personal preference for me, but i cant recommend the terminal application enough, it cleans up your terminal window to a nice clean output.

sudo apt install zsh

Enter fullscreen mode Exit fullscreen mode

Now you can stick with ZSH in its basic form, or you can install PowerLineLevel10k later on, which again id recommend as there is a shed load of options to use. but for the purpose of this tutorial... i'm just doing the basic.

Install PHP and Relevant dependencies.

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y php8.0

Enter fullscreen mode Exit fullscreen mode

And once that's done you can check the version by typing php -v

➜  ~ php -v                                        
PHP 8.0.10 (cli) (built: Aug 26 2021 15:50:07) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.10, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.10, Copyright (c), by Zend Technologies

Enter fullscreen mode Exit fullscreen mode

Laravel PHP Requirements

The Laravel framework requires some PHP Dependencies, these can be installed in a single command. The Dependencies are;

  • OpenSSL
  • Common
  • BCMath
  • Curl
  • mbstring
  • MySQL
  • XML
  • zip
  • sqlite3

If you go to the Laravel website there will be a requirement for php-json also. But, with PHP 8 it comes with it, so there is no extra install to complete. This will also include some of the Valet Dependencies.

The command for all of these is as follows. (Type 'y' to the question about disk space)

sudo apt install openssl php8.0-cli php8.0-curl php8.0-mbstring php8.0-mcrypt php8.0-xml php8.0-zip php8.0-common php8.0-bcmath php8.0-mysql php8.0-sqlite3

Enter fullscreen mode Exit fullscreen mode

Install Composer

I have no idea why but on my windows machine i used to learn dev work on i always struggled to get composer working properly. On Linux and macOS it just seemed easier...

The following commands needs to be run in terminal, I tend to run them one at a time just in case, but as far as i'm aware you can run them all at the same time.

Note: hash_file command is subject to change, so it might be worth checking for the latest command for this here.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

Enter fullscreen mode Exit fullscreen mode

Now lets make it Globally accessible so you can just run composer <Your Command> Instead of php composer.phar <your command>.

You need to move the composer.phar file to a location that is part of your systems path. In my case running Elementary 6 its /usr/local/bin/composer The command for this is simply;

sudo mv composer.phar /usr/local/bin/composer

Enter fullscreen mode Exit fullscreen mode

now if you type composer --version You should get your current composer version.

Now we need to add composer to our global path so ZSH can use it correctly as well. Open the ZSH config;

nano ~/.zshrc

Enter fullscreen mode Exit fullscreen mode

Paste the following lines at the bottom of the file;

PATH=$HOME/.config/composer/vendor/bin:~/.composer/vendor/bin:$PATH
export PATH

Enter fullscreen mode Exit fullscreen mode

Just above this command add a shortcut to a folder you will make in a second (if you want to). i add an alias to my zshrc file called wd and this will Change Directory to ~/www add the the below command BEFORE the PATH export.

alias wd="cd ~/www"

Enter fullscreen mode Exit fullscreen mode

Ctrl + X to exit and Save modified buffer? y and hit enter.

Now apply them changes by typing:

source ~/.zshrc

Enter fullscreen mode Exit fullscreen mode

Lets install Valet Linux

Valet is awesome, early in my Laravel journey i used homestead which is also very powerful but can be cumbersome. Average memory usage could be a gig or two whereas Valet..... 7mb..... Yep 7MB, you can park your domains so you can use ANY folder on your system you want for ease of use. I believe Valet was originally designed just for macOS but has since been ported to both Windows and Linux.

If you checkout the requirements for Valet-Linux here you will see there are a number of Dependencies required. You'll also note that we have installed the PHP Extensions and Optional Packages already when we first installed PHP. we now just need to run the following command to grab the OS packages required for Linux Valet:

Network Manager tools for Valet

sudo apt-get install network-manager libnss3-tools jq xsel

Enter fullscreen mode Exit fullscreen mode

one the prerequisites have installed it's time to time to composer require it from the Git repository:

composer global require cpriego/valet-linux

Enter fullscreen mode Exit fullscreen mode

Once that has run you need to install the package like so:

valet install

Enter fullscreen mode Exit fullscreen mode

Once you press enter to this it will start running through checks for the Valet installations. In my installation nginx, php7.4-fpm, dnsmasq and inotify-tools were not installed and Valet automatically pulled these down and installed for me.

Once its finished you should have received: Valet Installed successfully!

Time to create our websites folder. My preferred sites folder is www. so lets make that in the root:

mkdir ~/www

Enter fullscreen mode Exit fullscreen mode

Now we have created our websites folder we need to tell Valet that's where our sites will be hosted locally, With windows and homestead you need to add the directories manually to the Homestead.yaml but with Valet it couldn't be any easier!

cd ~/www
valet park

Enter fullscreen mode Exit fullscreen mode

That's it, now when you add a site to that folder it will generate the necessary dns records and links so you can run something like: raspada-blog.vm And it will load the site.

Install MySQL

We could actually just go ahead and install the Laravel package but nine times out of ten we will need a MySQL DB so lets get that done now.

sudo apt install mysql-server -y

Enter fullscreen mode Exit fullscreen mode

Remember to just accept the installation message for MySQL.

Now the next bit is entirely up to you, however i will say that i select Y to everything in the next installation process. And when it gets to the Password Tool, select 0 as your complexity.

sudo mysql_secure_installation

Enter fullscreen mode Exit fullscreen mode

If you're, installing on a server you want to add a higher level password for security reason... but locally, it really doesn't matter.

And that is it, MySQL is installed and you can check the installation with this command:

systemctl status mysql.service

Enter fullscreen mode Exit fullscreen mode

And you should see the following output.

➜  ~ systemctl status mysql.service
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2021-09-12 15:08:29 UTC; 2h 24min ago
    Process: 800 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
   Main PID: 926 (mysqld)
     Status: "Server is operational"
      Tasks: 37 (limit: 18755)
     Memory: 418.1M
     CGroup: /system.slice/mysql.service
             └─926 /usr/sbin/mysqld

Enter fullscreen mode Exit fullscreen mode

So were not using the root user in MySQL by default were going to create another user with all privileges, including grant privileges.

To open up MySQL Command line Type:

sudo mysql

Enter fullscreen mode Exit fullscreen mode

Now you will be faced with the mysql> prompt now lets create a user.

CREATE USER 'raspadatest'@'localhost' IDENTIFIED BY 'ThisIsMyNewPassword12!';

Enter fullscreen mode Exit fullscreen mode

That's the user created! now lets grant all privileges, do this by typing the following:

GRANT ALL PRIVILEGES ON *.* TO 'raspadatest'@'localhost'; 

Enter fullscreen mode Exit fullscreen mode

That's our new user with rights to all tables we currently have but will also create in the future.

We need to flush privileges now:

FLUSH PRIVILEGES;

Enter fullscreen mode Exit fullscreen mode

to test it we can exit out the MySQL prompt by typing:

mysql> exit;

Enter fullscreen mode Exit fullscreen mode

And that's it. which ever client you decide to use, login with what ever you created above on localhost or 127.0.0.1 and you're good to go.

Now if you want to manage the DB's with a GUI instead of going through command line you can install MySQL Workbench or phpMyAdmin i prefer to use DataGrip from JetBrains. I wont go through the specifics of that as it will depend on what you want to install. But if your following along and using Datagrip also you can simply run:

sudo snap install datagrip --classic

Enter fullscreen mode Exit fullscreen mode

Install Laravel!

This bit is just a single command...

composer global require laravel/installer

Enter fullscreen mode Exit fullscreen mode

And that's it, CD into your website directory and run the:

laravel new *site* - change site to you site name

Enter fullscreen mode Exit fullscreen mode

running the above command will add the relevant links so you can run site.test and you will be directed to your new application.

All done, you now have a fully functioning Laravel development server locally with Elementary OS.

Other things to do

Make sure you setup your local .env if your pulling from Git.... I stupidly spent around an hour wondering why i couldn't access my site! its because i didn't have an .env properly configured for local environment.

Another thing i tend to do is change the domain from test to .vm this is easily done by running the following command:

valet domain vm

Enter fullscreen mode Exit fullscreen mode

Apache2 still showing up when you try access one of your sites? This happened with me and i needed to run the following to stop Apache2 from startup up with system reboot:

sudo systemctl disable apache2 && sudo systemctl stop apache2

Enter fullscreen mode Exit fullscreen mode

That should stop Apache2 from starting when the machine boots up, we now need to get nginx starting up with the following command:

sudo systemctl enable nginx

Enter fullscreen mode Exit fullscreen mode

Need to install NodeJS? use the following two commands one for NodeJS itself and also the build essentials.

curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs

Enter fullscreen mode Exit fullscreen mode

and

apt-get install -y build-essential

Enter fullscreen mode Exit fullscreen mode

All done!

So far this has been my biggest Blog post so i hope it was all good, if you have any suggestions please drop me a message :D

Final Word

I hope this little walk through has has been helpful for you all!.

if you found this post useful please consider following me on twitter @skino2020 and if you found it really helpful consider buying me a coffee here.

Raspada-Blog

I post on my blog primarily and share the posts via API, please check out Raspada-Blog for more posts and information. If you have any questions please message me on twitter or use my website contact form.

Top comments (3)

Collapse
 
raibtoffoletto profile image
Raí B. Toffoletto

There's also a meta package called "elementary-sdk", you get git gcc vala make build essentials etc. It's a quick way to get basic dev tools 😉.

I'm not a Laravel developer so I don't know the needs, but I'm wandering how's different from Ubuntu? Since elementary's base is 20.04?

Nice article btw 🎉

Collapse
 
skino2020 profile image
skino

IM also finishing up one for Manjaro Linux which is quite a bit different.

Collapse
 
skino2020 profile image
skino

The installations are very similar. The Elementary OS one is an update to the Ubuntu one i did last year lol.