Enable and disable both Apache site configurations and additional functionality in modules using a2ensite and a2dissite, including vhost_alias and rewrite.
- [Instructor] We've added a new site to Apache, but we haven't actually told Apache to enable the site. Let's do that now. As we saw in the previous video, the Apache site configuration uses symbolic links. Ubuntu provides a pair of commands to help with this. The first is, "a2ensite--Apache2 enable site", and the opposite is "a2dissite--Apache2 disable site". Practically speaking, it just creates or removes symbolic links from the enable directory to the available directory.
After using one of these commands, we'll need to reload Apache in order to use the changed configuration. Let's start by managing the Apache sites. From the terminal, let's enable the newly created site configuration using "a2ensite". This is an administrative command, so start with "sudo", then "a2ensite", and then the name of the site, "vboxsf". The configuration is changed and we're asked to reload the server configuration.
However, we've got a few more changes to make first. While we're at it, disable the default site, which just shows placeholder content. "Sudo a2dissite 000-default". Before we go any further, we're going to have to enable some additional functionality in Apache for this configuration to work. Apache uses components known as modules, which are basically a system of plug-ins that add specific functionality to Ubuntu commands and and assists with modules "a2enmod" and "a2dismod", which enable and disable Apach2 modules.
Similar to site commands, these create and remove symbolic links from the enabled to the available directory. Unlike sites, a restart is required after changing modules, as modules effect the functionality of the server itself. There are a couple common Apache modules that we need to enable. The first is URL rewriting, which improves usability and search friendliness, it's named "rewrite". The second is for virtual host aliases, which provides dynamically configured mass virtual hosting.
Basically, being able to share any folder in virtual box and have Apache serve it. The second one is named "vhost_alias". Let's enable these modules now. From the terminal, start with "sudo" for the administration command, then "a2enmod", followed by the name of the modules we'd like to enable, "rewrite vhost_alias". Now that we've made all the configuration changes, we're ready to tell the server to use the new configuration.
The status message says to restart the server. But why? There's a couple of reasons why the restart is required. Remember how we had a permission problem accessing the shared folder after we changed groups? The same thing will happen with Apache if we just reload. The Apache user need these new group permissions, and that doesn't work until a new session starts, which restarting will do. Also, we enabled and disabled modules, which changed our functionality and those won't take effect until the server is restarted. Alright, so how do we restart Apache? In Ubuntu, Apache is installed as a service that runs whenever the server us started named "apache2".
To manage services, use the Service command, which runs the service script that starts and stops the service. The syntax is service, followed by the name of the service and the action. A number of actions are available that are fairly self-explanatory. Start, stop, restart, and reload. Not every service supports reload. It's best practice to use Service when managing services whenever possible. Back in the terminal, the name of the service we want to restart is "apache2". Start with "sudo" for administrative commands, followed by "service apache2", and the action "restart".
Apache will restart with a new configuration. Let's make sure it's working. Open a browser. Navigate to the host name that we set up earlier, "sandbox.dev:8080/server-status". This is Apache's built-in diagnostic information. It'll say how long the server's been running, and what the various requests that are being served. The fact that we can see it, means it's working, which is fantastic.
The web server is up and running, but PHP is still in it's default configuration. Let's change that.
Note: The demonstrations use the Ubuntu distribution of Linux, but the skills are applicable to other Linux distributions.
- What is Linux and why should you use it?
- Choosing a Linux distribution
- Creating a virtual machine (VM)
- Managing Linux from the command line
- Configuring a Linux server
- Managing Apache sites and modules
- Configuring the MySQL database
- Configuring PHP for development
- Debugging PHP code in Linux
- Installing PHP tools such as Composer and CodeIgniter
- Managing VMs with VirtualBox
- Troubleshooting LAMP