Linux: add Users and others

Create User Account for web developing

For the web developing based on Linux, some workers share a user account. E.g, 5 developers use 1 user account and sharing the codes. It is NOT a good choice, the potential conflicts of overwriting, deleting, renaming, will make hard works invoid.

To solve this problem, the best way is to create individual user account for each team worker.
Each team worker has his space to code, test, maintain his sources codes. Plus version control system, like git or cvs, the developing env is solid and scalable.

The following are the steps to create 2 Linux user accounts who share a common group:

# groupadd -g 10005 web_group
# useradd -d /home/test1 -s /bin/bash -p test1 -g web_group  test1
# useradd -d /home/test2 -s /bin/bash -p test2 -g web_group  test2
# usermod -a -G apache,mysql,nobody test1
# usermod -a -G apache,mysql,nobody test2

The user ‘test1’, ‘test2’ will have their individual home directory, in the same group ‘web_group’. Meanwhile, we add 3 groups besides the ‘web_group’: ‘apache’ related to webserver, ‘mysql’ to database control, and ‘nobody’ which maybe the webserver running user.
Now the 2 users share the benefits of the ‘apache, mysql, nobody, web_group’ groups.

The following codes are regarding on grant, re-assgin previleges etc.

-- recursive change dirs to user/group read/write/excutable
-- and others without write permission.
$ find . -type d -exec chmod -R 775  {} \;

-- change directory owner.
$ suexec chown -R test1/web_group web_testing_dirs/

Where should web programs to save files?

It is NEVER a good idea to store information (upload files, temperarily web files) under web developer’s home directory. Because it always generates privilege problems, and unsafe, hard to maintain. In such case, use public shared directory instead.

Here list the potential directories to hold temporaily/middle files in server side:

  • /tmp
  • /usr/tmp/
  • $DocumentRoot/$somedir/

Where are the best place? I use /usr/tmp/, which can be access even by ‘nobody’ user (the dir’s previlege is 1777, default to allow every user share).
Some reference for Apache and MySQL

  • for mysql.sock, it is in /var/lib/mysql/
  • for apache’s php session, it is in /var/lib/php/session/

MySQL and Apache can be assigned dir when compiling (configure, make, make install) in Linux.

Alias for web application

To shortcut access local applications like:

We need to configure Apache’s httpd.conf:

$ vi httpd.conf

Alias /test1 "C:/Users/.../test1/"
Alias /test2 "C:/Users/.../test2/"

# First, we configure the "default" to be a very restrictive set of 
# features.  
<Directory />
    Options FollowSymLinks Indexes MultiViews  Includes ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

After the adding, use: httpd -t to run syntax check for config files.

jQuery: put html tag in first place

    
$('<span></span>').addClass('error-message').
  text(errorMessage).appendTo(target);

Always put html tag in the first place (with CLOSE tag), this will make it compatiable with IE browsers.

PHP: header() and exit()

    if (some_condition_meets) {
  header("Location: otherpage.php");
  exit; 
}
other php codes ....

exit() should immediately follows after header(). This is Very neccessary, it will fork an new process for header(), then exit. Otherwise, PHP continues runing even a new processs is forked for header().

Javascript Compactor and Decompactor

It is always a good idea to compact JavaScript codes in html, especially the JS file is big. My way to do so is:

  • edit a JS file, let’s say, sample.js
  • testing, debuging it in developing environment(step over error, breakpoint)
  • compact sample.js to sample.min.js
  • So there are 2 versions: sample.js (visualable), and sample.min.js(remove whitespace)
  • in production environment, replace sample.js to samle.min.js: use <script language=”javascript” type=”text/javascript” src=”sample.min.js”></script>
  • use decompactor(remove all whitespace) to decompact JS codes, editing, improving in developing env, the compact it to production env.

In production env, we have to always use the compact JS to improve performance.
Currently there are some free JS compactor/decompactor, the following are 2:
MeanFreePath JavaScript Code Compactor
JavaScript Code Decompressor

Leave a comment