The next step after setting up and securing VPS server is installing the software stack that is required for hosting websites. I am going to install Apache as web server, you can follow or install Nginx.
Installing Apache is easy just enter the below command. I have disabled root login and using a user account with admin privileges to manage server, that is why sudo is appended in the command line. If you are using root login then don’t enter sudo.
[shell]sudo apt-get install apache2[/shell]
After installing Apache you need to change some settings for better performance. Apache2 configuration is stored in apache2.conf file, previous apache versions used httpd.conf as config file, that is deprecated in apache2.
Open apache config file for editing with the following command.
[shell]sudo nano /etc/apache2/apache2.conf[/shell]
You need to change the values for MinSpareServers, MaxSpareServers, MaxClients and MaxRequestserChild according to your needs as a starter. Alternatively you can use .htaccess files to override apache configuration directives.
After you are done save changes to the file by pressing Ctrl + X and pressing Y.
Restart Apache for the change in settings to take effect.
[shell]sudo service apache2 restart[/shell]
Next you need to create directories for hosting files and need to create vhost files for domain names. We will see that later.
vhosts files can be created with the following command
[shell]sudo nano /etc/apache2/sites-available/example.com[/shell]
A typical vhost file for individual domains will look like this. Change the directory paths to domain name to reflect your setup.
[shell]# domain: mydoamin.com
# public: /var/www/hosts/mydomain.com/htdocs
# Admin email, Server Name (domain name), and any aliases
ServerAdmin webmaster@mydomain.com
ServerName www.mydomain.com
ServerAlias mydomain.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /var/www/hosts/mydomain.com/htdocs
# Log file locations
LogLevel warn
ErrorLog /var/www/hosts/mydomain.com/log/error.log
CustomLog /var/www/hosts/mydomain.com/log/access.log combined
[/shell]
After creating the file save with Ctrl+x and by pressing y.
Now enable the site using this command
[shell]sudo a2ensite mydomain.com[/shell]
Restart apache for the changes to take effect.
Other articles in this series
Dedicated VPS Server with Linode
How to install PHP and APC on Ubuntu VPS
Useful .htaccess tips and tricks
[…] Installing Apache webserver on Ubuntu VPS […]