How to Install Ubuntu or Mint LAMP (Linux Apache MySQL PHP) Server and Configure Vsftpd

Recipe # | posted in Howto, Linux | Comments

How to install LAMP in Ubuntu or Mint linux

1 – Problem Description

Install a new Ubuntu or Mint LAMP (Linux Apache MySQL PHP) Server and configure vsftpd. The solution in this problem assumes multiple projects with different ftp (virtual) users.

2 – Solution

Cast your self to root to avoid sudo in each command!

sudo -i

Install SSH

apt-get install ssh

Install Apache2

apt-get install apache2

Install PHP5

apt-get install php5 libapache2-mod-php5

Install MySQL Server

apt-get install mysql-server

Install phpMyAdmin

apt-get install phpmyadmin 

Install vsftpd

apt-get install vsftpd libpam-pwdfile

Configure vsftpd

vi /etc/vsftpd.conf

Add or edit the variables below in the config file and leave everything else with the default value. (press letter i in vi to start editing)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Run standalone?  vsftpd can run either from an inetd or as a standalone
# daemon started from an initscript.
listen=YES
#
# Run standalone with IPv6?
# Like the listen parameter, except vsftpd will listen on an IPv6 socket
# instead of an IPv4 one. This parameter and the listen parameter are mutually
# exclusive.
#listen_ipv6=YES
#
# Allow anonymous FTP? (Disabled by default)
anonymous_enable=NO
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
anon_upload_enable=YES
dirlist_enable=YES
download_enable=YES
guest_enable=YES
virtual_use_local_privs=YES
pam_service_name=vsftpd
user_sub_token=$USER
local_root=/var/www/$USER
#local_enable=yes

# As guest you can set your user name to avoid read/write perminsions changes when updating a WP plugin for example
guest_username=vsftpd

chroot_local_user=YES
user_config_dir=/etc/vsftpd_user_conf
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list

# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# If enabled, vsftpd will display directory listings with the time
# in  your  local  time  zone.  The default is to display GMT. The
# times returned by the MDTM FTP command are also affected by this
# option.
use_localtime=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
# This option should be the name of a directory which is empty.  Also, the
# directory should not be writable by the ftp user. This directory is used
# as a secure chroot() jail at times vsftpd does not require filesystem
# access.
secure_chroot_dir=/var/run/vsftpd/empty
#
# This string is the name of the PAM service vsftpd will use.
##pam_service_name=vsftpd
#
# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
rsa_cert_file=/etc/ssl/private/vsftpd.pem

# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=000

Press Esc and type the following characters :wq to save changes. $USER as we will see below could be the directory name of each web site.

Configure PAM to check the password file for users

vi /etc/pam.d/vsftpd

Add

1
2
auth required pam_pwdfile.so pwdfile /etc/ftpd.passwd
account required pam_permit.so

and remove everything else from the file.

Create the passwd file containing the users (projects) and add the first user (project), my_blog

If you use Ubuntu >= 12.04 or Mint >= 13 you need to use the -d in htpasswd since newer versions seems to use MD5 instead of Crypt that was default before.

htpasswd -cd /etc/ftpd.passwd my_blog

add more users (projects) if you like

htpasswd -d /etc/ftpd.passwd youjizz

Create folder vsftpd and create inside that folder a file chroot_list with the name of the sites

cd /etc; mkdir vsftpd; cd vsftpd; vi chroot_list

As before press i and write

my_blog
youjizz

Press :wq and [ENTER] key

Create folder vsftpd_user_conf

cd /etc; mkdir vsftpd_user_conf; cd vsftpd_user_conf

Create two files my_blog and youjizz and add

1
2
3
4
write_enable=YES
chroot_local_user=YES
user_sub_token=$USER
local_root=/var/www/$USER

Create user’s directory

cd /var/www/
mkdir my_blog
mkdir youjizz

Assuming you are working in two different projects my_blog and youjizz :P

Restart vsftpd

/etc/init.d/vsftpd restart

Enable mod_rewrite module (just in case ;))

a2enmod rewrite; service apache2 restart

Your server may not have the AllowOverride directive enabled. If the AllowOverride directive is set to None in your Apache config file, then .htaccess files are completely ignored. In this case, the server will not even attempt to read .htaccess files in the filesystem. When this directive is set to All, then any directive which has the .htaccess Context is allowed in .htaccess files.

Example of enabled AllowOverride directive in /etc/apache2/sites-available/default

1
2
3
4
 <Directory />
    Options FollowSymLinks
    AllowOverride All
 </Directory>

You may also have to enable the AllowOverride directive in your DocumentRoot:

1
2
3
4
 <Directory /var/www/html>
    # ... other directives...
    AllowOverride All
 </Directory>

This is done in case you set up WordPress on your server and you are trying to configure permalinks to this format /%category%/%postname%

Enjoy!

3 – References

[1] strdoc.com

[2] www.ubuntututorials.net

[3] howto.gumph.org

Comments