Prerequisite: homebrew
Disclaimer: This article is for the streamlined installation of laravel command-line tools with PHP and MySQL on MacBook. You can follow the installation and starting guide on laravel.com, I personally like the installation with
sail
. But this is the traditional way of using laravel on Macbook.
Installation
PHP installation
we will need to install PHP with homebrew, with command
brew install php
This command will install the latest version of php.
If you have PHP installed already then simply update php
brew update php
MySql Installation
The command is simple enough like
brew install mysql
once installation completed you can start mysql with brew services
brew services start mysql
once mysql is running on your machine you can login to the mysql with
mysql -u root -p
and enter your password by default it will blank string.
now you can use all of the commands for mysql.
Installation of the composer.
For installing composer goto https://getcomposer.org/download/
and paste the following code found on the installation document.
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
If you try to use the composer command it will not be found and the composer.phar
file is not executable. Follow the following command to make it executable and move it to the local bin folder.
$ chmod +x composer.phar
$ mv composer.phar /usr/local/bin/composer
Now try using composer
composer
You must be able to see available commands for the composer listed.
Laravel installer
Install laravel with composer globally
composer global require laravel/installer
Now try using laravel, the command will not found because composer is not been set on the zsh (our terminal)
For zsh
echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
If you are bash then use
echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Now you have successfully installed the laravel command line tool. Now you can create laravel application with
laravel new example-app
Now you can start creating your awesome application with laravel.
cd example-app
php artisan serve
Happy Coding....
Top comments (0)