Show Menu
Cheatography

LAMP on OSX High Sierra Cheat Sheet (DRAFT) by

A list of reminders for building web sites using the LAMP stack.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Helpful Links

Turn on apache

- At the terminal, type: >
sudo apachectl start

- In a browser type:
localhost
or
localh­ost­/in­dex.html

- If you see: It Works!, it works.

Apache General Inform­ation

Apache Doc Root Directory
/Libra­ry/­Web­Ser­ver­/Do­cuments
httpd.conf lives in:
/etc/a­pac­he2­/ht­tpd.conf
localhost web access
http:/­/lo­cal­hos­t/i­nde­x.php
Other docs and dirs in Document Root
phpinf­o.php, phpmya­dmin, php.ini, inc/
bash alias
docroo­t='cd /Libra­ry/­Web­Ser­ver­/Do­cum­ents\'

Turn on PHP

At the terminal, type: $>
sudo vi /etc/a­pac­he2­/ht­tpd.conf

Uncomment:
#LoadM­odule php7_m­odule libexe­c/a­pac­he2­/li­bph­p7.so

Save file then restart apache: $>
sudo apachectl restart


In the document root: $>
sudo vi index.php

Enter:
<?php

phpinfo();

?>

Save file then restart apache: $>
sudo apachectl restart

In a browser, type:
localh­ost­/in­dex.php

Install MySQL

- Download from https:­//d­ev.m­ys­ql.c­om­/do­wnl­oad­s/mysql
- Choose the version for your OS
- Click “No thanks, just start my download”
- Go through the download process
- Make sure you copy the password for root@l­oca­lhost
- Start MySQL Server
- Add
/usr/l­oca­l/m­ysq­l/bin
to path in
.bash_­profile


To update password, see "If you lock yourself out of phpmyadmin"

Install phpmyadmin

- Download phpmyadmin
- Make new directory in the document root:
sudo mkdir phpmyadmin

- Make it writeable by owner (which could be root):
sudo chmod 755 phpmyadmin

- Unzip or unpack the zip file and copy to new directory
Also see: phpmyadmin setup doc
- From
localh­ost­/ph­pmy­adm­in/­setup
, create a new server connection by clicking New server
- Under Authen­tic­ation tab, enter
root
as user and new password for root
Then click Save.
- Now navigate to
localh­ost­/ph­pmy­admin

If you lock yourself out of phpmya­dmin:

...by turning on no password IN phpmya­dmin:
At the command line:
$ sudo mysql

mysql> SET PASSWORD FOR root@l­oca­lho­st=­PAS­SWO­RD(­'le­tme­in');

mysql> quit;

Now use username root and password letmein
 

Database Access Inform­ation

Directory for include files
[docro­ot]/inc
MySQL Login file
db_con­n.php
PHP include line
requir­e_once 'inc/d­b_c­onn.php';
[docro­ot]­/in­c/d­b_c­onn.php
<?php

// creden­tials for connecting to database

$host = 'hostn­ame';  //database hostname

$user = 'db_user';  //database username

$pw = 'db_us­er_pw';  //database user password

$db = 'datab­ase';  //mysql database name

?>

Database normal­ization

FIRST NORMAL FORM
NO repeating columns containing same type of data
ALL columns contain a single value
Unique PRIMARY KEY for each row

SECOND NORMAL FORM
Table must be in First Normal Form
Create new tables for any data that is repeated in columns
Each new table needs a unique PRIMARY KEY for each row.
AUTO_I­NCR­EMENT
can do this.

THIRD NORMAL FORM
Table must be in First and Second Normal Form. This is usually all that is necessary.
Any data that is not dependent on a primary key, but is dependent on another value, should be removed to another table. This is a very strict use of normal­iza­tion.