Setting up PHP, MySQL, phpmyadmin on mac sierra

Mac OS Sierra comes with PHP, MySQL pre installed isn’t it cool? There are two-label root directory, one is called system label and another is user label. The default system label root is “/Library/WebServer/Documents”. The other user label root is missing by default. In this article we’re going to work with user label root.

PHP installation

Create folder named “Sites” at your root directory. (For those who are newbies) From terminal type “cd” and “sudo mkdir Sites”. To run this user label system make a configuration file under /etc/apache2/users/{your-username}.conf (here in the place of “your-username” type your currently logged in users username) and place the below code in it.

<Directory "/Users/username/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>

 

permission this file should be “-rw- r– r– 1 root” if not, run this command “sudo chmod 644 {your-username}.conf”

Next open the “/etc/apache2/httpd.conf” file to active some module

✓ LoadModule authz_core_module libexec/apache2/mod_authz_core.so
✓ LoadModule authz_host_module libexec/apache2/mod_authz_host.so
✓ LoadModule userdir_module libexec/apache2/mod_userdir.so
✓ LoadModule include_module libexec/apache2/mod_include.so
✓ LoadModule rewrite_module libexec/apache2/mod_rewrite.so
✓ LoadModule php5_module libexec/apache2/libphp5.so
✓ Include /private/etc/apache2/extra/httpd-userdir.conf

Then open another apache configuration file at “/etc/apache2/extra/httpd-userdir.conf “ and active module

✓ Include /private/etc/apache2/users/*.conf

Save and restart apache “sudo apachectl restart”

If your are going the web serving document root at “/Library/WebServer/Documents”, its good idea to allow any .htaccess file used to override the default settings. This can be done by editing the “/etc/apache2/httpd.conf” file “AllowOverride All”. Also uncomment the below module

✓ LoadModule rewrite_module libexec/apache2/mod_rewrite.so

To test php running write a php file under /Library/WebServer/Documents and name it according your wish and run through browser “localhost/{your-file- name.php}”

MySQL installation

Download MySQL from MySQL’s native website and install it manually.
The first time after installations a dialog box will popup showing a temporary password, save that carefully for future use. Stop MySQL and start in safe mood and change the given password to yours by running these below commands.

✓ sudo /usr/local/mysql/support-files/mysql.server stop
✓ sudo mysqld_safe — skip-grant- tables
✓ mysql -u root
✓ FLUSH PRIVILEGES;
✓ ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘MyNewPass’;
✓ sudo /usr/local/mysql/support-files/mysql.server start

You may be encountering the problem/error “ERROR! MySQL server PID file could not be found!”.

The problem is because the MySQL pid file isn’t in the MySQL configuration file. The default configuration sample file directory is “/usr/local/mysql/support-files/my-default.cnf”

Create a MySQL configuration file copy and pasting from “my-default.cnf tomy.cnf” And the PID file is under the directory “/usr/local/mysql/data/{your-pc-name}.pid”. At the bottom of configuration file write the MySQL pid path like “pid-file = /usr/local/var/mysql/{username}.pid”. look for running MySQL using command “ps -A | grep MySQL” and kill it “sudo kill -15 pidno” if any.
start MySQL “/usr/local/mysql/bin/mysql -v -uroot -p” here you will be promoted for password. Type the temporary password given/shown. First change the password “ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘MyNewPass’;”

To work with MySQL through terminal “/usr/local/mysql/bin/mysql -u root –p”

PHPMYADMIN

Download phpmyadmin, from your download directory rename it phpmyadmin and put it under (you created earlier) Sites folder Make a directory under phpmyadmin and name it config “Sudo mkdir ~/Sites/phpmyadmin/config”

Change the permission “chmod o+w ~/Sites/phpmyadmin/config”

Browse http://localhost/~{your-username}/phpmyadmin/setup/

Click on “new server” and then on Authentication tab fill the “password for config auth” with your desired password. Click save and then save. move the file under the config directory to direct phpmyadmin folder (one level up) and remove the config directory.

Browse http://localhost/~username/phpmyadmin/