Apache (HTTP Server)

apachectl -v // display Apache version
sudo apachectl restart
sudo apachectl start
sudo apachectl stop
apachectl -t // test apache
sudo apachectl -M // list all Loaded Modules
sudo nano /etc/apache2/httpd.conf // edit Apache conf
sudo nano /etc/apache2/users/almccann.conf // edit Apache user conf
sudo nano /etc/apache2/extra/httpd-userdir.conf // Include user.conf files
sudo nano /etc/apache2/extra/httpd-vhosts.conf // Include virtual host directories including localhost

Apache 2.4 upgrade settings:
Edit /etc/apache2/httpd.conf: Require all granted (not Order allow, deny)

Document Root

Document root is the location where the files are served from the file system (similar to public_html).  On OS X, there is the admin level document root, and user level.

Virtual Hosts allow you to set up sites in individual folders.

http://localhost/ // admin level
/Library/WebServer/Documents/ // Document folder
http://localhost/~username // user level
/User/username/Sites // Document folder


powder down // disable Pow
powder up // enable Pow


php -v // PHP version
echo "<?php echo phpinfo(); ?>" > ~/Sites/info.php // Create a PHP info file

brew install php56 --with-apache --with-imap
brew unlink httpd24

edit /etc/apache2/httpd.conf to use brewed php:
Replace LoadModule php5_module libexec/apache2/libphp5.so with LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so


brew install phpmyadmin

Add configuration to /etc/apache2/httpd.conf:

Alias /phpmyadmin /usr/local/share/phpmyadmin
<Directory /usr/local/share/phpmyadmin/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Require all granted



brew install mysql
mysql_secure_installation // updates MySQL settings for secure connection

Installation with Homebrew and launchd launch at startup
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents //  have launchd start mysql at login
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist // load mysql now
mysql.server start // start mysql server

A "/etc/my.cnf" from another install may interfere with a Homebrew-built server starting up correctly.
Host and user represent the hostname where mySQL is running and the username of mySQL.

mysql --host=_instance-IP_ --user=_user-name_ —password [after allowing IP address] // Connect to cloud SQL: this is root and MySQL password
mysql -h localhost -u [username] -p // connect to mySQL locally


; // completes a command
, // will roll over to new column
\c // clears the command
\h // help
\q // quit

GRANT ALL PRIVILEGES ON [database].* TO "dbusername"@"hostname" [IDENTIFIED BY "setthepassword"];
SELECT User,Host FROM mysql.user; // Show all users
SHOW TABLES FROM [database];
show databases;
show grants for 'user'@'hostname';
use [database name] // use does not require a ;
select version();
select now();
select user();
current date;

mysql -u root -p // connect to localhost with root