How to Set Up a Laravel Environment with PHP 7.4
Thank you for your continued support.
This article contains advertisements that help fund our operations.
Table Of Contents
This article explains how to set up a Laravel environment specifying PHP 7.4 as the version.
Simple Way to Set Up a Laravel Environment for Beginners
Install PHP 7.4
We will use Homebrew for this installation. The Homebrew installation process is simple:
You can install it easily by running the command provided on the Homebrew official page.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew -v
If the installation is successful, you can check the version.
Install PHP 7.4
brew install php@7.4
Set Up the Path
For macOS Catalina or later using zsh:
echo 'export PATH="/usr/local/opt/php@8.2/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@8.2/sbin:$PATH"' >> ~/.zshrc
For older macOS versions using bash:
echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> ~/.bash_profile
This will set up the path correctly.
Start PHP 7.4
brew services start php@7.4
Restart the Terminal (Easy to Forget)
php -v
If the PHP version is displayed, the setup is complete.
Install Composer
Run the commands from the official site in order:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }"
php composer-setup.php
php -r "unlink('composer-setup.php');"
After running these commands, a composer.phar
file will be created in your current terminal directory. You need to move it to a specific location to make it executable. Use the following command:
sudo
means executing the command as an administrator.mv
stands for "move."- This command moves
composer.phar
to/usr/local/bin/composer
.
sudo mv composer.phar /usr/local/bin/composer
You will be prompted for your computer's login password.
Install Laravel
The latest version of Laravel may not support PHP 7.4, so you may need to install an older version.
composer create-project laravel/laravel:^6.0 . example-app
cd example-app
php artisan serve
For more details, including images, check out this article: