Apache & Webroot

Where’s Apache and webroot for the different distros?


# Redhat, Fedora, Centos, Amazon Linux
# Debian, Ubuntu, Mint

Apache Configuration:

# Redhat, Fedora, Centos, Amazon Linux
# Debian, Ubuntu, Mint

How to Rotate Apache Logs

Apache comes with a logrotate utility. You can customize the way logrotate behaves by editing the /etc/logrotate.d/apache file. The logrotate utility has many options. In this example, we are rotating the log files that are located at the /var/www/domain.com/log/ directory. We are instructing the log files to rotate monthly for a total of 24 times. We are compressing the files by zipping them. We are using the date extension as part of the filename. We are also delaying the compression until the log has been rotated at least twice. Finally, Apache is restarted.

$ sudo nano /etc/logrotate.d/apache
/var/www/domain.com/*.log {
  rotate 24
  create 640 root adm
    if /etc/init.d/apache2 status > /dev/null ; then \
      /etc/init.d/apache2 reload > /dev/null; \
    if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
      run-parts /etc/logrotate.d/httpd-prerotate; \
    fi; \

To learn more about the logrotate utility, please visit the documentation.

Get Apache Version

To find out what version of Apache running on your server, type the following.

Ubuntu-based distros

apache2 -V

Debian-based distros

apachectl -V

Redhat-based distros

httpd -V

Apache Virtual Host on Mac

Creating an Apache virtual host on your Mac is quite easy. Assuming you already have Apache installed and running on your Mac, you will now have to decide whether to serve your pages from the default web root, or create your own virtual host, and serve your pages from an alternate location.

This article is part of a series of articles on how to manually install MAMP or Apache, PHP, MySQL on the Mac OS. Installing the popular MAMP application is as simple as installing any other application on the Mac, but it will not give you any valuable learning experience, nor will you have complete control of your development environment. I recommend manually installing the individual applications to maximize your learning experience.

Create an Apache Virtual Host on Mac OS X

Edit the /etc/apache2/httpd.conf file using the nano editor.

$ sudo nano /etc/apache2/httpd.conf

Look for the text ‘# Virtual hosts’ located at the end of the file. Uncomment by removing # from the line that says:

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

Save file and exit. If your not familiar with nano, it’s Ctrl-O for save, and Ctrl-X for exit.

Now edit the https-vhosts.conf file.

$ sudo nano /private/etc/apache2/extra/httpd-vhosts.conf

Append the following at the end of the file:

<VirtualHost *:80>
	DocumentRoot "/Users/Ulysses/Sites/"
	ServerName ulysses.dev
	ErrorLog "/private/var/log/apache2/ulysses.dev.local-error_log"
	CustomLog "/private/var/log/apache2/ulysses.dev.local-access_log" common
	<Directory "/Users/Ulysses/Sites/">
		AllowOverride All
		Order allow,deny
		Allow from all

In this example, I am using an alternate web root located at ‘/Users/Ulysses/Sites/.’ In addition, I’m also using a made-up domain called ‘ulysses.dev.’ I used .dev because it’s not a real top level domain or TLD. There won’t be a conflict with a real existing domain on the Internet. You can use any domain or TLD that you like.

The final step. Edit your hosts file to add your domain. This step is very important since we are using a made-up domain that doesn’t exist. By editing our hosts file, we are spoofing our system that a host does exist.

$ nano /private/etc/hosts

Add the following domain at the end of the line. is the loopback address of your system.  ulysses.dev

Save file and exit.

Restart Apache

$ sudo apachectl restart

From the terminal ping your domain.

$ ping ulysses.dev

Write permissions

The Apache user on the Mac is _www and is part of the staff group. To make the Sites folder writeable to the Apache _www user, perform the following commands from the Terminal.

cd /Users/Ulysses
$ sudo chown -R _www:staff Sites
$ sudo chmod -R 755 Sites

Finally, open up your browser and access your domain. In this example, http://ulysses.dev.