Cheatography
https://cheatography.com
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.
Turn on apache
- At the terminal, type: > sudo apachectl start
- In a browser type: localhost
or localhost/index.html
- If you see: It Works!, it works. |
Apache General Information
Apache Doc Root Directory |
/Library/WebServer/Documents |
httpd.conf lives in: |
/etc/apache2/httpd.conf |
localhost web access |
http://localhost/index.php |
Other docs and dirs in Document Root |
phpinfo.php, phpmyadmin, php.ini, inc/ |
bash alias |
docroot='cd /Library/WebServer/Documents\'
|
Turn on PHP
At the terminal, type: $> sudo vi /etc/apache2/httpd.conf
Uncomment: #LoadModule php7_module libexec/apache2/libphp7.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: localhost/index.php
|
Install MySQL
- Download from https://dev.mysql.com/downloads/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@localhost
- Start MySQL Server
- Add /usr/local/mysql/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 localhost/phpmyadmin/setup
, create a new server connection by clicking New server
- Under Authentication tab, enter root
as user and new password for root
Then click Save.
- Now navigate to localhost/phpmyadmin
|
If you lock yourself out of phpmyadmin:
...by turning on no password IN phpmyadmin:
At the command line:
$ sudo mysql
mysql> SET PASSWORD FOR root@localhost=PASSWORD('letmein');
mysql> quit;
Now use username root and password letmein |
|
|
Database Access Information
Directory for include files |
[docroot]/inc |
MySQL Login file |
db_conn.php |
PHP include line |
require_once 'inc/db_conn.php';
|
[docroot]/inc/db_conn.php
<?php
// credentials for connecting to database
$host = 'hostname'; //database hostname
$user = 'db_user'; //database username
$pw = 'db_user_pw'; //database user password
$db = 'database'; //mysql database name
?>
Database normalization
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_INCREMENT
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 normalization. |
|