Apache HTTP Server (Apache)
- colloquially called Apache
- is free and open-source cross-platform web server software
Installation
macOS
1. mac comes pre-installed with apache server in
/private/etc/apache22. verify theApache version
httpd -vapachectl -v3. Start, Stop, Restart
sudo apachectl startsudo apachectl stopsudo apachectl restart4. Configuring Apache
sudo vi /private/etc/apache2/httpd.conf5. Default Document Root
/Library/WebServer/Documents
homebrew
Install
1. install apache server using home-brew
brew install pcre libtoolbrew install homebrew/apache/httpd242. verify theApache version
httpd -vapachectl -vConfiguration
1. Configuring Apache Conf
sudo vim /usr/local/etc/apache2/2.4/httpd.confsudo vim /usr/local/etc/httpd/httpd.confRestart
brew services start httpdbrew services stop httpdbrew services restart httpdIf you don’t want a background service
sudo apachectl startsudo apachectl stopsudo apachectl restart
yum
1. install apache server
sudo apt-get updatesudo apt-get install apache22. adjust firewall
show available app profiles
sudo ufw app listallow Apache port 80 and 443
sudo ufw allow ‘Apache Full’3. start apache server
sudo systemctl start apache24. verify it works
http://localhost
apt-get
Install
1. install apache server
sudo apt-get updatesudo apt-get install apache22. adjust firewall
show available app profiles
sudo ufw app listallow Apache port 80 and 443
sudo ufw allow ‘Apache Full’3. start apache server
sudo systemctl start apache24. verify it works
http://localhostConfiguration
- Configuring Apache: /etc/apache2/apache2.conf
Start Stop Restart
1. Start, Stop, Restart
sudo systemctl start apache2sudo systemctl stop apache2sudo systemctl restart apache22. If you are simply making configuration changes, Apache can often reload without dropping connections
sudo systemctl reload apache23. By default, Apache is configured to start automatically when the server boots
To disable this behavior by typing
sudo systemctl disable apache2To re-enable the service to start up at boot, you can type
sudo systemctl enable apache2
Forbidden You don't have permission to access / on this server
1. Error message “Forbidden You don’t have permission to access / on this server”
- go to this link
- http://stackoverflow.com/questions/10873295/error-message-forbidden-you-dont-have-permission-to-access-on-this-server
- quick answer, locate something like this in the http.conf and replace it with this
<Directory />#Options FollowSymLinksOptions Indexes FollowSymLinks Includes ExecCGIAllowOverride AllOrder deny,allowAllow from all</Directory>
Configuration
Click here to expand...
Apache HTTP Server is configured by placing directives in plain text configuration files. The main configuration file is usually called httpd.conf or apache2.conf
1. locate httpd binary
whereis httpd2. find which httpd.conf file the httpd binary loads
/path/to/httpd -V | grep SERVER_CONFIG_FILE.htaccess
.htaccess is a configuration file for use on web servers running the Apache Web Server software. When a .htaccess file is placed in a directory which is in turn ‘loaded via the Apache Web Server’, then the .htaccess file is detected and executed by the Apache Web Server software. These .htaccess files can be used to alter the configuration of the Apache Web Server software to enable/disable additional functionality and features that the Apache Web Server software has to offer. These facilities include basic redirect functionality, for instance if a 404 file not found error occurs, or for more advanced functions such as content password protection or image hot link prevention.
http.conf
1. Configuring Apache
sudo vi /usr/local/etc/apache2/2.4/httpd.conf2. enable PHP - uncomment this line in the httpd.conf file
LoadModule php5_module path/to/php.so/fileThe paths in httpd.conf are relative to HTTPD_ROOT
Which can be found with the command httpd -V
3. map the .php file extension to the PHP MIME type in Apache, search for the other AddType lines and add a new line below them:
AddType application/x-httpd-php .php
4. enable loading index.php as a directory index, replace DirectoryIndex index.html in httpd.conf with the following and restart Apache:
DirectoryIndex index.html index.php index.phtml
5. optional - Next remove the comment (the # symbol) from the beginning of the following lines to enable a few commonly used modules:
LoadModule expires_module libexec/mod_expires.soLoadModule deflate_module libexec/mod_deflate.soLoadModule rewrite_module libexec/mod_rewrite.so6. By default, Apache is configured to store your website directories in /usr/local/var/www/htdocs. To change this to another directory change the following lines:
DocumentRoot “/usr/local/var/www/htdocs”<Directory “/usr/local/var/www/htdocs”1. Configuring Apache
sudo vi /private/etc/apache2/httpd.conf2. enable PHP - uncomment this line in the httpd.conf file
LoadModule php5_module libexec/apache2/libphp5.solibexec/apache2/libphp5.so to pointing to /usr/libexec/apache2/libphp5.so
The paths in httpd.conf are relative to HTTPD_ROOT
Which can be found with the command httpd -V
3. map the .php file extension to the PHP MIME type in Apache, search for the other AddType lines and add a new line below them:
AddType application/x-httpd-php .php4. enable loading index.php as a directory index, replace DirectoryIndex index.html in httpd.conf with the following and restart Apache:
DirectoryIndex index.html index.php5. Next remove the comment (the # symbol) from the beginning of the following lines to enable a few commonly used modules:
LoadModule expires_module libexec/mod_expires.soLoadModule deflate_module libexec/mod_deflate.soLoadModule rewrite_module libexec/mod_rewrite.so6. By default, Apache is configured to store your website directories in /Library/WebServer/Documents. To change this to another directory change the following lines:
DocumentRoot “/Library/WebServer/Documents”<Directory “/Library/WebServer/Documents”>1. the httpd.conf should contain the line
Include /path/to/httpd/extra/vhosts/*.conf2. create directory to store all virtual host configurations
mkdir -p /path/to/httpd/extra/vhosts
Set Modules
Click here to expand...
php
Apache Server
PHP
this is for apache server apr and apr-util dependency
sudo apt-get install libapr1-dev libaprutil1-devthis is for apache server pcre dependency
sudo apt-get install libpcre3-dev libbz2-devthis is for php install
sudo apt-get install libxml2-devun-package apache server
Install from Site:
mod_evasive
Installation
yum 1. install mod_evasive
sudo yum install mod_evasive2. verify mod_evasive was installed
sudo httpd -M | grep evasiveapt-get
sudo apt-get install libapache2-mod-evasive
module against DoS and DDoS attacks