Skip to content

Instantly share code, notes, and snippets.

@dreamsparkx
Last active April 2, 2024 04:09
Show Gist options
  • Star 49 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save dreamsparkx/45fba1a25d6b175283a456b19f935ca3 to your computer and use it in GitHub Desktop.
Save dreamsparkx/45fba1a25d6b175283a456b19f935ca3 to your computer and use it in GitHub Desktop.
Install Apache, PHP, MySQL and phpMyAdmin on Mac OS X

Prerequisites

Install homebrew:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

1. Enable Apache

Open Terminal and run the following Code: sudo apachectl start

Open your browser and access http://localhost. If it says It Works, then you are set otherwise see if your apachectl has started or not.

2. Enable PHP for Apache

Let's make a backup of the default Apache configuration. This will help you to cross check later what you changed or in case you want to restore the configuration to default.

cd /etc/apache2/
cp httpd.conf httpd.conf.bak

Now edit the httpd.conf with vi or any other text editor: vi httpd.conf

Now uncomment the following line (Remove #): LoadModule php5_module libexec/apache2/libphp5.so

Now Restart apache: sudo apachectl restart

3. Install MySQL

To install MySQL: brew install mysql

Install brew services now: brew tap homebrew/services

Now start MySQL: brew services start mysql

Now configure MySQL : mysql_secure_installation

  • Validate Password Plugin
  • Remove anonymous users
  • Disallow root login remotely
  • Remove test database and access to it
  • Reload privilege tables now - Choose yes

After finishing this up, test MySQL: mysql -uroot -p.

It will ask you write the password you set for mysql before. Enter password and then something like this appear:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.19 Homebrew

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

4. Connect PHP and MySQL

Now we need to ensure PHP and MySQL:

cd /var
mkdir mysql
cd mysql
ln -s /tmp/mysql.sock mysql.sock

All your sites would have URLs like http://locahost/some-site pointing to /Library/WebServer/Documents/some-site.

Note on Permissions

You may recieve 403 forbidden when you visit your local site. The Apache user(_www) needs to have access to read, and sometimes write, your web directory.

You can either change permissions like this: chmod 755 directory/ or you can change the ownership of the directory to the apache user and group: chown -R _www:_www directory

5. Install PHPMyAdmin

This is optional. You can use MySQL through command line but this is a good way to administer MySQL. Download phpmyadmin from site.

cd /Library/WebServer/Documents/
tar -xvf ~/Downloads/phpMyAdmin-4.7.4-english.tar.gz
mv phpMyAdmin-4.7.4-english/ phpmyadmin
cd phpmyadmin
mv config.sample.inc.php config.inc.php

Done! Done! Done!

@Andrewngabriel
Copy link

This is very helpful! Thanks for sharing 👍

@eldaraldashev
Copy link

Many thanks

@milad-ahmd
Copy link

which port phpmyadmin has been start?

@manickkbala
Copy link

8080

@pinoyeto
Copy link

can these instruction works in Big Sur?

@alekusito
Copy link

It shows "You don't have permission to access /phpmyadmin/ on this server."

@alizadeh118
Copy link

alizadeh118 commented Jul 27, 2021

Thank you, it was really helpful.
There is a typo in the line starts with All your sites would have URLs: l is missing in localhost link.

@BryanTitan
Copy link

It shows "You don't have permission to access /phpmyadmin/ on this server."

add "sudo" before the command

@websasindu
Copy link

Big Sur

Working like champ on Big Sur. thank you

@sajanaKaru
Copy link

I'm using this in macOS Monterey. But I before edit my /usr/local/etc/httpd/httpd.conf . now it's not working. Can I have the default file, please?

@ncmochacity
Copy link

After following the steps, I'm still getting localhost/phpmyadmin error that site cannot be reached. However, I tested the server with localhost:8080 and it works.

@ashot-developer
Copy link

Hello @dreamsparkx 8080 port does not work for me. How can I fix it?

@5ylvino
Copy link

5ylvino commented Dec 25, 2022

very helpful. Thanks

@alsyedscholar
Copy link

Enable PHP for Apache: when I am creating backup using command it gives me Permission denied
Please guide me how to give permission in Mac.

@jumacniaco
Copy link

jumacniaco commented Apr 21, 2023

Enable PHP for Apache: when I am creating backup using command it gives me Permission denied Please guide me how to give permission in Mac.

Did you tried adding sudo before the command, as suggested by @BryanTitan ?

@jumacniaco
Copy link

Thank you very much @dreamsparkx!!

I can't login to phpMyAdmin localhost web page because I haven't credential!!
What's the username?

@jumacniaco
Copy link

I can login via command line using user: root and password: my_password
but I cannot login via web user interface at http://localhost/phpmyadm using same credential.

Please, help me

@alsyedscholar
Copy link

Thanks it's working using the terminal command

@Muniraj577
Copy link

I cannot access phpmyadmin "localhost/phpmyadmin". It says "Forbidden You don't have permission to access this resource."
I have given the permission using chmod 755.

@Muniraj577
Copy link

Muniraj577 commented May 27, 2023

localhost/phpmyadmin throws error This page isn’t workinglocalhost didn’t send any data.
ERR_EMPTY_RESPONSE
How can I solve this issue?

@thenotoriousgustav
Copy link

why when i open the phpmyadmin it say "Forbidden You don't have permission to access this resource." ??

@ahsinil
Copy link

ahsinil commented Nov 13, 2023

still get 403 Forbidden after change permission with chmod 755 Documents/ on MacOS Sonoma

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment