LAMP on Debian 7 Print

  • 5

Install Apache Web

sudo apt-get install apache2



Edit Apache's httpd.conf

The apache2.conf can be found in /etc/apache2/ and configures resource usage.

This is an example of a configuration for a VPS with 2GB of RAM:

KeepAlive Off
 
...
 
<IfModule prefork.c>
StartServers 4
MinSpareServers 20
MaxSpareServers 40
MaxClients 200
MaxRequestsPerChild 4500
</IfModule>

 

NOTE:  The Apache config should be closely monitored. Different sites may require adjustment of these values to optimize performance. This configuration is presented as a good baseline.

Set Up Virtual Hosts

Create a file named yourdomain.com.conf in /etc/apache2/sites-available/ using your own domain in place of yourdomain.com in the filename and configuration:

NameVirtualHost *:80
 
<VirtualHost *:80>
ServerAdmin webmaster@yourdomain.com
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/yourdomain.com/public_html/
ErrorLog /var/www/yourdomain.com/logs/error.log
CustomLog /var/www/yourdomain.com/logs/access.log combined
</VirtualHost>
NOTE: you will need to make a new entry in your yourdomain.com.conf file like this for each domain you intend to host on your VPS

Now you must make the directories referenced in your vhost.conf file - remember to replace yourdomain.com with your actual domain name:
sudo mkdir -p /var/www/yourdomain.com/public_html
sudo mkdir /var/www/yourdomain.com/logs

Enable virtual host

sudo a2ensite yourdomain.com.conf

Restart Apache

sudo service apache2 restart



Install MySQL

sudo apt-get install mysql-server


Secure MySQL

We suggest you answer "yes" to all the options given when you run this command:

mysql_secure_installation


Create a Database

First you will need to log in to MySQL:

mysql -u root -p

Now, create a database and user, replacing webdata with your database name, webuser with your username, and password with a strong password:

create database webdata;
grant all on webdata.* to 'webuser' identified by 'password';

Quit MySQL:

quit

Install PHP

sudo apt-get install php5 php-pear

Install MySQL support:

sudo apt-get install php5-mysql

Edit the /etc/php.ini to improve performance, error messages, and logs:

error_reporting = E_COMPILE_ERROR | E_RECOVERABLE_ERROR | E_ERROR | E_CORE_ERROR
error_log = /var/log/php/error.log
max_input_time = 30


Create the error directory

sudo mkdir /var/log/php
sudo chown www-data /var/log/php


Restart Apache:

sudo service apache2 restart




Was this answer helpful?

« Back