Prerequisites:
You have to do the following tasks before starting the installation of Valet.
A. Install a Laravel project
B. Install the required dependencies
$ sudo apt-get install jq
$ sudo apt-get install xsel
$ sudo apt-get install libnss3-tools
$ sudo apt install nginx
C. Update the composer
Install Valet in Laravel:
Run the following command to download the valet using the composer.
Run the following command to install the valet on Ubuntu.
|| 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 disable apache2
Run the following command to start the Nginx server.
Run the following command to restart the network manager.
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.
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.
$ 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.
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.
You can run the following ping command to test the site is alive or not.
The output shows that the site is alive.
Now, run the following URL from the browser to test that it is working or not.
Run the following command to make the site insecure and run the project using the URL, http://laravelpro.test.
You can change the default domain of the valet. The following valet command will change the .test domain .bd domain.
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.
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
0 Comments