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



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






Restart mysql

systemctl restart mysqld




Install PHP


pacman -S php php-apache libmcrypt libtool


nano /etc/php/php.ini






nano /etc/locale.gen


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
    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


Raspberry Pi: mount flash disks at boot

Now that I got a little time to work on my Raspberry Pi, I decided to have 2 2GB flash drives mounted at boot to save some write cycles on the SD card:

After a few failed times, I googled for a while and the important bit is the 6th field in your /etc/fstab file. Here's mine:


[root@pi ~]# cat /etc/fstab
# /etc/fstab: static file system information
# <file system>        <dir>         <type>    <options>          <dump> <pass>
devpts                 /dev/pts      devpts    defaults            0      0
shm                    /dev/shm      tmpfs     nodev,nosuid        0      0
/dev/mmcblk0p1  /boot           vfat    defaults        0       0

/dev/sda1       /var       ext4    defaults          0       2
/dev/sda2       /data      ext4    defaults          0       2
/dev/sda3       /tmp       ext4    defaults          0       2
/dev/sdb1       /home      ext4    defaults          0       2


The "2" in the 6th field tells the kernel to wait for the drive to be available before trying to mount it.

Here's the "mount" command output:

/dev/mmcblk0p1 on /boot type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=cp437,iocharset=ascii,shortname=mixed,errors=remount-ro)
/dev/sdb1 on /home type ext4 (rw,relatime,user_xattr,barrier=1,data=ordered)
/dev/sda2 on /data type ext4 (rw,relatime,user_xattr,barrier=1,data=ordered)
/dev/sda3 on /tmp type ext4 (rw,relatime,user_xattr,barrier=1,data=ordered)
/dev/sda1 on /var type ext4 (rw,relatime,user_xattr,barrier=1,data=ordered)




  • IGlr