|
1 | 1 | # php-environment-setup-for-mac
|
2 | 2 | PHP environment setup sometime ruins our day. So here is the easiest way to setup Laravel valet on your Mac machine to run PHP or WordPress.
|
| 3 | +You can follow the guideline bellow or you may read the web version from [WPMiners.com](https://www.wpminers.com) |
| 4 | + |
| 5 | +<i>[Setup Laravel Valet On Mac](https://www.wpminers.com)</i> |
| 6 | + |
| 7 | +# SETTING UP A PHP / WORDPRESS DEVELOPMENT ENVIRONMENT TAKES TEN MINUTES. |
| 8 | + |
| 9 | +You must set up a local server if you have a Mac and want to run PHP or create a local development environment for WordPress. Sometimes, setting that up can destroy our day. |
| 10 | + |
| 11 | +But we can make it easy by doing some tricks. I will show you how to set up a local environment for PHP, Laravel, or WordPress within 5-10 minutes. |
| 12 | + |
| 13 | +You can run your servers using several apps such as xammp, mamp, and wamp. However, we will make use of Laravel Valet. |
| 14 | + |
| 15 | +## What is Laravel Valet? |
| 16 | + |
| 17 | +Laravel Valet is a development environment for macOS minimalists. Laravel Valet configures your Mac always to run Nginx in the background when your machine starts. |
| 18 | + |
| 19 | +To set up the valet server, you must first set up Homebrew. |
| 20 | + |
| 21 | +## What is Homebrew? |
| 22 | + |
| 23 | +Homebrew is a package management application for the Mac. “It’s more like the npm (node package manager) you use to continually update and install or remove your node packages,” for example. Homebrew serves the same purpose as npm on Mac and Linux. |
| 24 | + |
| 25 | +To set up a Mac development environment, we have to install several applications on our device. |
| 26 | + |
| 27 | +> We will install by following steps: |
| 28 | +1. Homebrew Installation |
| 29 | + |
| 30 | +2. PHP & MySQL Installation |
| 31 | + |
| 32 | +3. Composer Installation |
| 33 | + |
| 34 | +4. Laravel valet install |
| 35 | + |
| 36 | +# SETUP STARTED: |
| 37 | +## 1. INSTALLING HOMEBREW ON MAC: |
| 38 | +Open your macOS terminal and run this command bellow |
| 39 | + |
| 40 | +> `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"` |
| 41 | +
|
| 42 | +Use this command to check the Homebrew version. If all goes well, you could see like this. |
| 43 | + |
| 44 | +[<img alt="brew-setup-done" src="assets/brew.png"/>](https://github.com/csesumonpro/Github-Readme-Cheatsheet) |
| 45 | + |
| 46 | +If it throws any exception, your global path may need to be set up; just follow the instructions on the terminal. |
| 47 | + |
| 48 | +> `brew -v` |
| 49 | +
|
| 50 | +Homebrew version check on terminal |
| 51 | + |
| 52 | +## 2. INSTALLING PHP AND MYSQL: |
| 53 | +You must have to install PHP if your device has not any. It will be simple using brew command. Run this command on your terminal. |
| 54 | + |
| 55 | +> `brew install php` |
| 56 | +
|
| 57 | +Then, if you wish to store your data, you must install MySQL. It is also essential if you want to run WordPress locally. |
| 58 | + |
| 59 | +Run command to install MySQL |
| 60 | + |
| 61 | +> `brew install mysql` |
| 62 | +
|
| 63 | +After successfully installing PHP and MySQL, you must run those services. You can run any services using Homebrew with a single command like “brew services start YourServiceName” |
| 64 | + |
| 65 | +For example, you can run MySQL by |
| 66 | +> `brew services start mysql` |
| 67 | +
|
| 68 | +And to run PHP using: |
| 69 | +> `brew services start php` |
| 70 | +
|
| 71 | +Recommend: |
| 72 | + |
| 73 | + To run all services like PHP and MySQL by a single command. |
| 74 | + |
| 75 | +> `brew services restart --all` |
| 76 | +
|
| 77 | +This success message will be displayed to let you know whether your service is up and running. |
| 78 | + |
| 79 | +Restarting all services by Homebrew |
| 80 | +Restarting all services by Homebrew |
| 81 | +After installing PHP, you are ready to install the Composer package manager |
| 82 | + |
| 83 | +## 3. INSTALLING COMPOSER |
| 84 | +Composer is also a package manager of PHP like npm or brew. And it is also very easy to install using the brew command. |
| 85 | + |
| 86 | +Run this command below: |
| 87 | + |
| 88 | +brew install composer |
| 89 | +To check the successful installation, you can check the version by the command |
| 90 | + |
| 91 | +> `composer -v` |
| 92 | +
|
| 93 | +And it will show like this with the current version number. |
| 94 | + |
| 95 | +[<img alt="brew-setup-done" src="assets/composer.png"/>](https://github.com/csesumonpro/Github-Readme-Cheatsheet) |
| 96 | + |
| 97 | +Composer installed globally |
| 98 | +Composer installed globally |
| 99 | +Exceptions: |
| 100 | + |
| 101 | +Sometimes it may throw some exceptions cause your composer is not on the global path. To make this happen, you may have to run this command below: |
| 102 | + |
| 103 | +> `sudo mv composer.phar /usr/local/bin/composer` |
| 104 | +Then check again by the version is available or not. If you see the version, then your composer setup is done. |
| 105 | + |
| 106 | +## 4. INSTALLING LARAVEL VALET USING COMPOSER |
| 107 | +Using composer, you can easily install Laravel Valet. Run the command below |
| 108 | + |
| 109 | +> `composer global require laravel/valet` |
| 110 | +
|
| 111 | +After that, you are ready to install valet on your machine. |
| 112 | + |
| 113 | +> `valet install` |
| 114 | +## Exception: |
| 115 | +<hr> |
| 116 | + |
| 117 | + Sometimes you may face this issue Laravel “valet install” not found” |
| 118 | + |
| 119 | + you need to make sure that <b>~/.composer/vendor/bin</b> directory is in your system’s PATH; you can check this by running `echo $PATH` To solve this issue, run this command below. |
| 120 | + |
| 121 | +> `export PATH=$PATH:~/.composer/vendor/bin` |
| 122 | +
|
| 123 | +<i>Then run again:</i> |
| 124 | + |
| 125 | +> `valet install` |
| 126 | +
|
| 127 | +<hr> |
| 128 | + |
| 129 | +And You are done installing all packages. Now you can use your server; open the directory in your terminal that you want to run with the server. Go to the project directory, Then run this command on the terminal. Laravel valet server is parked. You might be prompted to enter your Mac password; simply input it and press Enter. Then it will appear as follows: You parked your project directory. |
| 130 | + |
| 131 | +Following the execution of the command, |
| 132 | + |
| 133 | +> `valet park` |
| 134 | +
|
| 135 | +will validate that your directory has been added to the valet’s path. It appears to be like the image below. |
| 136 | + |
| 137 | +[<img alt="brew-setup-done" src="assets/valet.png"/>](https://github.com/csesumonpro/Github-Readme-Cheatsheet) |
| 138 | + |
| 139 | +This command will park your project on the server |
| 140 | + |
| 141 | +# How to run projects on your server: |
| 142 | + |
| 143 | +It’s very easy and no need to run every day. It will run automatically for you. Run your project in any browser on your Mac in this manner. |
| 144 | + |
| 145 | +http://Your-project-name.test |
| 146 | + |
| 147 | +Just one thing you have to ensure your projects is in the parked directory. If not, then just add it using the same command: valet park |
| 148 | + |
| 149 | +Example: |
| 150 | + |
| 151 | +Here is my directory, which contains a project called “Welcome” that is already in the parking directory. You can get to it by typing welcome.test into your local browser. |
| 152 | + |
| 153 | +[<img alt="brew-setup-done" src="assets/directory.png"/>](https://github.com/csesumonpro/Github-Readme-Cheatsheet) |
| 154 | + |
| 155 | +Project directory for valet server |
| 156 | +Project directory |
| 157 | +Access valet server |
| 158 | +Even if You can make this test domain secure by a single command, open your project on the terminal and run this command below, then It will run under SSL now. |
| 159 | + |
| 160 | +> `valet secure` |
| 161 | +
|
| 162 | +Making projects secure under SSL you can run like this https://Your-project-name.test |
| 163 | +Your server configuration is complete. You can run your PHP , Laravel application using this server. Also, you can run your WordPress locally. If you face any problems, please leave a remark below. |
0 commit comments