Install Apache with PHP for your HTPC

Install Apache with PHP for your HTPC

A good Apache configuration will give you the advantage of having every applications in one pocket. In other world, you won’t need to access plex, deluge, phpsysinfo, or any other web application via different ports. You will be able to access these applications via a domain name or subdomains.


In exemple could be a proxy to your http://localhost:32400/ which is the default plex address. So, if you are in a place where every other port then 80 and 443 are blocked, you won’t have any problem accessing your home network. It will also be easier to remember your http addresses.

You will also benefit of having all the apache configuration interjecting the process between your web application and the rest of the world. You could have openssl support, some advance ip filtering, advance virtual domains, username and password protection and so on…


Installing apache on linux is a piece of cake. And the configuration are basically the same on any operating system (XBMCbuntu, OpenElec, etc).

  1. Install Apache sudo apt-get install apache2
  2. Start Apache sudo /etc/init.d/apache2 start
  3. If everthing worked well you can now open open a browser and type: http://localhost or You should see the Apache2 Ubuntu Default Page. So that it for now, it is pretty useless without futher configuration so we encourage you to check the advance configuration topics below for more information on how to set up your home web server.apache_default_ubuntu
  4. You can always check if it works via another computer in your network by tapping your linux local ip address: I.E.: See Set Static Ip for more information.
  5. To check if your web site if reachable from the world wide, you can find your ip by checking here: Just type in your browser: http://your ipadress (I.e.  BE AWARE: If you have a rooter there is a great chance you will have to set up a port forwarding (See: Set up port forwarding for apache world wide access)
  6. Start apache on boot: update-rc.d apache2 defaults
  7. We highly suggest you to change the user that will run apache. Warning: Changing apache user to root is very not recommend for sever security risks. By default, the user that will run apache will be www-data. You can change this by editing this file: cat /etc/apache2/envvars. Change Those 2 lines:
    export APACHE_RUN_USER=www-data
    export APACHE_RUN_GROUP=www-data
  8. After changing the user, you need Apache to have the read access to your root directory, otherwise it will throw a permission error when you try to reach the index page. To do so, a good option would be to create a folder in the home directory of the apache user (i.e. : /home/apache-user/www/ ).
  9. Create Folder and change permission (Change apache-user and apache-group with whatever you like):
    sudo mkdir /home/apache-user/www
    chown apache-user:apache-group /home/apache-user/www
    chmod 774 /home/apache-user/www
  10. To change your root directory in apache edit the config file: cat etc/apache2/sites-enabled/000-default.conf. Change The line DocumentRoot /var/www/html to: DocumentRoot /home/apache-user/www/
  11. Restart Apache:  sudo /etc/init.d/apache2 restart


This is not necessary, but it will give you the opportunity to write custom script. It will also be good if you want to add some web application to monitor your htpc away from home. In exemple: phpsysinfo is a very interesting php framework. It monitor your HTPC via a web interface. To do so you need a basic installation of php:

  1. Install php: sudo apt-get install libapache2-mod-php5
  2. Enable php module: sudo a2enmod php5
  3. Restart Apache: sudo /etc/init.d/apache2 restart
  4. Check if php is install by going to your web folder. By default it should be there: /var/www/html (you can find your root folder by checking in your apache configuration file. By default this file should be here: /etc/apache2/sites-enabled/000-default.conf. Look for the line starting with: document root).
  5. So create a php file there: echo '<?php phpinfo(); ?>' | sudo tee -a /var/www/html/index.php
  6. Check if it works via a web browser: http://localhost/index.php



Here is some more advance topic of how to configure apache with your different set of applications and how to secure it via openSSL encryption.

  1. Create a custom web page to monitor your HTPC
  2. Install phpsysinfo for extended HTPC monitoring
  3. Link Apache, deluge and plex to your domain name and secure them with OpenSSL