Raspberry Pi: installing a LAMP server

Let's put the Raspberry Pi to good use:

 

1. Install Mysql

sudo pacman -S mysql

2. Start your server

# systemctl start mysqld

3. Secure your mysql installation

# /usr/bin/mysql_secure_installation

——————-

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 … Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 … Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 … Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 – Dropping test database…
 … Success!
 – Removing privileges on test database…
 … Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 … Success!

Cleaning up…

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

———————-

 

# nano /etc/mysql/my.cnf

 

[mysqld]

bind-address=127.0.0.1

 

 

Restart mysql

systemctl restart mysqld

 

 

================

Install PHP

 

pacman -S php php-apache libmcrypt libtool

 

nano /etc/php/php.ini

 

 

 

======================

 

nano /etc/locale.gen

enable:

en_US.UTF-8 UTF-8
en_US ISO-8859-1

 

save and generate your locales

# locale-gen

 

 

Install and Configure PostgreSQL

pacman -S postgresql

 

# mkdir -p /var/lib/postgres/data

# chown httpd:httpd -Rv /var/lib/postgres/

 

Configure Postgresql data dir

# su – postgres -c "initdb –locale en_US.UTF-8 -D '/var/lib/postgres/data'"

———————–

The files belonging to this database system will be owned by user "httpd".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

fixing permissions on existing directory /var/lib/postgres/data … ok
creating subdirectories … ok
selecting default max_connections … 100
selecting default shared_buffers … 24MB
creating configuration files … ok
creating template1 database in /var/lib/postgres/data/base/1 … ok
initializing pg_authid … ok
initializing dependencies … ok
creating system views … ok
loading system objects' descriptions … ok
creating collations … ok
creating conversions … ok
creating dictionaries … ok
setting privileges on built-in objects … ok
creating information schema … ok
loading PL/pgSQL server-side language … ok
vacuuming database template1 … ok
copying template1 to template0 … ok
copying template1 to postgres … ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
–auth-local and –auth-host, the next time you run initdb.

Success. You can now start the database server using:

    postgres -D /var/lib/postgres/data
or
    pg_ctl -D /var/lib/postgres/data -l logfile start
 

——————————————

 

Enable the service

# systemctl enable postgresql

Start if you want to use it before rebooting

# systemctl start postgresql

 

Brighter LAMP: phpmyadmin installation

Install mcrypy for phpmyadmin dependencies:

 

# apt-get install php5-mcrypt

 

Now you need to restart apache for the changes to take effect

 

# /etc/init.d/apache2 restart

 

Now, on to the installation:

# apt-get install phpmyadmin

 

Choose Apache2 when you're prompted

 

 

Answer yes to Configure database for phpmyadmin with dbconfig-common?

 

 

after that,

 

Configure phpmyadmin

 

su – httpd

cd domains/

cd ~domains/debian.portnumber53.local/html

