Setting up Localhost on OSX Mojave for PHP Development

Laravel Valet? What is it?

I am using Laravel Valet to install Nginx and a domain masking service which will allow us to access our localhost address (127.0.0.1) from a domain something like mysite.test.

Valet is helpful for people who have a very low configuration laptop or PC. I use MacBook Air with 8GB RAM and 128GB SSD. I have to keep my RAM available for Chrome, so I can’t provide enough resource for the local server. This is why I use Valet instead of Xampp or Mamp. It just uses 7 MB of RAM and really fast compared to any other local server solution and I really love the domain masking and SSL feature.

You can read more about Laravel Valet here https://laravel.com/docs/5.8/valet

Steps for zombies

  1. /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  2. brew install php
  3. brew install mariadb
  4. Download composer from here https://getcomposer.org/installer
  5. Rename the file to composer.phar
  6. php composer.phar
  7. mv composer.phar /usr/local/bin/composer
  8. composer global require laravel/valet
  9. export PATH=$PATH:~/.composer/vendor/bin
  10. Go to the folder you will be using as your development directory
  11. valet install
  12. valet park

Explanation of what each command does

1. I have installed Home Brew. It helps to install and remove programs easily. The commands you see in step 2 and 3 are done with the help of Home Brew. Without installing Home Brew the commands will not work.

2. We are installing PHP. I work with WordPress plugin and themes and I test several of them every day.

3. I am installing MariaDB. I used to use MySQL before (I guess) but heard that MariaDB is faster, so using it from 2019.

4. We are downloading composer, a command line tool to help with installing PHP packages.

5. Renaming it to Composer so that we can access it easily from the command line.

6. Now we will check if the file is working properly. After running the command from the terminal, we will see the available commands and that will confirm that it is working perfectly.

7. Now is the time to move the file to a directory, from where we will be able to use the command without writing the file extension (.phar).

8. It’s time to add Laravel Valet to our PHP packages.

9. Adding the path to the list will help us access the PHP packages from the command line. For example, we will be able to access the valet command from the terminal after running this command.

10. Now we need to find a folder where we will keep all our website files. The folder can be anywhere you like. Desktop or user folder doesn’t matter.

11. Running this command means we are telling Valet that I will use this folder as my web server.

12. This one tags the folder as the root folder and will look for sites inside here. For example, I have created a folder named themeum and installed Valet on that folder. So it is the root folder. Inside themeum folder, I have created folders named crowdfunding, tutor, megamenu.
After this step, my web server is ready and I can access the content inside crowdfunding folder from crowdfunding.test domain.

Valet Commands

valet start it starts the server. By default, it is running in the background.

valet stop it stops the server. If you are very low in resources, you should stop it after you are done using.

Similar Posts

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *