Use of Laravel Valet

If you want to check how your Laravel project works online without publishing the project on any real server then you can use Valet or Homestead package to develop a visualized development environment. Homestead is used to develop a fully visualized Linux development environment with Nginx configuration and it consumes more resources. If you want to develop a fast local development environment with minimum resources then the Valet package is a good choice. It works with the Nginx web server. How you can install Valet on Ubuntu and use it to run your Laravel project online for certain times are shown in this article.

Prerequisites:

You have to do the following tasks before starting the installation of Valet.

A. Install a Laravel project

$ composer create-project --prefer-dist laravel/laravel latavelpro

B. Install the required dependencies

$ sudo apt-get install php7.4-curl
$ sudo apt-get install jq
$ sudo apt-get install xsel
$ sudo apt-get install libnss3-tools
$ sudo apt install nginx

C. Update the composer

$ sudo composer self-update --stable

Install Valet in Laravel:

Run the following command to download the valet using the composer.

$ composer global require cpriego/valet-linux

Run the following command to install the valet on Ubuntu.

$ test -d ~/.composer && bash ~/.composer/vendor/bin/valet install
|| bash ~/.config/composer/vendor/bin/valet install

If the valet is installed successfully then the following output will appear.

Run the following commands to stop and disable the apache2 server.

$ sudo systemctl stop apache2
$ sudo systemctl disable apache2

Run the following command to start the Nginx server.

$ sudo systemctl start nginx

Run the following command to restart the network manager.

$ sudo service network-manager restart

Restart the terminal and browser before using the valet commands.

Using Valet commands:

Many commands exist in the Valet package to check the current status, start and stop the daemon, add or remove project directory, uninstall valet, etc. The list of commonly used Valet commands is shown below.

Commands purpose
valet start Start the valet daemon.
valet stop Stop the valet daemon.
valet restart Restart the valet daemon.
valet link Create the link of a particular Laravel project.
valet unlink Remove the previously created project link.
valet links Display the existing links created by the valet.
valet secure Make the site secure and show the URL with https://.
valet unsecure Make the site insecure and show the URL with http://.
valet status Show the current status of the valet daemon.
Valet domain domain-name Change the domain
valet share Share the local site publicly and test how it works online.
valet uninstall Remove the valet permanently.

The uses of some necessary Valet commands are shown in the next section.

Check the status:

the status command is used to check the current status of the Valet. Run the following command from the terminal.

$ valet status

The following output will appear if the fpm and Nginx are running and valet is working properly.

Serve the site:

Two valet commands can be used to serve any Laravel site. These are park and link. The uses of the link command are shown below.

link command:

Create a new folder named myprojects and go to the folder that will work as a Valet path. Create a new Laravel project or copy any existing Laravel project folder inside this folder. An existing Laravel project is copied inside the folder here. Go to the Laravel project folder and run the link command to register the folder in the Valet path.

$ mkdir myprojects
$ cd myprojects
$ cp -r /var/www/html/laravelpro laravelpro
$ cd laravelpro
$ valet link

The following output will appear after running the commands.

Run the following command to check the list of symbolic links with URLs created by the valet.

$ valet links

The following output will appear if the link for the Laravel project is created. The default domain of the valet URL is .test. The Laravel project name is set as Site value. The URL value is generated by adding the default domain with the project name. The Path stores the project folder location.

Run the following valet command to make the site secure.

$ valet secure

You can run the following ping command to test the site is alive or not.

$ ping laravelpro.test

The output shows that the site is alive.

Now, run the following URL from the browser to test that it is working or not.

https://laravelpro.test/

Run the following command to make the site insecure and run the project using the URL, http://laravelpro.test.

$ valet unsecure

You can change the default domain of the valet. The following valet command will change the .test domain .bd domain.

$ valet domain us

Now, you can check the following URL from the browser to test the domain.

http://laravelpro.bd

Share the site:

One of the important purposes of using Valet is to test how the site works online on different types of devices running from the local server. The site can be shared in many ways using valet. The site is shared by Ngrok by default. Run the following command to share the Laravel site with the world.

$ valet share

The following output will appear if the site is shared properly. The following information shows that the site is online for 8 hours. The site can be accessed from anywhere by using the URL, http://69763ffe9768.ngrok.io.

The following output will appear if the URL is executed in the browser of any Internet-connected device.

Conclusion:

Sometimes it is very important to check the Laravel project is working properly or not on various types of devices like mobile, tablet, etc. before publishing the site in the real server. Laravel valet makes this task easier by using the share command. The site can be tested online easily by this valet feature. The way to install and use the different Laravel valet commands are explained in this article for helping the Laravel users to test their Laravel sites easily.



from Linux Hint https://ift.tt/3igEC5R

Post a Comment

0 Comments