Category Archives: Web Hosting - Page 2

What version of Apache am I running?

Httpd is the Apache HyperText Transfer Protocol (HTTP) server program. To display the current apache version, type the following in your terminal window:
# httpd -v
Sample output:

Server version: Apache/2.2.3
Server built:   Oct 28 2008 07:22:45

Output list of modules compiled into the server:

# httpd -l
This will not list dynamically loaded modules included using the LoadModule directive. To dump a list of loaded Static and Shared Modules:
# httpd -M
Sample output:

Loaded Modules:
 core_module (static)
 mpm_prefork_module (static)
 http_module (static)
 so_module (static)
 auth_basic_module (shared)
 auth_digest_module (shared)
 authn_file_module (shared)
 authn_alias_module (shared)
 authn_anon_module (shared)
 authn_dbm_module (shared)
 authn_default_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 authz_owner_module (shared)
 authz_groupfile_module (shared)
 authz_dbm_module (shared)
 authz_default_module (shared)
 ldap_module (shared)
 authnz_ldap_module (shared)
 include_module (shared)
 log_config_module (shared)
 logio_module (shared)
 env_module (shared)
 ext_filter_module (shared)
 mime_magic_module (shared)
 expires_module (shared)
 deflate_module (shared)
 headers_module (shared)
 usertrack_module (shared)
 setenvif_module (shared)
 mime_module (shared)
 dav_module (shared)
 status_module (shared)
 autoindex_module (shared)
 info_module (shared)
 dav_fs_module (shared)
 vhost_alias_module (shared)
 negotiation_module (shared)
 dir_module (shared)
 actions_module (shared)
 speling_module (shared)
 userdir_module (shared)
 alias_module (shared)
 rewrite_module (shared)
 proxy_module (shared)
 proxy_balancer_module (shared)
 proxy_ftp_module (shared)
 proxy_http_module (shared)
 proxy_connect_module (shared)
 cache_module (shared)
 suexec_module (shared)
 disk_cache_module (shared)
 file_cache_module (shared)
 mem_cache_module (shared)
 cgi_module (shared)
 version_module (shared)
 chroot_module (shared)
 perl_module (shared)
 php5_module (shared)
 proxy_ajp_module (shared)
 python_module (shared)
Syntax OK

Print the version and build parameters of httpd, and then exit

Type the command:
# httpd -V
Sample output:

Server version: Apache/2.2.3
Server built:   Oct 28 2008 07:22:45
Server's Module Magic Number: 20051115:3
Server loaded:  APR 1.2.7, APR-Util 1.2.7
Compiled using: APR 1.2.7, APR-Util 1.2.7
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="logs/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="logs/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

To view other configuration settings open httpd.conf file (usually located in /etc/httpd directory).Red hat, CentOS and Fedora stores httpd at the following location:
# vi /etc/httpd/conf/httpd.conf
Debian and Ubuntu stores httpd.conf in apache2.conf file at the following location:
# vi /etc/apache2/apache2.conf
FreeBSD stores apache2.2 configuration at the following location:
# vi /usr/local/etc/apache22/httpd.conf
If you made any changes to httpd.conf, check httpd syntax for error using the -t option:
# httpd -t

Using SSI (Server Side Includes) with domain aliases

I had several domain aliases and wanted to show a different html page based on the domain visited. Since these sites are all very similar, I wanted to share images and other content between them. I also wanted to be able to update the content in only one location. After some research, I determined that SSI could do exactly what I needed.

Add lines to your .htaccess file

Options +Includes
AddType text/html .shtml
AddHandler server-parsed .html .shtml
DirectoryIndex index.shtml index.html index.php

Enter the following in your index.html file

<!–#if expr='”$HTTP_HOST” = “domain1.tld” || “$HTTP_HOST” = “www.domain1.tld”‘–>
<!–#include virtual=”domain1.html” –>
<!–#elif expr='”$HTTP_HOST” = “domain2.tld” || “$HTTP_HOST” = “www.domain2.tld”‘–>
<!–#include virtual=”domain2.html” –>
<!–#elif expr='”$HTTP_HOST” = “domain3.tld” || “$HTTP_HOST” = “www.domain3.tld”‘–>
<!–#include virtual=”domain3.html” –>
<!–#elif expr='”$HTTP_HOST” = “domain4.tld” || “$HTTP_HOST” = “www.domain4.tld”‘–>
<!–#include virtual=”domain4.html” –>
<!–#else–>
<!–#include virtual=”NoneOfThese.html” –>
<!–#endif–>

Explanation of above:

Options +Includes Turn on includes
AddType text/html .shtml Recognize .shtml file extension
AddHandler server-parsed .html .shtml Process both .html and .shtml for SSI
DirectoryIndex index.shtml index.html index.php Display index pages in this order

You can find many resources online that will explain all the features of SSI. Here, I am only looking to say “if the domain visited is X.com or www.X.com, then show X.html”.

Breakdown of SSI index.html

<!–# … –> Process for SSI
<!–#if expr=’ … ‘–> Start ‘If’ evaluation. If … is true, then execute next action
“$HTTP_HOST” String value for current domain name
“$HTTP_HOST” = “domain1.tld” Value of ‘True’ if current domain is domain1.tld
|| ‘Or’ operation. If either is true, then result is true
include virtual=”domain1.html” Insert content from domain1.html
<!–#elif expr=’ … ‘–> If nothing true yet, then continue checking elseif lines
<!–#else–> If noting was true, then execute next line
<!–#endif–> Stop processing this ‘If’ statement

 