(Create the directory if it doesn't exist)

$ ln -s /usr/share/phpmyadmin .phpMyAdmin

 

 

 

nano /etc/phpmyadmin/config.inc.php

$cfg[‘blowfish_secret’] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

 

 

 

# nano /etc/php5/conf.d/suhosin.ini

Edit the following, keeping in mind that suhosin values may cause issues with some operations

suhosin.request.max_vars 2048
suhosin.request.max_value_length 1000000
suhosin.request.max_array_index_length 256
suhosin.request.max_totalname_length 8192
suhosin.post.max_vars 2048
suhosin.post.max_array_index_length 256
suhosin.post.max_totalname_length 8192
suhosin.post.max_value_length 1000000
suhosin.sql.bailout_on_error Off
suhosin.log.file 0
suhosin.log.phpscript 0
suhosin.log.phpscript.is_safe Off
suhosin.log.sapi 0
suhosin.log.script 0
suhosin.log.use-x-forwarded-for Off

 

 

Disable the warning

 

# nano /etc/phpmyadmin/config.inc.php

$cfg[‘SuhosinDisableWarning’] = true;

 

Setting up a Debian box for development: making a LAMP: php5

Now P for PHP 5:

 

# apt-get install php5 php-pear php5-suhosin

 

# nano /etc/php5/apache2/php.ini

 

max_execution_time = 30
memory_limit = 64M
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
display_errors = Off
log_errors = On
error_log = /var/log/php.log
register_globals = Off

 

Add mysql support.

# apt-get install php5-mysql

 

 

 

Setting up a Debian box for development: making a LAMP: mysql

Let's make a lamp

 

First M for Mysql:

# apt-get install mysql-server

The script will ask you to define the password for the root mysql user:

Secure your mysql installation:

# mysql_secure_installation

 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n
 … skipping.

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 … Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 … Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 – Dropping test database…
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 … Failed!  Not critical, keep moving…
 – Removing privileges on test database…
 … Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 … Success!

Cleaning up…

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!
 

 

Setting up a Debian box for development: making a LAMP: apache2

Add a user for the web stuff

# adduser httpd

Choose a simple (but secure) password.

# apt-get install apache2
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following extra packages will be installed:
  apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common libapr1 libaprutil1 libaprutil1-dbd-sqlite3
  libaprutil1-ldap
Suggested packages:
  apache2-doc apache2-suexec apache2-suexec-custom
The following NEW packages will be installed:
  apache2 apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common libapr1 libaprutil1
  libaprutil1-dbd-sqlite3 libaprutil1-ldap
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,155 kB of archives.
After this operation, 7,266 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://ftp.us.debian.org/debian/ squeeze/main libapr1 amd64 1.4.2-6+squeeze3 [94.2 kB]
Get:2 http://ftp.us.debian.org/debian/ squeeze/main libaprutil1 amd64 1.3.9+dfsg-5 [92.3 kB]
Get:3 http://ftp.us.debian.org/debian/ squeeze/main libaprutil1-dbd-sqlite3 amd64 1.3.9+dfsg-5 [28.1 kB]
Get:4 http://ftp.us.debian.org/debian/ squeeze/main libaprutil1-ldap amd64 1.3.9+dfsg-5 [25.7 kB]
Get:5 http://ftp.us.debian.org/debian/ squeeze/main apache2.2-bin amd64 2.2.16-6+squeeze4 [1,439 kB]
Get:6 http://ftp.us.debian.org/debian/ squeeze/main apache2-utils amd64 2.2.16-6+squeeze4 [164 kB]
Get:7 http://ftp.us.debian.org/debian/ squeeze/main apache2.2-common amd64 2.2.16-6+squeeze4 [308 kB]
Get:8 http://ftp.us.debian.org/debian/ squeeze/main apache2-mpm-worker amd64 2.2.16-6+squeeze4 [2,240 B]
Get:9 http://ftp.us.debian.org/debian/ squeeze/main apache2 amd64 2.2.16-6+squeeze4 [1,396 B]
Fetched 2,155 kB in 5s (423 kB/s)
Selecting previously deselected package libapr1.
(Reading database … 32742 files and directories currently installed.)
Unpacking libapr1 (from …/libapr1_1.4.2-6+squeeze3_amd64.deb) …
Selecting previously deselected package libaprutil1.
Unpacking libaprutil1 (from …/libaprutil1_1.3.9+dfsg-5_amd64.deb) …
Selecting previously deselected package libaprutil1-dbd-sqlite3.
Unpacking libaprutil1-dbd-sqlite3 (from …/libaprutil1-dbd-sqlite3_1.3.9+dfsg-5_amd64.deb) …
Selecting previously deselected package libaprutil1-ldap.
Unpacking libaprutil1-ldap (from …/libaprutil1-ldap_1.3.9+dfsg-5_amd64.deb) …
Selecting previously deselected package apache2.2-bin.
Unpacking apache2.2-bin (from …/apache2.2-bin_2.2.16-6+squeeze4_amd64.deb) …
Selecting previously deselected package apache2-utils.
Unpacking apache2-utils (from …/apache2-utils_2.2.16-6+squeeze4_amd64.deb) …
Selecting previously deselected package apache2.2-common.
Unpacking apache2.2-common (from …/apache2.2-common_2.2.16-6+squeeze4_amd64.deb) …
Selecting previously deselected package apache2-mpm-worker.
Unpacking apache2-mpm-worker (from …/apache2-mpm-worker_2.2.16-6+squeeze4_amd64.deb) …
Selecting previously deselected package apache2.
Unpacking apache2 (from …/apache2_2.2.16-6+squeeze4_amd64.deb) …
Processing triggers for man-db …
Setting up libapr1 (1.4.2-6+squeeze3) …
Setting up libaprutil1 (1.3.9+dfsg-5) …
Setting up libaprutil1-dbd-sqlite3 (1.3.9+dfsg-5) …
Setting up libaprutil1-ldap (1.3.9+dfsg-5) …
Setting up apache2.2-bin (2.2.16-6+squeeze4) …
Setting up apache2-utils (2.2.16-6+squeeze4) …
Setting up apache2.2-common (2.2.16-6+squeeze4) …
Enabling site default.
Enabling module alias.
Enabling module autoindex.
Enabling module dir.
Enabling module env.
Enabling module mime.
Enabling module negotiation.
Enabling module setenvif.
Enabling module status.
Enabling module auth_basic.
Enabling module deflate.
Enabling module authz_default.
Enabling module authz_user.
Enabling module authz_groupfile.
Enabling module authn_file.
Enabling module authz_host.
Enabling module reqtimeout.
Setting up apache2-mpm-worker (2.2.16-6+squeeze4) …
Starting web server: apache2.
Setting up apache2 (2.2.16-6+squeeze4) …

# a2enmod rewrite
Enabling module rewrite.
Run '/etc/init.d/apache2 restart' to activate new configuration!

# nano /etc/apache2/envvars

export APACHE_RUN_USER=httpd
export APACHE_RUN_GROUP=httpd

We will activate the Mass Hosting module for Apache so we can develop a bunch of projects at the same time

We need a file to correct the value of DOCUMENT_ROOT when using such module:

<?php

// Let's fix the document root because of a bug in Apache's mod_vhost_alias not
// setting up the correct $_SERVER[‘DOCUMENT_ROOT’] env variable.
$__mod_vhost_alias_fix_doc_root = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'domains' . DIRECTORY_SEPARATOR . $_SERVER[‘HTTP_HOST’] . DIRECTORY_SEPARATOR . 'html';

if (is_dir($__mod_vhost_alias_fix_doc_root)) {
$_SERVER[‘__MOD_VHOST_FIX_OLD_DOCUMENT_ROOT’] = $_SERVER[‘DOCUMENT_ROOT’];
    $_SERVER[‘DOCUMENT_ROOT’] = $__mod_vhost_alias_fix_doc_root;
}

?>

We create a configuration file for virtual hosts:

nano /etc/apache2/sites-available/vhosts
# get the server name from the Host: header
UseCanonicalName Off

# splittable logs
LogFormat "%{Host}i %h %l %u %t \"%r\" %s %b" vcommon
CustomLog ${APACHE_LOG_DIR}/access_log vcommon

<Directory /home/httpd/domains/portnumber53.local/html>
# ExecCGI is needed here because we can't force
# CGI execution in the way that ScriptAlias does
Options FollowSymLinks ExecCGI
</Directory>

# now for the hard bit

RewriteEngine On

# a ServerName derived from a Host: header may be any case at all
RewriteMap lowercase int:tolower

## deal with normal documents first:
# allow Alias /icons/ to work – repeat for other aliases
RewriteCond %{REQUEST_URI} !^/icons/
# allow CGIs to work
RewriteCond %{REQUEST_URI} !^/cgi-bin/
# do the magic
RewriteRule ^/(.*)$ /home/httpd/domains/${lowercase:%{SERVER_NAME}}/html/$1

## and now deal with CGIs – we have to force a MIME type
RewriteCond %{REQUEST_URI} ^/cgi-bin/
RewriteRule ^/(.*)$ /home/httpd/domains/${lowercase:%{SERVER_NAME}}/cgi-bin/$1 [T=application/x-httpd-cgi]

# that's it!
a2ensite vhosts
a2dissite default
///////////////
mkdir -p /home/httpd/domains/portnumber53.local/html
echo "PortNumber53.local<?php phpinfo(); ?>" > /home/httpd/domains/portnumber53.local/html/index.php

mkdir -p /home/httpd/domains/example.local/html
echo "Example.local<?php phpinfo(); ?>" > /home/httpd/domains/example.local/html/index.php

Let's restart Apache:
service apache2 restart

As long as your windows box solves portnumber53.local and example.local to the IP of your debian web box, try opening these domains in your browser.

 

Setting up a Debian box for development: linux installation

This will be a work in progress series of posts to help people get into the amazing world of developing applications on the web.

Will also give me opportunity to fine tune my knowledge.

 

This will be the L in LAMP, here we go:

 

1. Download a Debian ISO file (6.0.4 has just been release as of this writing)

2. Download LinuxLive USB Creator from http://www.linuxliveusb.com/

3. Run LiLi and create a bootable USB stick with the ISO file you downloaded from Debian website

Choose to format the key in FAT32

 

After following a default installation procedure…. so we're all starting from the same page.

install a few packages:

 

# apt-get update

# apt-get upgrade –show-upgraded

# apt-get install aptitude

# aptitude install sudo rsync

 

 

  • IGlr