sourcecode

Saturday, June 30, 2012

GET v.s. POST

Head First PHP & MySQL
page 278

The difference between GET and POST isn’t just form vs. URL since GET
requests can (and often are) used to submit form data as well. The real
distinction between GET and POST has to do with the intent of a request.
GET is used primarily to retrieve data from the server without affecting
anything on the server. POST, on the other hand, typically involves
sending data to the server, after which the state of the server usually
changes somehow in response to the data that was sent.

 Another distinction is that data passed through a GET is visible in a URL,
while POST data is hidden, and, therefore, is a tiny bit more secure.

So... GET is good for bookmarks!
/***************END***********/

Permission on a directory

drwxrwxrwx
read:  read the content of the directory
write: change the content of the directory: create new/rm/mv files or subdirectories
execute: cd into the directory

 (root can do ANY operations even when the file permission is ---------, always!)

http://content.hccfl.edu/pollock/AUnix1/FilePermissions.htm

Without execute permission on a directory, a user can't access files in a directory even if they own them and have all permissions on them.
With read but not execute, you can do ls someDir but not ls -l someDir.  With execute but not read permission, you can ls -l someDir/file but not ls someDir or ls -l someDir.  Thinking of the system calls involved (read and stat) may help clarify this.  Also, make sure ls isn't aliased to something such as ls --color or ls -F, since these options change the listing to identify directories, links, and executables by using stat, which requires execute permission.  (Try /bin/ls each time, or unalias ls.)
Remember that to use ls -l file, or on some systems ls -i dir (i.e., to use stat() system call), you must have execute on the directory, the directory's parent, and all ancestor directories up to and including / (the root directory).
With execute but not read permission on a directory, users cannot list the contents of the directory but can access files within it if they know about them.
A common situation illustrating all this is user web sites.  If a user's web page is /home/auser/public_html/index.htm, then 'x' permission is needed for everyone on /, /home, /home/auser, and /home/auser/public_html, and the file index.htm needs 'r' permission for everyone ('x' is not needed for the file.)
To delete a file requires both write (to modify the directory itself) and execute (to stat() the file's inode) on a directory.  Note a user needs no permissions on a file nor be the file's owner to delete it!
To put or create a file in a directory required both w and x permissions.  Write permission is needed because you are modifying the directory with a new hard link, and execute permission is needed in order to use stat, open, and creat system calls.  (Creating a file involves trying to open the file first to see if it already exists and stat if it does, and using either ln to create a new hard link or creat to create a new file.)

/**************END**************/

XAMPP phpMyAdmin access

XAMPP is great for a quick set of apache/php/perl/mysql for windows.
http://www.adobe.com/devnet/dreamweaver/articles/setup_php.html#articlecontentAdobe_numberedheader_2

But had a strange problem for hours.
The phpMyAdmin gave me an access denied error, even after the password was properly set for localhost.
A possible reason is
localhost
is not treat equivalently to
127.0.0.1
So try one or anther might solve the mystery when all other methods have failed.

/**************END*************/

Bash login logout script file

http://www.linuxfromscratch.org/blfs/view/stable/postlfs/profile.html
to prepare the environment when a login/shell starts up, modify the file:
~/.bash_profile
to clean up and/or run script upon logout, edit the file:
~/.bash_logout

/****************END*****************/

Thursday, June 28, 2012

MySQL account privileges

http://dev.mysql.com/doc/refman/5.0/en/show-grants.html
To show privileges, use SHOW GRANTS:
current account:
>SHOW GRANTS;
for another account:
>SHOW GRANTS FOR 'accountname'@'hostname';
For a read-only account, the minimum privilege should be granted is SELECT.
 http://www.symantec.com/business/support/index?page=content&id=HOWTO16962
> grant select on dbname.* to 'readonlyuser'@'%' identified by 'pogo$23';

/******************END**************/

Migrate MySQL database to a new server

How to move/copy/backup MySQL database to another server? Use mysqldump and ssh:

http://www.cyberciti.biz/faq/transferring-mysql-database-tables/
http://www.devshed.com/c/a/MySQL/Backing-up-and-restoring-your-MySQL-Database/

#mysqldump -u sqluser1 -psqlpass1 database1 |ssh sshuser@server2.com mysql -u sqluser2 -psqlpass2 thedatabase2
Then the terminal pops password entry for ssh for sshuser on server2.com

/******************END**************/

Apache2 Configuration on Fedora Server for PHP

Get the install path of PHP(/usr/bin/php):
$>whereis php
and the path for php-cgi(/usr/bin/php-cgi):
$>whereis php-cgi

Edit the configuration file for apache2:
$>sudo vi /etc/httpd/conf/httpd.conf
insert the lines to accordance postions:
ScriptAlias /local-bin/ /usr/bin/

AddType applicatoin/x-httpd-php5 .php

AddHandler application/x-httpd-php5 php

Action application/x-httpd-php5 /local-bin/php-cgi

        Order allow,deny
        Allow from all
Finally reload apache:
$>sudo /usr/sbin/apachectrl restart
 /************END*****************/

How do I know which Linux version I am using

http://serverfault.com/questions/3331/how-do-i-find-out-what-version-of-linux-is-running
http://www.cyberciti.biz/faq/howto-find-out-what-kernel-version-running/
$ uname -mrsn

There is no cross-distribution way. However:
  • Redhat and friends: Test for /etc/redhat-release, check contents
  • Debian: Test for /etc/debian_version, check contents
  • Mandriva and friends: Test for /etc/version, check contents
  • Slackware: Test for /etc/slackware-version, check contents
Etc. Generally speaking, check for /etc/*-release and /etc/*-version.

/************END*****************/

How to start MySQL service on Linux

http://theos.in/desktop-linux/tip-that-matters/how-do-i-restart-mysql-server/

Redhat/Fedora:
/etc/init.d/mysqld start
or
# service mysqld start
Debian/Ubuntu:
/etc/init.d/mysql start

To auto start MySQL after reboot:
http://www.nossdutytask.com/mysql/start_stop_and_auto_start_mysql_server_on_fedora_core_linux


1. The Linux command that can be use to check the list of service that start on certain run level:

[root@tenouk ~]# chkconfig --list

2. To check only MySQLd server:

[root@fedora ~]# chkconfig --list mysqld
mysqld       0:off       1:off       2:off       3:off       4:off       5:off       6:off
[root@fedora ~]#

3. To make MySQLd auto start when you boot your computer:

[root@fedora ~]# chkconfig --level 35 mysqld on

Note:   Run Level 3 = Full multiuser mode with no GUI
                  Run Level 5 = X11 or GUI mode

4. Use the chkconfig again to verify the changes:

[root@fedora ~]# chkconfig --list mysqld
mysqld       0:off       1:off       2:off       3:on       4:off       5:on      6:off


/************END*****************/ 

Fedora run levels

http://www.techotopia.com/index.php/Configuring_Fedora_Runlevels_and_Services


  • Runlevel 0 - The halt runlevel. This is the runlevel at which the system shuts down. For obvious reasons it is unlikely you would want this as your default runlevel.
  • Runlevel 1 – Causes the system to start up in a single user mode under which only the root user can log in. In this mode the system does not start any networking, X windowing or multi-user services. This run level is ideal for system administrators to perform system maintenance or repair activities.
  • Runlevel 2 - Boots the system into a multi-user mode with text based console login capability. This runlevel does not, however, start the network.
  • Runlevel 3 - Similar to runlevel 2 except that networking services are started. This is the most common runlevel for server based systems that do not require any kind of graphical desktop environment.
  • Runlevel 4 - Undefined runlevel. This runlevel can be configured to provide a custom boot state.
  • Runlevel 5 - Boots the system into a networked, multi-user state with X Window System capability. By default the graphical desktop environment will start at the end of the boot process. This is the most common run level for desktop or workstation use.
  • Runlevel 6 - Reboots the system. Another runlevel that, for obvious reasons, you are unlikely to want as your default.


Testing:
[yguo@mo init.d]$ chkconfig --list sshd
sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
[yguo@mo init.d]$ chkconfig --list httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off
[yguo@mo init.d]$ chkconfig --list mysqld
mysqld          0:off   1:off   2:off   3:off   4:off   5:off   6:off

So I set:
[yguo@mo init.d]$ sudo chkconfig --level 35 mysqld on
/************END*****************/ 

Delete default MySQL anonymous account

http://bytes.com/topic/mysql/answers/77983-how-delete-guest-user
http://dev.mysql.com/doc/refman/5.0/en/default-privileges.html

There is a default anonymous (empty user name) in MySQL: ''
You get logged into this account when you type:
#mysql
and you are now using user name '' with no privileges everywhere.
which would be some careless mistake, instead of typing the right command:
#mysql -u lightnight -p

So, how to delete this ghost account? log in with root (or others with admin privileges):

>use mysql;
>delete from user where User='';
>delete from db where User='';
>flush privileges;

/************END*****************/