Joyent (TextDrive) shared server addresses

Here are important addresses for TextDrive (VCII, VCIII, VCIV, Mixed Grill) and Joyent (Accelerator and Golden Ticket upgraded) shared hosting accounts.

Newer accounts (Joyent):

Virtualmin

https://virtualmin.joyent.us/SERVER/

https://virtualmin.joyent.us/SERVER/password-recovery/

Usermin and Webmail

https://usermin.joyent.us/SERVER/

SSH or SFTP

SERVER.joyent.us

phpMyAdmin

https://SERVER.joyent.us/phpmyadmin/

DNS

  • dns1.joyentdns.com
  • dns2.joyentdns.com
  • dns3.joyentdns.com
  • dns4.joyentdns.com

Older accounts (TextDrive):

Webmin

https://webmin.SERVER.textdrive.com/

Usermin

https://usermin.SERVER.textdrive.com/

SSH or SFTP

SERVER.textdrive.com

phpMyAdmin

https://mysql.SERVER.textdrive.com/

Webmail

https://webmail.textdrivehosting.com/

DNS

  • dns1.textdrive.com
  • dns2.textdrive.com
  • dns3.textdrive.com
  • dns4.textdrive.com

htaccess 301 (permanent) Redirect and RedirectMatch

There are many different types of redirects. Here are a few different permanent redirects. All of these can be added to your htaccess file. The directories listed are relative to the htaccess location.

Redirect visitors of a single page to a different page.

# Redirect permanent /directory/index.html http://subdomain.domain.tld/AnotherPage.html

Redirect visitors of any page within a directory to a specific page.

# RedirectMatch 301 ^/mydirectory/ http://subdomain.domain.tld/AnotherPage.html

Redirect visitors of any page within a directory to that page in a different location. Notice the missing slash here, compared to above.

# RedirectMatch 301 ^/mydirectory http://subdomain.domain.tld/AnotherPage.html

Redirect your entire website to any other domain or directory

# Redirect 301 / http://domain.tld/

301 (Permanent) Redirect: Point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the “my-example.com” domain:

# This allows you to redirect your entire website to any other domain
Redirect 301 / http://my-example.com/

302 (Temporary) Redirect: Point an entire site to a different temporary URL. This is useful for SEO purposes when you have a temporary landing page and plan to switch back to your main landing page at a later date:

# This allows you to redirect your entire website to any other domain
Redirect 302 / http://my-example.com/

Redirect index.html to a specific subfolder:

# This allows you to redirect index.html to a specific subfolder
Redirect /index.html http://example.com/newdirectory/

Redirect an old file to a new file path:

# Redirect old file path to new file path
Redirect /olddirectory/oldfile.html http://example.com/newdirectory/newfile.html

Redirect to a specific index page:

# Provide Specific Index Page (Set the default handler)
DirectoryIndex index.html

mod_rewrite subdomain to directory (not redirect)

This is the code I used to setup a subdomain on my webserver. Paste these lines into the .htaccess file at the root level of the web/public folder. It seemed that nothing I read online could satisfy my needs and I found mod_rewire to be very challenging to work with. My main problem was that I ended up creating a loop and didn’t know it.

Here are my requirements:

  • When users visit http://subdomain.domain.tld, display files located at http://domain.tld/mydirectory/
  • Do not show /mydirectory/ in the url.
  • Allow for the possibility of a user prefixing the subdomain with www.

Steps

  • Make sure your DNS settings are correct. If you host your own DNS, setup an A record * and point to your IP Address. [*.domain.tld   A   1.2.3.4].
  • Make sure your webserver is setup to handle wildcard subdomains.
  • Test your DNS by performing a lookup of subdomain.domain.tld
  • Test your webserver by visiting subdomain.domain.tld and you should see the same thing you would see at domain.tld.
  • Add the following code to your .htaccess file

Code Summary

# Required for mod_rewrite to work
Options +FollowSymLinks

# Users should not view my directory listing.
# Other sites are wrong that this is required.
Options -Indexes

# Turn on mod_rewrite
RewriteEngine On

# Set directory for rewrites to occur, based on htaccess location.
# Mine will occur at the root level.
RewriteBase /

# Don’t mess with www.domain.tld
# Unnecessary in this rule because no regexp
# used in subdomain portion of the next condition.
# Left here because it is used in some of my other rules.
RewriteCond %{HTTP_HOST} !www.domain.tld$ [NC]

# Select what to rewrite.
# Only process pages beginning with
# www.subdomain.domain.tld or subdomain.domain.tld.
# Stores anything after ‘subdomain.domain.tld’ as string variable $1
RewriteCond %{HTTP_HOST} ^(www.)?subdomain.domain.tld [NC]

# Prevent a loop.
# Don’t process pages that already referencing correct directory.
RewriteCond %{REQUEST_URI} !mydirectory/ [NC]

# This tells mod_rewrite to load files in mydirectory.
# $1 is the string variable stored from
RewriteRule (.*) mydirectory/$1 [L]

Just the code

Options +FollowSymLinks
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?subdomain.domain.tld [NC]
RewriteCond %{REQUEST_URI} !mydirectory/ [NC]
RewriteRule (.*) mydirectory/$1 [L]