How to Install Apache, PHP and MYSQL in macOS

Install Apache in macOS - apache mysql php phpmyadmin

Install Apache without download anything

  1. Press “Shift” + “Command” + “A” together to open the applications folder.
  2. Scroll down and double click on “Terminal” Application
  3. Type “sudo apachectl start” and press enter
  4. Open your browser and type in “localhost” and if you see the screen below, it means you have enabled Apache
    Install Apache in macOS - apache

If in any case you want to restart or stop Apache, you can type in the following command

  • sudo apachectl stop
  • sudo apachectl¬†restart

 

So where can I find the folder?

This file is located at /Libarary/WebServer/Documents /

 

How to install PHP

  1. Open Terminal and type “sudo nano /etc/apache2/httpd.conf” and press enter
  2. Press Ctrl+W
  3. Type php and press enter, you will see the highlightedInstall Apache in macOS - php
  4. Remove the # from #LoadModule php7_module libexec/apache2/libphp7.so
  5. Press Ctrl+O followed by Enter to save the change you just made
  6. Press Ctrl+X to exit nano
  7. Type “sudo apachectl restart” and press enter

Let’s create a site folder so you can place all your files in there instead of the default folder.

You can create the folder anywhere you want, or you can follow our steps

  1. Press “Shift” + “Command” + “C” together to open the computer folder.
  2. Go to Users
  3. Find your computer name
  4. Create a new folder and name it “sites”
  5. Open your text editor and create a new file called index.php and save it in the folder your just created
  6. In the index.php, key in the following,
    <?php
    echo “Hello From Sites Folder!”;
    phpinfo();
    ?>
  7. Open Terminal and type “sudo nano /etc/apache2/httpd.conf” and press enter
  8. Press Ctrl+W
  9. Search “DocumentRoot”
    Install Apache in macOS - change directory
  10. Replaced both the “/Library/WebServer/Documents/” with “/users/YourComputerName/sites”
  11. Press Ctrl+O followed by Enter
  12. Press Ctrl+X to exit nano
  13. Type “sudo apachectl restart” and press enter

Go back to the browser, refresh the localhost page and the PHP info will be shown.

Install Apache in macOS - php 7

 

How to MYSQL

  1. Go to https://dev.mysql.com/downloads/mysql
  2. Scroll down and look for macOS xx.xx (x86, 64-bit), DMG Archive and click the download button
    Install Apache in macOS - mysql
  3. Scroll down and click “No thanks, just start my download”
  4. Once it is downloaded, double click the file and go through the installation process
  5. Once it is installed, MYSQL will auto start

To check if it is running, go to System Preferences, scroll down to the page and double click on MySQL. You will see MySQL is running and the color is in green.

Install Apache in macOS - system setting

Let’s do a simple configuration to MYSQL

  1. Open your Terminal program and type in “sudo /usr/local/mysql/bin/mysql -u root -p”
    Install Apache in macOS - mysql 1
  2. Key in your mac password
  3. Key in the password which you have set for MYSQL
  4. Type in “ALTER USER ‘root’@’localhost’¬†IDENTIFIED WITH mysql_native_password BY ‘YourPasswordAgain”
    Install Apache in macOS - mysql 2

 

How to install phpMyAdmin

    1. Go to https://www.phpmyadmin.net/
    2. You can click the download button at the top bar or the green download button
      – Download “http://phpMyAdmin-4.8.5-all-languages.zip” or “http://phpMyAdmin-4.8.5-english.zip”
      Install Apache in macOS - phpmyadmin 5
    3. Once it is downloaded, go to your download folder and unzip the file
      Install Apache in macOS - phpmyadmin
    4. Rename the folder from “phpMyAdmin-4.8.5-all-languages” to “phpMyAdmin”
    5. Copy this folder and paste it into your site folder which you have created earlier
      Install Apache in macOS - phpmyadmin 2
    6. Double click phpMyAdmin folder and look for a file named “config.sample.inc.php”
    7. Select the file and right click Duplicate
      Install Apache in macOS - phpmyadmin 3
    8. Rename the file “config.sample.inc copy.php” to config.inc.php”
    9. Open the file with a text editor
    10. Look for this line $cfg[‘Servers’][$i][‘host’] = ‘localhost’;
      Install Apache in macOS - phpmyadmin 4
    11. Replace “localhost” with “127.0.0.1” and save the file
    12. Go to your browser and key in “http://127.0.0.1/phpmyadmin/”
    13. Username is root
    14. The password is the one you have set when you are installing MYSQL
    15. You have successfully installed phpMyAdmin
      Install Apache in macOS - phpmyadmin 6

 

Hope you find this article useful and happy coding.

Share

facebook icon twitter icon linkedin icon what app icon

Comments