Configuring Apache2 on Shunya OS¶
Getting Started¶
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
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:
<?php phpinfo(); ?>
Step 3:Restart apache2 server
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
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
<html>
<body>
<h1>example</h1>
</body>
</html>
gedit test.com/public_html/index.html
<html>
<body>
<h1>example</h1>
</body>
</html>
Step 2:Configure virtual host for apache2
cd /etc/apache2/extra
Open httpd-vhosts.conf and add
<VirtualHost *:80>
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
</VirtualHost>
<VirtualHost *:80>
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
</VirtualHost>
Step 3:Enable httpd-vhosts.conf
Open /etc/apache2/httpd.conf and uncomment the following line
IncludedOptional /etc/apache2/extra/httpd-vhosts.conf
Step 4:Restart apache2 server
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
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