As we know that the to setup development environment for PHP, you need a PHP parser, a Web Server and a database like MySQL or Oracle if you want to work on a dynamic website. To do so, either you can install everything manually or you can install ready-made software packages, which comes packed with all the requirements for PHP development environment.
The most popular, cross-operating system software package is XAMPP, which is widely used for PHP development locally for Windows OS, but personally, it is not that good when it comes to the macOS. I would suggest installing MAMP for macOS as it is more compatible with it and has a better user interface, which is a must for beginners.
Installing MAMP on macOS is very simple. All you have to do is download the latest setup from MAMP's Official Website. Once the setup file is downloaded, click on it to start the installation. The installation process is pretty straightforward, with just one catch, MAMP Pro is also installed along with the MAMP free version, which you can, of course, uninstall later.
Now go to your applications and double click on MAMP icon to start it. Click on Start Server to start the Apache Web server and MySQL database server.
Composer is a Dependency Manager for your project. It downloads all the dependency that any project has on external libraries. These days almost all the libraries are using composer.
Now as PHP is installed within MAMP, we would want that Composer should use PHP installation that was done along with MAMP. For this we first need to create an alias for MAMP's PHP installation, for this, we will add the code for making a new alias in our bash profile.
Open your terminal, and run the below command to open profile. We are using nano, you can use vim if you want:
This will open the bash profile. Then on the top, in a blank line, add the following code:
Update the above command as per your php version. As the installed version of php in MAMP on my laptop is 7.1.8, hence the directory name is php7.1.8
With that set, now it's time to install composer.
First, run the following command in your terminal. This will install composer using MAMP's PHP
curl -sS https://getcomposer.org/installer | phpmamp
As you can see, that instead of the standard php at the end, we have used phpmamp, which is an alias for the PHP installation of MAMP.
Now to make composer available globally, i.e. everywhere in your computer/laptop. To do so, we have to move the generated composer.phar (PHP archive) file to location /usr/local/bin/composer
sudo mv composer.phar /usr/local/bin/composer
For this, the terminal might ask for your password. Enter your password and hit "return" and we are done.
To verify the successful installation of Composer, open your terminal(if you closed it), and type the following command:
It will show you the version installed and the available commands that you can use.
See, how simple it was.
SHARE YOUR THOUGHTS WITH US!
Made with by Abhishek Ahlawat
© 2018 Studytonight. All rights reserved.