Debian LEMP system setup

Icon


Contents:

1   Overview
2   Procedure
3   Optional: PHP phar setup
4   Additional steps
  Related pages






1. Overview.

This document is intended for Linux developers. If you notice mistakes, write to: oldcoder@yahoo.com

LEMP is a collection (or stack) of Web-related software. The name is an acronym that stands for Linux, Engine X (nginx), MySQL, and PHP5. LEMP is a variation of LAMP that is simpler and possibly faster.

This document describes a procedure that I used to set up Debian systems in 2012 and 2013 as LEMP development systems.

The procedure may or may not work for newer releases of Debian, Mint, and/or Ubuntu. However, it's discussed here in the hope that it may be useful.





2. Procedure.

2.1. I started with a box that was running an old Ubuntu. I used ssh to access the box and had superuser access. I upgraded the old copy of Ubuntu to Ubuntu 12.04 LTS Precise Pangolin. Details for the upgrade are beyond the scope of this document.

Subsequently I tried similar procedures using other variations of Debian. Most recently, Debian Wheezy has been tested.

2.2. The first actual step was to log-in as root on the system or to become superuser there.

2.3. Then I did the following setup:


export TERM=linux
apt-get -y update
apt-get -y upgrade
apt-get -y install build-essential
gcc --version

apt-get -y install \
autoconf aptitude automake bzr cmake curl git-core \
htop imagemagick joe lynx nano netpbm nmap perl-doc \
pkg-config rlwrap sqlite3 subversion sudo unrar-free \
wget zip \
libbz2-dev libevent-dev libpng-dev \
libncurses5-dev libreadline-dev libsqlite3-dev \
libssl-dev uuid-dev

2.5. I removed any existing MySQL setup and installed a fresh one. Note: I was prompted to specify a new root password for MySQL when the fresh copy was installed. The word ROOTPASS here stands for the password that I specified.


service mysql stop
sleep 5
rm -fr /etc/mysql
apt-get  -y remove --purge mysql-client
apt-get  -y remove --purge mysql-common
apt-get  -y remove --purge mysql-server-core
apt-get  -y autoremove
apt-get  -y autoclean
aptitude -y remove mysql-client
aptitude -y remove mysql-server
aptitude -y remove mysql-common
rm -fr /etc/mysql

aptitude -y install mysql-server mysql-client
service mysql status
mysqladmin -u root -p'ROOTPASS' status
apt-get  -y install libmysqlclient-dev

2.6. I removed any existing Apache and/or PHP5 setup. After that I installed PHP5 and started to install nginx:


apt-get -y remove --purge apache2-utils apache2.2-bin
apt-get -y remove --purge php5-common php5-mysql

apt-get -y install php-apc php-pear \
php5-cgi php5-cli php5-mysql php5-sqlite \
spawn-fcgi libfcgi-perl

apt-get -y install nginx
mkdir -p /var/nginx
chown -R www-data:www-data /var/nginx

For older Debians and variants I added php5-suhosin to the last apt-get command.

2.7. Continuing with nginx setup, I edited the file /etc/rc.local (which already existed) and replaced its contents with:


#!/bin/sh
/usr/bin/spawn-fcgi \
-a 127.0.0.1 -p 9000 \
-u www-data -g www-data \
-f /usr/bin/php5-cgi \
-P /var/run/fastcgi-php.pid
exit 0

2.8. I installed my version of the following nginx configuration file, replacing any existing copy:


/etc/nginx/sites-available/default

For a copy of my version of the file in question, click here.

2.9. I made sure that /etc/rc.local was executable:


chmod 755 /etc/rc.local

2.10. I did some additional nginx-perl setup:


wget http://nginxlibrary.com/downloads/perl-fcgi/fastcgi-wrapper \
    -O /usr/bin/fastcgi-wrapper.pl
wget http://nginxlibrary.com/downloads/perl-fcgi/perl-fcgi \
    -O /etc/init.d/perl-fcgi
chmod +x /etc/init.d/perl-fcgi
chmod +x /usr/bin/fastcgi-wrapper.pl
update-rc.d perl-fcgi defaults
PATH=/sbin:/usr/lib/insserv:$PATH
insserv perl-fcgi

2.11. I installed phpmyadmin and some additional development packages.


apt-get -y install \
lua5.1 lua5.1-dev libglib2.0-dev phpmyadmin

The phpmyadmin installer asked me to specify a web server to reconfigure automatically. I responded: none. It also asked me if I wanted to configure a database for phpmyadmin with dbconfig-common. I responded: no.

2.12. I rebooted the system and executed the following command. The latter step usually would not be needed but was done to be on the same side:


service nginx restart

2.13. I created some directories to hold non-standard binaries and data files:


mkdir -p  /opt/{bin,etc,include,lib,man,sbin,share}
mkdir -p  /opt/var/{cache,log,run}
chmod 777 /opt/var/{cache,log,run}

2.14. I added the following line at the top of /etc/ld.so.conf and executed ldconfig:


/opt/lib

2.14. I set the timezone, date, and time using commands similar to the following:


dpkg-reconfigure tzdata
date 06221723

2.15. I set up Perl CPAN support roughly as follows. Full documentation for this step is beyond the scope of this document.


# The first command below printed a  few questions.
# I responded as necessary; in most cases, I simply
# pressed Enter to accept the default setting.

# For some people, the command in question may fail
# the first  time. If this happens, repeat the com-
# mand and it may work.

rlwrap cpan JSON::XS
cpan YAML
cpan Term::ReadLine::Gnu
cpan Module::Install
cpan Bundle::LWP
cpan Bundle::DBI
cpan DBD::SQLite
cpan Inline
cpan Text::Document

At this point, I had a working Debian LEMP server and/or development system.





3. Optional: PHP phar setup.

3.1. There's a PHP PEAR utility named pyrus.phar which may be useful in some cases. Most developers won't need the tool but I installed it on some of my LEMP servers. To do so, I proceeded as follows.

3.2. First, I made sure that PHP SQLite3 support was enabled:


apt-get -y install php5-sqlite

3.3. I edited the following files:


/etc/php5/cgi/php.ini
/etc/php5/cli/php.ini

and added the following command to the Miscellaneous section in each case:


suhosin.executor.include.whitelist="phar"

3.4. I downloaded pyrus.phar from the link below and ZIPped the file:

http://pear2.php.net/pyrus.phar

To obtain a copy of the ZIP file, use this link:

pyrusphar.zip

At this point, pyrus.phar setup was believed to be completed.





4. Additional steps.

4.1. Optional: Install a fast bzip2.

4.1.1. Execute the commands:

apt-get install pbzip2
hash bzip2
cd /bin
mv -i bzip2 bzip2.original
ln -s `which pbzip2` bzip2

4.2. Optional: vsftpd setup.

4.2.1. Execute the command:

apt-get -y install vsftpd

4.2.2. Install the text file at this link as /etc/vsftpd.conf and follow the instructions in the file for any local users who need FTP access.

4.2.3. Execute the commands:

chmod 644 /etc/vsftpd.conf
service vsftpd restart





For acknowledgments related to CSS and other code used, click here.

Linked or embedded works (software, books, articles, etc.) are presented under their own licenses.

Other unique content on this page, excluding screenshots, is distributed under the following license: C.C. Attribution NonCommercial ShareAlike 3.0. In some cases, screenshots are distributed under the same license. In other cases, the associated program's license applies.

image Valid XHTML 1.0