Raspberry Pi + LAMP + FTP + SSH (Part 2)
04 Jun 2013
This is part 2 of a 3 part series. Part 1 and Part 3
Install and Configure VSFTP
sudo apt-get install vsftpd
Open configuration file for editing sudo vi /etc/vsftpd.conf and amend the following lines
- Change anonymous_enabled=NO
- Uncomment local_enable=YES
- Uncomment write_enable=YES
- Uncomment local_umask=022
- Uncomment and change tftpd_banner=Secure FTP server. Access strictly forbidden
Restart service sudo /etc/init.d/vsftpd restart
Test and check basic FTP is working from another PC.
Install and Configure Apache
Install Apache sudo apt-get install apache2
Test and check basic Web Site is working (from remote machine http://ip_address_of_raspberry_pi)
Install Mod Rewrite sudo a2enmod rewrite
Add index.php to /etc/apache2/mods-enabled/dir.conf (add index.php to beginning of list) sudo vi /etc/apache2/mods-enabled/dir.conf
Begin Optional Configure Virtual Host(s)
cd /etc/apache2/sites-available
Copy default configuration file to one of your choice sudo cp default hostname.of.your.site
Edit the file you just created sudo vi hostname.of.your.site and amend as below (extract)
<VirtualHost *:80>
ServerAdmin webmaster@hostname.of.your.site
ServerName hostname.of.your.site
ServerAlias *. hostname.of.your.site
DocumentRoot /home/your_name/public_html
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/your_name/public_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
ErrorLog ${APACHE_LOG_DIR}/main_error.log
...
CustomLog ${APACHE_LOG_DIR}/main_access.log common
Also change the entry in the default site to show access.log common
Make the file you just amended the default sudo a2ensite hostname.of.your.site (the opposite is a2dissite hostname.of.your.site to disable it)
End Optional Configure Virtual Host(s)
Navigate to your home folder and create a new folder for your web documents mkdir public_html
Restart apache sudo service apache2 restart
Install & Configure PHP5
Install PHP sudo apt-get install php5 php-pear php5-suhosin
Install PHP libraries sudo apt-get install php5-mysql
Test and check basic PHP file is working by creating a file with the following content
<?php phpinfo(); ?>
Save the file in the root directory of you web server which you created earlier (public_html) with the .php extension OR type php -v at the command prompt.
Edit the configuration file sudo vi /etc/php5/apache2/php.ini and change the following lines to match those below
-
error_reporting = **E_ALL E_STRICT** - error_log = /var/log/php_errors.log
Manually create the log file sudo touch /var/log/php_errors.log
Change ownership (www-data is the account APACHE runs under so I believe) sudo chown www-data: /var/log/php_errors.log
Change permissions sudo chmod +rw /var/log/php_errors.log
Restart apache sudo service apache2 restart
#####Install & Configure MySQL Server
Install MySQL sudo apt-get install mysql-server
Edit the MySQL configuration file sudo vi /etc/mysql/my.cnf and change to suite the static IP you configured earlier
- bind-address = 192.168.x.y (substitute your own IP here)
Restart MySQL sudo service mysql restart
Log into MySQL (enter your password) mysql -u root –p
Use the mysql database (which holds the user table) use mysql
Create the user(s) you require (type these on the command line)
- create user ‘your_username’@’localhost’ identified by ‘your_password’;
- grant all privileges on *.* to ‘your_username’@’localhost’ with grant option;
- create user ‘your_username’@’%’ identified by ‘your_password’;
- grant all privileges on *.* to ‘your_username’@’%’ with grant option;
- flush privileges;
Harden the installation mysql_secure_installation