Description
This document focuses on managing the server from the command line. Linux or Unix version is irrelevant in 99% of the cases, however, there are some commands specific to your operating system which you’ll also need to familiarize yourself with. All of these commands, once installed on the system, can be read about in more detail by using the ‘man’ command, which is short for ‘manual’. The manual will be help when you run into trouble on the job and it’s one of, or you your only available resource.
Any os-specific commands used throughout this site, as mentioned above, are going to be Red Hat, Centos or Fedora Linux commands. The main 2 commands handle package management details, ‘yum‘ and ‘rpm‘. See their respective manpages for more help with them: man rpm
or man yum
All commands listed here are safe to run and non-destructive to your system but you should always exercise caution when copying commands from any websites. It’s a good idea to setup an isolated test environment in a Virtual Machine manager like Vagrant or a spare laptop lying around for testing and running commands without fear of data loss.
Common Basic Server Configurations
These are the most common basic webserver software configurations for various operating systems, there are many other configurations as well.
LAMP Stack
Linux
Apache httpd
MySQL / Maria
PHP / Perl / Python
LEMP Stack
Linux
Enginx
MySQL / Maria
PHP / Perl / Python
MAMP Server
Mac OSX
Apache httpd
MySQL / Maria
PHP / Perl / Python
WAMP Server
Windows
Apache httpd
MySQL / Maria
PHP / Perl / Python
Also see: XAMPP
Basic Server Management
Remember that type case (aA) is important on Linux, Unix and Mac OSX operating systems. If a command has upper or lowercase letters it’s generally for a reason.
- cd
- – Change directory.
- chmod
- – Change mode of files and directories.
- chown
- – Change ownership of files and directories.
- cp
- – Copy files and directories.
- df
- – Displays total disk usage for mounted filesystems.
- du
- – Displays total disk usage for named directories.
- find
- – Searches a given directory structure for a named string and displays pertinent results.
- grep
- – Searches the named input file(s) (or standard input if no files are named, or the file name – is given) for lines containing a match to the given pattern.
- groupadd
- – reate a new group on the system.
- groupdel
- – Remove group on the system.
- ls
- – List files and directories.
- mv
- – Move or rename files and directories.
- nano
- – A popular text editor.
- rm
- – Remove or delete files and directories.
- passwd
- – Used to update a user’s authentication token(s).
- ps
- – Prints a list of currently running processes, their respective owners and process id’s.
- pwd
- – Print the name of the working directory.
- useradd
- – Add new users to the system.
- userdel
- – Delete users from the system.
- usermod
- – Modify users on the system.
- vi
- – A popular text editor.
Example: cd /var/www
Example: chmod -Rf 755 /var/www/example.com
Example: chown -Rf webuser:bob /var/www/example.com
Example: cp -r /var/www/exmaple.com ~/backups
Example: df -h
Example: du -chs /var/www/example.com
Example: find /home/ -iname "back*"
Example: grep -r -i "include_once*" /var/www/example.com
Example: groupadd sshusers
Example: groupremove sshusers
Example: ls -lash /var/www
Example: mv /var/www/example.com /var/www/example.net
Example: nano /var/www/example.com/index.php
Example: rm -f /var/www/example.com/testfile.php
Example: passwd bob
Example: ps aux
Example: pwd
Example: useradd bob
Example: useerdel bob
Example: usermod -a -G sshuusers bob
Example: vi /var/www/example.com/index.php
Advanced Server Management
These commands are generally used for maintenance, troubleshooting issues or monitoring the system.
- apachetop
- – Display real-time web server statistics in a like the ‘top’ command.
- dstat
- – Dstat is a versatile replacement for vmstat, iostat and ifstat and allows you to view all system resources instantly.
- htop
- – Interactive process viewer
- kill
- – Terminate a currently running or rogue process. also see: killall.
- mc
- – (Midnight Commander) Visual shell for Unix-like systems
- mytop
- – Display MySQL / MariaDB server performance info like the ‘top’ command.
- screen
- – Full featured virtual terminal and terminal sharing application.
- sed
- – Stream editor for filtering and transforming (inserting, deleting, rearranging, editing) text.
- strace
- – trace system calls and signals from a running program.
- su
- – Substitute user command. most commonly used to run commands / daemons which require root privileges, view / alter certain directories, files and log files.
- tail
- – View or output the last x=n lines of a file, useful for error log debugging.
Example: apachetop /var/log/httpd/example.com_access_log
Example: dstat
Example: htop
Example: kill -9 12345
Example: mc
Example: mytop
Example: screen -S unique_name
Example: sed -i 's/foo/foo_bar/g' /path/to/file
Example: strace /usr/sbin/httpd
Example: su -
Note: the ‘-‘ is important because it gives us the shell of the user which is handy for running commands without the full path.
Example: tail -f /var/log/httpd/example.com_error_log