The Apache virtual host mechanism allows for the possibility of storing multiple websites with different domains on a single web-server. At this point, there is no requirement to set up multiple websites but it's helpful to think of websites and domains as separate to web-servers. In addition to this, the Virtual Host mechanism allows a lot of control over how the website is processed. For example, the Virtual Host file also enables us to instruct Apache to follow a symbolic link and pull in the source code from the application from the user account we have created.
Before we proceed with the Virtual Host file order that your user account can be available to the webserver we need to create a symbolic link in the document root of the webserver. The document root is the directory on a web server where the web files are located. This is equivalent to the xampp\htdocs folder which we have been using in Windows environments. The document root of the webserver on Ubuntu is /var/www/html (this may vary in different flavours/versions of Linux). In order to create files in this folder you need to be logged in as root so if you find yourself still logged on to the tennisclub account type
to log out.
To create the symbolic link first change directory into the document root folder as follows:
to create the symbolic link to your application folder type
ln -s /home/tennisclub tennisclub
The settings for the Virtual Host live, like most settings on Linux, in /etc folder. As an Apache setting it will live under the /etc/apache2. To create a Virtual Host file for your application change directory into the sites-available folder as follows
To open the nano editor with which you can create a VirtualHost file for your application type
sudo nano tennisclub.conf
paste the following lines into your new file
<Directory /var/www/html/tennisclub> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory>
sudo a2ensite tennisclub.conf
Mod re-write is a module add-on to apache which enables apache to interpret regular expression rules in order to route urls to the correct location. PhalconPHPs routing functionality is dependent on mod-rewrite. To enable mod-rewrite type
sudo a2enmod rewrite
You now have a website in your document root folder that, when you visit http://your_server_ip_address/tennisclub, will follow the symbolic link and load the files from /home/tennisclub - the home folder of the user account tennisclub. This gives you the ability to control the permissions and files for the website through one, carefully controlled user account.