You are here

Apache Tricks - Ubuntu 12.04 LTS

This page contains various tricks done in Apache.

Change the apache execution user

Normally by default Apache executes in www-data:www-data context. This can be modified easily by adding two lines in file /etc/apache2/envvars. Say we want to execute Apache from my_user:my_user context.

  1. Go to file /etc/apache2/envvars
  2. Add/Modify two lines in /etc/apache2/envvars
    export APACHE_RUN_USER=my_user
    export APACHE_RUN_GROUP=my_user
    /etc/init.d/apache2 restart

Thats all, you have successfully changed user under which apache2 executes.

Grant root capability to apache execution user

To enable any user root capability you need to execute below command.

sudo usermod -aG sudo my_user

If you want everytime system restarts, this to be executed you can add this comamnd line in /etc/init.d/rc.local before case statement.

Enable clean url in apache
  1. Go to /etc/apache2/sites-available/default and modify
    <Directory /var/www/ >
    AllowOverride None
    </Directory >

    to

    <Directory /var/www/ >
    AllowOverride All
    </Directory >
  2. Enable rewrite module
    sudo a2enmod rewrite
Modify document root for apache web server
  1. Open file /etc/apache2/sites-available/default
  2. Modify line
    DocumentRoot /var/www/

    to

    DocumentRoot /var/www/new-document-root
  3. Modify below block

    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all

    to


    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
  4. Restart apache2
    /etc/init.d/apache2 restart

    Done. Now the document root is changed. If you access localhost in Mozilla, your new-document-root site shows up.

    PHP mcrypt
    apt-get install php5-mcrypt
    php5enmod mcrypt
    service apache2 restart
Change the apache execution user in ubuntu 14.04 LTS

Normally by default Apache executes in www-data:www-data context. This can be modified easily by adding two lines in file /etc/apache2/envvars. Say we want to execute Apache from my_user:my_user context.

  1. Go to file /etc/apache2/envvars
  2. Add/Modify two lines in /etc/apache2/envvars
    export APACHE_RUN_USER=my_user
    export APACHE_RUN_GROUP=my_user
    /etc/init.d/apache2 restart

Thats all, you have successfully changed user under which apache2 executes.

Grant root capability to apache execution user

To enable any user root capability you need to execute below command.

sudo usermod -aG sudo my_user

If you want everytime system restarts, this to be executed you can add this comamnd line in /etc/init.d/rc.local before case statement.

Enable clean url in apache
  1. Go to /etc/apache2/apache2.conf and modify
    <Directory>
    Options FollowSymLinks
    AllowOverride None
    Require all denied
    </Directory>

    to

    <Directory>
    Options FollowSymLinks
    AllowOverride All
    Require all denied
    </Directory>
  2. Modify below block in /etc/apache2/apache2.conf
    <Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
    </Directory>

    to

    <Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
    </Directory>
  3. Enable rewrite module
    sudo a2enmod rewrite
Modify document root for apache web server
  1. Open file /etc/apache2/sites-available/000-default.conf
  2. Modify line
    DocumentRoot /var/www/html

    to

    DocumentRoot /var/www/html/new-document-root
  3. Restart apache2
    /etc/init.d/apache2 restart

    Done. Now the document root is changed. If you access localhost in Mozilla, your new-document-root site shows up.

    PHP mcrypt
    apt-get install php5-mcrypt
    php5enmod mcrypt
    service apache2 restart