How to Setup your MacOS for Laravel Development?
Congratulations on your recent purchase of a MacBook! If you intend to use it for Laravel development, you have come to the right place. Allow me to guide you through the necessary steps for setting up your MacBook for a Laravel development environment.
To install PHP on macOS, you can use the package manager Homebrew. First, make sure you have Homebrew installed by running the following command in your terminal:
If you don't have Homebrew installed, you can install it by running the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Once you have Homebrew installed, you can install PHP by running the following command:
brew install php
If you want to install specific php version you can search available php package in brew.
brew search php
brew-php-switcher php-code-sniffer php-cs-fixer@2 firstname.lastname@example.org phplint phpmyadmin phpunit pup
php php-cs-fixer email@example.com phpbrew phpmd phpstan pcp
eclipse-php phpstorm phpwebstudy pop
For example if you want to install php version 8 just.
brew install firstname.lastname@example.org
Now export path for binary php, change
~/.zshrc to whatever shell you are using in this case I use zsh.
echo 'export PATH="/email@example.com/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/firstname.lastname@example.org/sbin:$PATH"' >> ~/.zshrc
To install Composer, you can follow the instructions on the Composer website: https://getcomposer.org/download. Here is a brief summary of the steps to install Composer on macOS:
Download the Composer installer by running the following command in your terminal:
curl -sS https://getcomposer.org/installer | php
Move the Composer binary to a directory that is included in your system path by running the following command:
sudo mv composer.phar /usr/local/bin/composer
Verify that Composer is installed by running the following command:
This should print the version of Composer that is installed on your machine
Composer version 2.4.4 2022-10-27 14:39:29
This is optional. But if you want to create new project quickly you can use it directly from composer.
composer create-project --prefer-dist laravel/laravel project-name
You also can create laravel project using the official cli. First install the cli.
composer global require laravel/installer
Now export binary path.
echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >> ~/.zshrc
And here's how to create project from it.
laravel new lara-blog
Most people use MySQL for Laravel projects. You might as well if you do. Please follow the instructions below for installation.
brew install mysql
This will install the latest version of MySQL on your machine. You can verify that MySQL is installed by running the following command:
This should print the version of MySQL that is installed on your machine.
After installing MySQL, you will also need to start the MySQL server. You can do this by running the following command:
brew services start mysql
This will start the MySQL server in the background. To stop the MySQL server, you can run the following command:
brew services stop mysql
To secure a MySQL installation, you can follow these steps:
Set a strong password for the MySQL root user: By default, the MySQL root user has no password, so you should set a strong password for the root user to prevent unauthorized access to your MySQL server. You can do this by running the following command:
mysql -u root
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
new_password with a strong password of your choice.
Reload the privilege tables: After making changes to the MySQL user accounts and permissions, you will need to reload the privilege tables to apply the changes. You can do this by running the following command:
I hope this helps! Let me know if you have any other questions.