LAMP Wiki

Recommend the XAMPP project, as individual releases do not seem to be tested with the other LAMP technologies. For example, I recently downloaded the lastest version of PHP and MYSQL, only to find that PHP had old MySQL drivers installed. So I copied the new drivers from the MySQL drivers to Apache, and Apache crashed.

Linux

Backup


'''Backup Script'''
located at /usr/local/sbin/backup_vtiger"
scheduled to run at 3:00 AM every day.
creates a zip file of everything in "/var/lib/mysql"
zip file created in "/backup/vtiger_backups"
log file in "/backup/vtiger_backups.log" with output from the script

The backup script checks for both the Apache and MySQL daemons, shutting them down if they are running. Then it creates the zip backup file, after which it restarts the MySQL and Apache daemons. However, it is intelligent enough NOT to restart the daemons if they weren't running in the first place -- that way, if you shut down either or both of the daemons for maintenance, they won't get accidentally restarted by this backup script. Currently, the backup script takes about 15-16 seconds to run, and creates a backup file of about 3.7 MB in size.

Commands

Tab should list more files How to list only directories

Disk Utilization: du

-h human readable
-s summary

Examples:
du -sh    =>   total size of current directory human readable

File Count using find

This counts all of the files in the current directory and all children directories:

find . -type f | wc -l

Find

The basic syntax of the find command is:

$ find . -name foo.bar

This will recurssively search starting in the current directory (.), and all subdirectories of the current directory, for the file named <filename>.


To filter out "Permission Denied" messages, use:

$ find . -name foo.bar -print 2>/dev/null

 

What version of Linux am I running?

uname -a 

chmod

permissions are represented by 3 digits

ugo => u=owner, g=group, o=otherw

1=execute, 2=write, 4=read

chmod 664 file => read and write access for the owner and group, read only for all others. 

 chmod 0 => removes all priveledges for all

chmod -R 755 => recursive, read+write+execute for owner, read+execute for group and others

chown

chown -R apache:apache drupal

grep

Generalized Regular Expression Parser

grep string file => finds all occurances of <string> in <file>

-i => ignore case

-w => whole word

-l => list file name only

grep -r 'searchstring' /home => recursive - search all files

find /somedir -name '*.doc' -print | xargs grep 'somestring' /dev/null =>

recursive - specify specific file pattern

 

tar

To create a compressed tar file: tar -cvf

To uncompress a tar file: tar -xvf

c=compress x=extract z=zip-format v=verbose (optional) f=file (must be last)

Examples: Create:

tar -czvf mystuff.tgz mystuff/

tar -cvzf file.tar.gz inputfile1 inputfile2

Extract: tar -xzvf mystuff.tgz tar -xvzf file.tar.gz

whereis

Handy way to find a file or directory: Example: whereis mysql

Imaging for Windows

VI Editor

Goto:

: => line mode, operates on current line unless specific line numbers are specified

^ or 0 ==> beginning of line
$ ==> end of line

:0==>beginning of file
G ==> end of file

nG ==> go to line n
:n ==> go to line n

Return ==> first non-blank char

H ==> top line on screen
L ==> last line on screen
M ==> middle of screen
Ctrl+L ==> Redraw screen??
b              beginning of previous word              
w              beginning of next word                  
e              end of current/next word                
0 (zero) or ^  beginning of line                       
$              end of line                             
(              beginning of current/previous sentence  
)              beginning of next sentence              
{              beginning of current/previous paragraph 
}              end of current paragraph                
H              top line on screen                      
M              middle line on screen                   
L              bottom line on screen

Search and Replace

The search command is /.  
/hello => search for "hello"
n repeats the search in the same direction
N repeats the search in the opposite direction

:s/search_string/replacement_string => global search and replace

:s/search_string/replacement_string/g => global search and replace


:s/search_string/replacement_string/gc => global search and replace with confirm

Yank (copy) and Put (paste)

yw yank rest of word
y$ yank rest of line
yy yank entire line
Y yank entire line

p put yanked/deleted text before cursor
P put yanked/deleted text after cursor
 

ln

A symbolic link, also known as a soft link or symlink, is a special type of file that points to another file or directory.

ln -s {target} {symlink name}

For, to example create a symlink for /home/domain/mydomain:

ln -s /home/domain/mydomain mydomain

Apache

'''Apache'''
Config file location: /etc/httpd/conf/httpd.conf Document Root: DocumentRoot "/var/www/html" Changes made by ServerPoint: -too many time_wait apache connections in the server -turned on KeepAlive -reduced the KeepAlive Timeout to 5 -too many mysql sleeping process running in the server, so mysql persistent connection were disabled -checked using a third party website and -it is loading within 2 seconds from different location of the world
'''Restarting Apache and Mysql'''
login to your server shell using root user and run these commands.
service httpd restart
service mysql restart
or service httpd stop
service httpd start
service mysql stop
service mysql start

htacess

MySQL


'''MySQL'''
mysql -u root -h localhost -p < import.sql

Shutdown local: go to mysql bin directory then:

mysqladmin -u root -p shutdown

How to get CREATE TABLE code?

To generate create table code, you could run a mysqldump on the database, which generates code to create all of the tables in the database (and load all of the data).

You could also execute the single SQL command:

show create table <tablename>;

How to see if mysql is running

Using mysqladmin:

mysqladmin -u root -p status

Using ps:

ps aux ¦ grep mysql

MySQL Socket File: mysql.sock

The MySQL Socket file "mysql.sock" can be used to communicate with the server, as opposed to using TCPIP.  Often the MySQL socket file is located '/var/lib/mysql/mysql.sock' or '/tmp/mysql.sock', although this may vary from one installation to another.     

Navicat

Navicat makes commercial database management tools for MySQL. For more information, see http://navicat.com.

Passwords

To set a root password when the root password is currently blank: mysqladmin -u root password <newpassword> To change passwords in general: 1. Login to the mysql command line interface with the user's current password: mysql -u <username> -p 2. At the "mysql>" prompt, type: set password = password("newpassword");

phpMyAdmin

PHP

 Snippets for Drupal:

Print node fields to screen:

<pre>
<?php print_r($node) ?>
</pre>

Print Node Body:

 

<?php print $node->content['body']['#value']; ?>

 

<?php print="">

<?php print=""><?php>

Commands

var_dump

var_dump displays structured information about one or more expressions that including its type and value.  A recursive listing is created for Arrays and Objects, with values indented to show structure.

Public, private and protected Object properties are returned in the output.

Figure out Apache/PHP user names

When setting security permissions in Linux, it may be important to figure out the name of the Apache and PHP users.  Often they are the same.  To find the name of the Apache user, issue the command:

ps -ef | grep apache

To determine the name of the PHP user, create and execute a PHP script with the following code:

<?php echo posix_getuid();?>
 

Figure out php.ini location

Where is php.ini?

From the Linux command line:

To determine the location of php.ini, run the following (Linux only):

php -r "phpinfo();" | grep Configuration

 

 

From Drupal:

The easiest way is to install the Devel Module, which has an option to run PHPinfo() and display the results in the browser.

PHP Ini Settings

The default PHP timeout in php.ini is 30 seconds, which is too short for some Drupal activities like listing/enabling modules.

SVN

Commonly Used Command

snv info - status of current directory if it is a working copy

svn commit - commit changes to repository

svn update - update working copy with latest changes from repository