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.
- Go to file /etc/apache2/envvars
- Add/Modify two lines in /etc/apache2/envvarsexport 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
- Go to /etc/apache2/sites-available/default and modify<Directory /var/www/ >
AllowOverride None
</Directory >to
<Directory /var/www/ >
AllowOverride All
</Directory > - Enable rewrite modulesudo a2enmod rewrite
Modify document root for apache web server
- Open file /etc/apache2/sites-available/default
- Modify lineDocumentRoot /var/www/
to
DocumentRoot /var/www/new-document-root - Modify below block
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from allto
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all - 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 mcryptapt-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.
- Go to file /etc/apache2/envvars
- Add/Modify two lines in /etc/apache2/envvarsexport 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
- 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> - 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> - Enable rewrite modulesudo a2enmod rewrite
Modify document root for apache web server
- Open file /etc/apache2/sites-available/000-default.conf
- Modify lineDocumentRoot /var/www/html
to
DocumentRoot /var/www/html/new-document-root - 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 mcryptapt-get install php5-mcrypt
php5enmod mcrypt
service apache2 restart