Web Developer’s Guide to System Administration

Posted in Articles

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

It is not really a web developer’s job to configure servers.  But sometimes you have to.   As long as you know the basic principles, you can Google for the exact commands.  Here are a few notes.  Keep in mind that I am not a system administrator, and some of these commands are quite invasive.  And it varies depending on the flavor of Linux.

ssh into the server with …

ssh username@example.com

You will land in your home directory which is likely /home/username/ and it would likely contain a .ssh folder.

sudo powers

“sudo” stands for “super user do”.

If you have sudo powers, you can run certain commands by preceding it with “sudo”.  For example, this is how to look into the passwd file …

sudo cat /etc/passwd

If the second field (password field) contains an “x”, that means the password is stored in the /etc/shadow/  (Don’t worry, the password is not in clear text; it’s encrypted).

If you need to rerun the last command with sudo, you can do …

sudo !!

If you don’t want to precede everything with sudo, you can “substitute user” with …

sudo su

And you will become root.  Try not to stay in this shell too long.  Exit back to your own shell with “exit”.

To see who have sudo powers, look in /etc/sudoers

But do not edit this file directly.  A wrong key can lock everyone out of the server.  Instead use visudo which will validate the syntax before saving.

It may show that a group named “wheel” has sudo powers.  To see who is in wheel group, look in the /etc/group file.

More info about sudo.

Members and Groups

To see what group the member username is in …

id -nG username

To add “username” to a group “wheel”…

usermod -a -G wheel username

This reads like “append group wheel to username”.  This example just gave the member sudo powers.  So don’t do this example, unless that’s is really what you want to do.

To remove sudo powers from that user use syntax…

gpasswd -d user group

For example…

gpasswd -d username wheel

To disable a member, …

passwd username -l

This locks the password by putting an ! in front of the encrypted password in the passwd or shadow file.

To unlock the user,

passwd username -u

To permanently delete the user …

userdel username

Be careful with the -r option in this command.  It deletes the user home directory as well.  And if the user’s home directory was set to document root, your whole website could be deleted.

Creating Users with FTP to document root

To learn how to create users and set their home directory and group and give them FTP access to document root of the web server (which typically is /var/www/html in some Linux flavors, or may be /Library/WebServer/Document, or others), read this article by RackSpace support.

Installing PHP with yum

yum install php

To see what other php packages you can install…

yum search php-

To install the full LAMP stack, read this.

Starting Apache

The apachectl script is more user friendly way of controlling the httpd (http daemon).  Some commands are …

apachectrl configtest (checkthe syntax of the apache config file)

apachectl start

apachectl stop

apachectl restart

apachectl graceful (A more graceful way of doing a restart)

apachectl status

These commands are easier to remember than to do …

service httpd start

To determine what version of Apache you have, type …

httpd -v

To determine if Apache is running …

ps aux | grep httpd

Or just go to browser and type in localhost.

Apache Configuration File

/etc/apache2/httpd.conf

To set the user document root of Apache for an user

0.  In httpd.conf, enable these lines…

LoadModule userdir_module libexec/apache2/mod_userdir.so

Include /private/etc/apache2/extra/httpd-userdir.conf

LoadModule authz_core_module libexec/apache2/mod_authz_core.so

LoadModule authz_host_module libexec/apache2/mod_authz_host.so

In the file httpd-userdir.conf, enable line to …

Include /private/etc/apache2/users/*.conf

1. Create a Sites folder inside a user folder such as /Users/someuser/Sites

2.  Create a Apache configuration file for this user at /etc/apache2/users/someuser.conf that looks like …

<Directory "/Users/someuser/Sites/">
   Options Indexes MultiViews
   AllowOverride All
   Require all granted
</Directory>

3. Change the permission of the configuration file to …

chmod 644 someuser.conf

4. Restart apache

5.  Now …

localhost/~someuser/

will start serving files from that user’s directory in addition to the default main document root.

Enabling PHP in Apache config

Make sure the line …

LoadModule php5_module libexec/apache2/libphp5.so

is enabled.