############################################################ Configuring Apache2 on Shunya OS ############################################################ Getting Started =============== Installation ------------- To install apache2 run the following command: .. code-block:: shell sudo opkg install apache2 Configuration ============== Apache2 configuration files are located in **/etc/apache2/httpd.conf**. Apache2 server root is located in **/usr/share/apache2/htdocs/** Configuring apache2 for php --------------------------- For using php with apache2 you need to install the following modules: php php-modphp **This can be done through the following command** **Step 1:Installing necessary modules** .. code-block:: shell sudo opkg install php php-modphp **Step 2:Write a php script in /usr/share/apache2/htdocs/** For testing purpose we created a minimal file /usr/share/apache2/htdocs/index.php **The test .php file contains a single line:** .. code-block:: php **Step 3:Restart apache2 server** .. code-block:: shell systemctl restart apache2 **Step 4:Test** To test this on the browser type the following in the URL: localhost/filename.php (in our case it was localhost/index.php) Configuring virtual-host for apache2 ------------------------------------ virtual-host allow users to use same ip address for different domain names. Let us take an example. Suppose we want to have 2 domain names called test.com and example.com on the same ip, the following steps will help us illustrate how virtual-hosts are achieved on Shunya-Os. **Step 1:Create 2 webpages** .. code-block:: shell cd /usr/share/apache2/htdocs sudo mkdir -p example.com/public_html test.com/public_html sudo chown -R shunya:shunya example.com/public_html test.com/public_html sudo chmod -R 755 /usr/share/apache2/htdocs gedit example.com/public_html/index.html .. code-block:: html

example

gedit test.com/public_html/index.html .. code-block:: html

example

**Step 2:Configure virtual host for apache2** .. code-block:: shell cd /etc/apache2/extra **Open httpd-vhosts.conf and add** .. code-block:: shell ServerAdmin admin@example.com ServerName example.com ServerAlias www.example.com DocumentRoot /usr/share/apache2/htdocs/example.com/public_html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined ServerAdmin admin@test.com ServerName test.com ServerAlias www.test.com DocumentRoot /usr/share/apache2/htdocs/test.com/public_html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined **Step 3:Enable httpd-vhosts.conf** Open **/etc/apache2/httpd.conf** and uncomment the following line .. code-block:: shell IncludedOptional /etc/apache2/extra/httpd-vhosts.conf **Step 4:Restart apache2 server** .. code-block:: shell sudo systemctl restart apache2 **Step 5:Add the websites to /etc/hosts** Open the /etc/hosts file and add example.com and test.com as shown below .. code-block:: shell 127.0.0.1 localhost.localdomain localhost test.com example.com **Step 6:Test** To test this on the browser type the following in the URL: http://test.com or http://example.com