Snippets

Chris Charlton Apache commands

Created by Chris Charlton

File Apache.md Added

  • Ignore whitespace
  • Hide word diff
+# Apache commands
+Commands quick reference for working with Apache.
+
+###### Apache config files
+* `/etc/apache2/apache2.conf` - Main configuration file. It is recommended to use separate, designated files for simplicity. This file is usually used to configure defaults and be the central point of access for the server to read configuration details.
+* `/etc/apache2/ports.conf` - Used to specify the ports that virtual hosts should listen on. Be sure to check that this file is correct if configuring SSL.
+* `/etc/apache2/conf.d/` - Directory used for controlling specific aspects of the Apache configuration. For example, define SSL configuration and default security choices here instead of the global config.
+* `/etc/apache2/sites-available/` - Directory contains all virtual host files, for each hosted web site. These are available configurations, not active configurations.
+* `/etc/apache2/sites-enabled/` - Directory establishes which virtual host definitions are actually being used. Usually, consists of symbolic links to files defined in the "sites-available" directory.
+* `/etc/apache2/mods-[enabled,available]/` - These directories are similar in function to the sites directories, but they define modules that can be optionally loaded instead.
+
+###### Default Virtual Host File
+`/etc/apache2/sites-available/default`
+
+## General Apache commands
+
+#### Get Apache version
+```
+httpd -v
+```
+
+#### Find Apache
+##### The easy way...
+```
+apache2ctl -V
+```
+Outputs what config and server settings are being used.
+
+##### The not-as-easy way...
+```
+ps -ef | grep apache
+```
+Get the path of running Apache.
+
+```
+sudo apachectl -V | grep SERVER_CONFIG_FILE
+```
+...or...
+
+```
+/usr/sbin/apache2 -V | grep SERVER_CONFIG_FILE
+```
+May produce config errors, versus first option. 
+Example output: `-D SERVER_CONFIG_FILE="/etc/apache2/apache2.conf"`
+
+
+
+## Managing Apache
+
+#### Start, Stop, and Restart Apache
+```
+service apache2 [start|stop|graceful-stop|graceful|restart]
+```
+...or...
+
+```
+apachectl [start|stop|graceful-stop|graceful|restart]
+```
+`graceful` is the same as `restart` but not as abrupt.
+
+#### Reload apache config
+```
+sudo service apache2 reload
+```
+
+#### Stop everything NOW!
+```
+apachectl -k stop
+```
+"Immediately attempts to kill off all of its children. It may take it several seconds to complete killing off its children. Then the parent itself exits. Any requests in progress are terminated, and no further requests are served."
+
+
+## Adding & Removing new sites in Apache
+
+#### Enable a new site
+```
+sudo a2ensite VIRTUAL_HOST_FILE_NAME
+```
+Then reload the config to make site active.
+
+#### Disable an active site
+```
+sudo a2dissite VIRTUAL_HOST_FILE_NAME
+```
+Then reload the config to make site inactive.
+
+#### Enable & Disable Apache Modules
+Modules can be enabled or disabled by using the `a2enmod` and `a2dismod` commands respectively. They work the same way as the enable/disable sites command.
+
+
+
+## Additional Apache commands
+
+#### Run syntax check for config files
+```
+apachectl -t
+```
+
+#### Show all loaded modules
+```
+apachectl -t -D DUMP_MODULES
+```
+
+#### List all compiled Apache modules
+```
+apachectl -l
+```
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.