Dugan Chen's Homepage

Various Things

LEMP on Slackware

I’ve gotten to really like the nginx web server. Here’s how to set it up on Slackware.


The nginx SlackBuild on SlackBuilds.org is ahem not quite the way I’d like it. As Apache’s document root is /var/www/htdocs, nginx’s should be /var/www/ngdocs. Therefore, I’ve created a patch to fix it.

From the SlackBuild directory:

$ patch -p1 < ../nginx_ngdocs.diff 
patching file ngdocs.patch
patching file nginx.SlackBuild

Use the patched SlackBuild to build and install nginx.

Then make nginx’s startup script executable, and start it.

chmod +x /etc/rc.d/rc.nginx
/etc/rc.d/rc.nginx start

Browse to http://localhost/, and you should see nginx’s start page.

Add the following to /etc/rc.d/rc.local, so that nginx is started on boot:

if [ -x /etc/rc.d/rc.nginx ]; then
    /etc/rc.d/rc.nginx start


The commands for getting MySQL working are boilerplate:

cd /usr/share/mysql
cp my-huge.cnf my.cnf
chmod +x /etc/rc.d/rc.mysqld
chown -R mysql:mysql /var/lib/mysql
/etc/rc.d/rc.mysqld start


For PHP support in nginx, you need php-fpm running:

chmod +x /etc/rc.d/rc.php-fpm
/etc/rc.d/rc.php-fpm start

Add the following to /etc/rc.d/rc.local, so that rc.php-fpm is started on boot:

if [ -x /etc/rc.d/rc.php-fpm ]; then
    /etc/rc.d/rc.php-fpm start

Uncomment the following section of /etc/nginx/nginx.conf:

location ~ \.php$ {
    root           /var/www/ngdocs;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;

In the same file, set nginx to recognize index.php files:

location / {
    root   /var/www/ngdocs;
    index  index.php index.html index.htm;

Create /var/www/ngdocs/phpinfo.php, with the following contents:

<?php phpinfo(); ?>

Restart nginx:

/etc/rc.d/rc.nginx restart

Browse to http://localhost/phpinfo.php, and you should see that PHP is working.


This is where it comes together. Install PHPMyAdmin from SlackBuilds.org.

Build it with the appropriate flags:

DOCROOT=/var/www/ngdocs PHPGROUP=root ./phpmyadmin.SlackBuild

Install it, then set the permissions so that nginx can see it:

chmod 0755 /var/www/ngdocs/phpmyadmin

Browse to http://localhost/phpmyadmin/, and you can now log in and browse your MySQL databases.

I’d call that a start. I typically then turn indexing on, install h5ai, and then use nginx to stream MP4 files to my iPad.


A PHP server setup isn’t complete until the server can send email. PHP’s standard library’s mail command needs to be configured for that. Typically, you want PHP to relay mail through an external SMTP server. The easiest way to do that is with msmtp.

Install, in order, libgsasl and msmtp, both from SlackBuilds.org. Use sbopkg to build a queue, and you’ll be done in no time.

Edit /etc/httpd/php.ini and set your sendmail_path to the msmtp binary:

/usr/bin/msmtp -t

Then edit /etc/msmtprc and add the authentication credentials for your smtp server. Templates for servers such as GMail and SendGrid should be very easy to find. Here’s one for GMail, adapted from the Arch Linux wiki:

# Accounts will inherit settings from this section
auth             on
tls              on

# A first gmail address
account        gmail
host           smtp.gmail.com
port           587
from           username@gmail.com
user           username@gmail.com
password       my_password
tls_trust_file /etc/ssl/certs/ca-certificates.crt

account default: gmail

Then send out a test email from PHP:

php -r 'mail("username@gmail.com", "testing from PHP", "Did this arrive?");'

If you want to set up Postfix (Howto) or, God forbid, Sendmail (Howto) to do this instead, you can. Those are valid options. But if the use case is just to get one application (PHP) to relay mail to an external SMTP server, then msmtp the more focused solution.