Litespeed - Serve a PHP domain

Now the PHP host template has been configured we can start to serve PHP domains. We'll sort out some permission issues and then create a PHP virtual host (this takes around 10 seconds per domain).

When we first created the user 'paul', it was in the group 'paul'. When we setup Litespeed we used the user www-data in the group www-data.

You may notice the difference in the names! First thing is to add the user 'paul' to the group www-data:

sudo usermod -a -G www-data paul

This simply adds the user 'paul' to the group 'www-data'. You will have to log out and log back in for the group change to take effect. You can see what groups your username belongs to via:

groups

If it reports more than paul and www-data ask yourself if 'paul' needs to be in those groups.

Looking back to the Virtual Host Layout article, we see how the PHP domain can be laid out.

To keep this consistency, let's create that layout now. We'll start by creating the public_html directory (if it does not already exist) and move into it:

mkdir ~/public_html
cd public_html

Now we can create the main directory for our PHP domain. I've used the name phpdomain.com for the folder - use your domain name here so if this site was a PHP domain, I would call the folder usefuljaja.com:

mkdir phpdomain.com
cd phpdomain.com

Now we have the main virtual host folder, we can create the skeleton structure for our PHP virtual host:

mkdir log
mkdir config
mkdir cgi-bin
mkdir private
mkdir public

The folder names speak for themselves, but do refer to the Virtual Host Layout article if you want a refresher.

Lets create a very simple php index file for our domain - once we know this works, simply replace it with your site folders and files.

nano public/index.php

You can put whatever you like in the index.php file and the example below is a very simple example of a php test:

<html>
  <head>
    <title><?php echo $_SERVER['SERVER_NAME']; ?></title>
  </head>
  <body>
    <?php
      echo "<h1>" . $_SERVER['SERVER_NAME'] . "</h1>";
    ?>
  </body>
</html>

One final change is to set the permissions on the public_html folder. We need to change the group for the folder to www-data:

sudo chgrp -R www-data ~/public_html

When a file is written by Litespeed, for example when uploading a file or creating a dynamic page, the file is given the user and group www-data as that is the user and group the Litespeed server belongs to.

We need to make sure that each file and folder is readable and writeable by the user paul and the group www-data. To enable this, we use the command:

sudo chmod -R 2770 ~/public_html

The 2 makes the permissions 'sticky' so any file written by the user is given the group www-data. The 770 means that the user and the group have read/write permissions and everybody else has nothing - they can't even see the files.

That's it.

Now login to the Litespeed Admin Area and go to the Virtual Host Template area:

Click on the PHP_SuEXEC link:

Click on 'Add' in the Member Virtual Hosts area. You will see a very simple form - we have to fill out three boxes - 'Virtual Host Name', 'Domain' and 'Aliases':

For consistency and ease of administration, call the Virtual Host Name the same as your domain name:

Virtual Host Name         phpdomain.com
Domain                        phpdomain.com
Aliases                         www.phpdomain.com

That's all the configuration you have to do to add a Virtual Host. Three bits of information.

Click 'Save'. You will notice that your new domain has been added to the Member Virtual Hosts list:

You could leave the domain there but we are going to 'Instantiate' it. This simply means that it will be an independent Virtual Host so if any changes were made to the PHP template, it would have no effect on our domain. It also means we can tweak and adjust any setting within our Virtual Host and it will not effect anything else.

So, click 'Instantiate', confirm you want to do this by clicking 'Yes' (very Windows like!), Apply Changes and gracefully restart the server.

Now, assuming you have the domain DNS pointing to your VPS (if not, see the setting up your domain article), navigate to your domain, i.e. http://www.phpdomain.com and you will be greeted with your test PHP page giving your domain name.

Any changes to the domain can be made from the Virtual Hosts page as it is now an independent configuration.

PickledOnion.

Digg it | del.icio.us | reddit | StumbleUpon

Article Comments:

toby 10 May, 2007

Each time i get to the Instantiate point and click yes I see "invalid path: /config" do you have any thoughts as to why I get this and possible solutions?

Cheers

PickledOnion 10 May, 2007

Hi Toby,

It sounds as if you have not created the directory 'config' at the VH_ROOT. It should contain log, config, cgi-bin, private and public. Don't forget to set the permissions as well.

If you get any more problems, just email me. I am sure we can sort this out.

PickledOnion

Gleb Esman 14 Jul, 2007

Paul, I create second virtual host and they both were running fine non-instantiated. I decided to instantiate second virtual host and received "permission denied error" while creating configuration file. I decided to repeat 2 commands: sudo chgrp -R www-data ~/public_html sudo chmod -R 2770 ~/public_html

  • and after this I was able to successfully instantiate and run new virtual host. Originally I thought it was "one-time" job. Wondering if it necessary to repeat this procedure for every new domain?

Gleb

PickledOnion 14 Jul, 2007

Hi Gleb,

Yes you will need to create a virtual host for each domain or Litespeed will not know what to serve.

If you meant do you need to instantiate each virtual host - the answer to that is if you want an independent virtual host then yes.

If you don't instantiate it then it will take settings from the virtual host template. This may be fine for a few of your domains but, as said, if you want settings unique to that domain (awstats for example) then you will need to instantiate it.

I explain the difference here: Instantiating a Virtual Host".

I hope that helps,

PickledOnion.

Gleb Esman 15 Jul, 2007

Thanks for the detailed answer. I actually meant to ask if it is needed to repeat 2 'sudo' commands for every host separately.

Gleb

Comments are closed for this article.