How To Install Valet Linux From Scratch

How To Install Valet Linux From Scratch

In this post, we will set our development environment with PHP, Laravel, MariaDB/MySQL, and Valet Linux; yeah, the exclusive macOS development tool working on Linux ;D.

Install MariaDB

mariadb.png

To install MariaDB, open the terminal, and type the following command:

1sudo apt install mariadb-server mariadb-client

After the installation concludes, test the following commands in that specific order to check if the installation was successful:

1sudo systemctl stop mariadb.service
2sudo systemctl start mariadb.service
3sudo systemctl enable mariadb.service

After verifying the installation was successful, we need to run the mysql_secure_installation, to set MariaDB correctly in our development environment:

1sudo mysql_secure_installation

After you execute the command, please answer the following questions:

Restart MariaDB’s service:

1sudo systemctl restart mariadb.service

Then, access to MariaDB through the terminal:

1sudo mariadb -u root -p

Or

1sudo mysql -u root -p

Remember that MariaDB is fully compatible with MySQL ;).

We need to write the password that we defined in the mysql_secure_installation process in the following SQL statement. This also helps to access MariaDB without sudo on the terminal:

1GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY "your_password";

Now exit from MariaDB by pressing: Ctrl+C on the terminal.

Install PHP on Linux

php.png

This is very straight; forward we only need to run the following command:

1sudo apt install php libapache2-mod-php php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-mysql php-cli php-mcrypt php-zip php-curl php-sqlite3 php-pgsql

And then open php.ini file to make some adjustments:

1sudo nano /etc/php/7.X/apache2/php.ini

Modify the following variables:

1memory_limit = 256M
2upload_max_filesize = 64M
3cgi.fix_pathinfo=0

We save the changes by pressing Ctrl+O and exit with Ctrl+X.

Install Laravel on Linux

laravel.png

We need composer installed in our system to do that, we can install it with:

1sudo apt install composer

And now install Laravel:

1composer global require laravel/installer

Now we need to add Laravel in our $PATH variable, to make “laravel” a recognizable command:

1sudo nano .bashrc

If you are using zsh:

1sudo nano .zshrc

Scroll down to the last line of the file and add the following:

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

We save the changes by pressing Ctrl+O and exit with Ctrl+X.

And to force our shell to read the changes, execute:

1source .bashrc

If you are using zsh:

1source .zshrc

Now we can create a Laravel app:

1laravel new laravel-app

If you want to use Laravel 7, try with the following commands and ensure that the PHP version you installed is PHP 7 and not PHP 8:

1composer create-project laravel/laravel=^7 laravel-app --prefer-dist

If it does not work try replacing the ^ with >:

1composer create-project laravel/laravel=>7 laravel-app --prefer-dist

It should create a Laravel app without problems.

Install Valet Linux

valet.png

Finally, execute:

1composer global require cpriego/valet-linux

If it throws an error, please execute:

1sudo apt install php-curl

Try again and now it should work.

Now execute the installation process:

1valet install

This also could throw an error, if that’s the case, please force the shell to read the changes as we did before:

1source .bashrc

If you are using zsh:

1sudo nano .zshrc

We need to ensure that we update our $PATH environment variable correctly on the previous steps.

Now valet should throw an error about missing dependencies, to solve that we simply run:

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

Now it should install valet correctly:

1valet install

But if you have another error related with nginx, you need to stop the service that is running in the same port as nginx, if it’s apache who is provoking this problem you can simply stop the apache’s service:

1sudo systemctl stop apache2.service

And try again:

1valet install

To verify everything is ok, run:

1ping valet.test

And after a few seconds it should say something like this:

1X packets transmited, X received...

If that’s the case, congrats! you successfully installed Valet Linux!

Now we need to set the directory where we are going to create Laravel or PHP projects:

1cd directory/where/you/are/going/to/work

And execute:

1valet park

Now create a folder called: phpinfo, inside the create a file called index.php and in the file, we can write something to check its working:

1<?php echo phpinfo();

And finally, we write the following URL in our browser:

http://phpinfo.test/index.php

It should display info about PHP without errors.

You can custom the domain if you don’t like .test with:

1valet domain dev

And now to get access you need to change your current URL with the following: http://phpinfo.dev/index.php

And that’s it, hope you enjoy it, if you want to see how to do it in fedora and manjaro, please comment it :D.