From SME Server
Jump to navigationJump to search

Important.png Note:
For v10 we have created a new update version of PHPKi called PHPKi-ng with fixes and higher security defaults. If you used the previous version you will need to create a new CA and certificates. We have imported the original version to contribs if you really need to use it, but it is not recommended, and will not be generally released


Previous: [1]Daniel B. from Firewall Services

Now maintained by Koozali SME


Old version prior SME10:smeserver-phpki and phpki

New Version:

Contrib 10:
The latest version of smeserver-phpki-ng is available in the SME repository, click on the version number(s) for more information.

Contrib 10:
The latest version of phpki-ng is available in the SME repository, click on the version number(s) for more information.

Please follow the installation instructions below. The installation instructions will satisfy all dependencies and the latest versions of the above 2 RPMs will be installed automatically.


PHPki is an Open Source Web application for managing a multi-agency PKI for HIPAA compliance. With it, you may create and centrally manage X.509 certificates for use with S/MIME enabled e-mail clients, SSL servers, and VPN applications. PHPki is now used to manage certificates with the latest release of the SME Server OpenVPN Bridge contrib.

You can see a demo installation here


  • SME Server 10.x
Verified on:
SME Server 10.0 - RequestedDeletion

Warning.png Warning:
This version of PHPki is a slightly modified version, so it can be used with certificates generated with previous release of smeserver-openvpn-bridge, plus some others minor modifications.


Warning.png Warning:
If openvpn is not detected PHPKi cannot generate a TA Key and it should advise you during install. To generate a TA Key once you have openvpn installed do this (assuming this is the correct directory)
openvpn --genkey --secret /opt/phpki/phpki-store/CA/private/takey.pem 
chown phpki:phpki /opt/phpki/phpki-store/CA/private/takey.pem

  • install the rpms
yum --enablerepo=smecontribs install smeserver-phpki-ng

go to the server-manager to the manage certificate menu and start creating your CA certificate

Warning click only once and wait for the page to update it can be very long to create the 4096 certificate...

you have to enable the epel repository

  • install the rpms
yum --enablerepo=smecontribs,epel install smeserver-phpki
  • and start/restart needed services:
expand-template /etc/httpd/conf/httpd.conf
expand-template /etc/httpd/pki-conf/httpd.conf
sv t /service/httpd-e-smith
sv u /service/httpd-pki
  • alternatively issue the following :
signal-event post-upgrade; signal-event reboot

on update you can issue

expand-template /etc/httpd/conf/httpd.conf
expand-template /etc/httpd/pki-conf/httpd.conf
sv t /service/httpd-e-smith
sv t /service/httpd-pki

For sme8

  • install the rpms
yum --enablerepo=smecontribs install smeserver-phpki
  • and start/restart needed services:
expand-template /etc/httpd/conf/httpd.conf
expand-template /etc/httpd/pki-conf/httpd.conf
sv t /service/httpd-e-smith
sv u /service/httpd-pki
  • alternatively issue the following :
signal-event post-upgrade; signal-event reboot

Configure your new PKI

Go in the server-manager, you'll find a new "Manage Certificates" menu (or you can use the URL https://server.domain.tld/phpki/ca) Here you have to enter the following informations:

    • Organisation
    • Department
    • Common Name of the Master CA
    • E-mail (technical contact)
    • City
    • State
    • Country Code
    • Password (to protect the private key of the Master CA)
    • Validity of the CA
    • Keys size
    • URL of your PKI (https://my.domain.tld/phpki)

These two screenshots illustrate the first (and the most important) part of this configuration page:

First part of the initiale configuration page (above)
First part of the initiale configuration page (low)

The second part is like this:

Second part of the initiale configuration page

The default settings should be OK for most installations. You may just want to change the "Help Document Contact Info" part.

Once you have submitted this form (which can take several minutes, be patient, as generating dh parameters can take a long time), you should have something like this:

Second part of the initiale configuration page

Now you'll be able to start using PHPki. It's quite easy to use.

The administrative interface is available on the server-manager or directly https://my.domain.tld/phpki/ca

There's also a public interface, available only from the local networks, but without password at https://my.domain.tld/phpki. Here, users can download the Master CA certificate, the CRL, or search for certificates of other users (public part only of course).

Important.png Note:
If you just installed the OpenVPN_Bridge contrib and are installing PHPki as suggested by the wiki page, or you just want to use PHPki without OpenVPN_Bridge contrib, then you are done here, and you don't have to migrate any certificates

Migrate Certificates from previous OpenVPN-Bridge contrib installations

If you are installing this phpki contrib because you have used OpenVPN_Bridge before and have already certificates, follow the instructions below. If you have a fresh and new install of OpenVPN_Bridge, skip the below instructions for you do not have 'old' certificates!

PHPki is now the certificate manager recommended to manage OpenVPN_Bridge certificates. This part will explain how-to import your certificates created with openvpn-bridge into PHPki

  • First, you need to install the contribs as it's explain on this page (you can enter anything for the configuration of the CA, all your old parameters will be restored)
  • Second, you need to copy this script on your server (for example as /root/ and execute it as root.

Warning.png Warning:
Of course, take some time to read this script before runing it as root.


# Read Openvpn-Bridge DB
ORGNAME=$(/sbin/e-smith/db openvpn-bridge getprop default_config organizationName)
COUNTRY=$(/sbin/e-smith/db openvpn-bridge getprop default_config countryCode)
STATE=$(/sbin/e-smith/db openvpn-bridge getprop default_config countryName)
LOC=$(/sbin/e-smith/db openvpn-bridge getprop default_config localityName)
DEP=$(/sbin/e-smith/db openvpn-bridge getprop default_config sectionName)
KEYSIZE=$(/sbin/e-smith/db openvpn-bridge getprop default_config keySize)
EMAIL=$(/sbin/e-smith/db openvpn-bridge getprop default_config mailAddress)


# Store the actual time in $TIME
TIME=$(date +%d%m%Y%H%M%S)

# Create needed directories
        mkdir -p $NEWDIR/{certs,newcerts,requests,pfx,private}

# Migrate the certificates to phpki store
        cd $OLDDIR

        # Copy the old index.txt and serial
        cat $OLDDIR/index.txt > $NEWDIR/index.txt
        cat serial > $NEWDIR/serial

        # Copy the cacert related files
        cat ca.crt > $NEWDIR/certs/cacert.pem
        cat ca.key > $NEWDIR/private/cakey.pem

        # Now, for each file ending with .crt
        for CERT in $(ls ./*.crt); do
                CERT=$(basename $CERT .crt)

                ISININDEX=$(grep -c "/CN=$CERT/" $NEWDIR/index.txt)

                # If the current cert isn't referenced in the index,
                # or the corresponding key or csr file dosn't exists, then skip it
                # This can happen in some situation where the serial has been corrupted

                if [ $ISININDEX -gt 0 ]&&[ -s $CERT.key ]&&[ -s $CERT.csr ]; then
                        # Retrieve the serial number as reported by  openssl
                        SERIAL=$(openssl x509 -noout -serial -in $CERT.crt | cut -d"=" -f 2)

                        # Create the pem only cert in the new dir
                        $OPENSSL x509 -in $CERT.crt -inform PEM -outform PEM -out $NEWDIR/newcerts/$SERIAL.pem

                        # Create the der formated cert
                        $OPENSSL x509 -in $CERT.crt -inform PEM -outform DER -out $NEWDIR/certs/$SERIAL.der

                        # And the pkcs12 bundle (cert+key+ca)
                        $OPENSSL pkcs12 -export -in $CERT.crt -inkey $CERT.key -certfile ca.crt -caname $ORGNAME -passout pass: -out $NEWDIR/pfx/$SERIAL.pfx

                        # Copy the private key
                        cat $CERT.key > $NEWDIR/private/$SERIAL-key.pem 

                        # And the cert request
                        cat $CERT.csr > $NEWDIR/requests/$SERIAL-req.pem

        # Restrict access
        chown -R phpki:phpki $NEWDIR
        chmod -R o-rwx $NEWDIR

        # Retrieve the common name of our CA with openssl command
        CACN=$($OPENSSL x509 -subject -noout -in $OLDDIR/ca.crt | cut -d'=' -f 8 | cut -d'/' -f 1)

        if [ -e /opt/phpki/phpki-store/config/config.php ]; then
                # Move the actual phpki configuration file               
                mv /opt/phpki/phpki-store/config/config.php /opt/phpki/phpki-store/config/config.php.$TIME

                # And use sed to configure it properly
                sed -e "s/config\['organization'\].*/config\['organization'\] = '$ORGNAME';/" \
                        -e "s/config\['unit'\].*/config\['unit'\] = '$DEP';/" \
                        -e "s/config\['contact'\].*/config\['contact'\] = '$EMAIL';/" \
                        -e "s/config\['locality'\].*/config\['locality'\] = '$LOC';/" \
                        -e "s/config\['province'\].*/config\['province'\] = '$STATE';/" \
                        -e "s/config\['country'\].*/config\['country'\] = '$COUNTRY';/" \
                        -e "s/config\['common_name'\].*/config\['common_name'\] = '$CACN';/" \
                        -e "s/config\['ca_pwd'\].*/config\['ca_pwd'\] = '';/" \
                        -e "s/config\['keysize'\].*/config\['keysize'\] = '$KEYSIZE';/" \
                        /opt/phpki/phpki-store/config/config.php.$TIME \
                        > /opt/phpki/phpki-store/config/config.php

        # Here, we just migrate dhparam and ta to phpki store
        if [ -e $OLDDIR/dh.pem ]; then
                cat $OLDDIR/dh.pem > $NEWDIR/private/dhparam1024.pem
        if [ -e $OLDDIR/ta.key ]; then
                cat $OLDDIR/ta.key > $NEWDIR/private/takey.pem


Now, go in the server-manager, in "Manage Certificates" and check your old certificates are here.


To uninstall the contrib from your server, just run the following commands:

yum remove smeserver-phpki-ng phpki-ng
expand-template /etc/httpd/conf/httpd.conf
sv t /service/httpd-e-smith

Important.png Note:
As with many other rpms, removing phpki won't remove everything from your server. Especially certificates will be kept, and some php files. PHPKi-ng will attempt to backup any old certificates.

Certificates and PKI configuration are stored in /opt/phpki/phpki-store, php files are in /opt/phpki/html

Warning.png Warning:
These files can be very important, so my recommendation is to let them remain here. If you really want to remove them, just backup them before:
cd /opt/phpki
tar cvzf ~/phpki-backup.tar.gz ./

Now you can remove the entire /opt/phpki directory


If you have removed the contrib, and want to re-install it, you'll need to follow these steps after you have installed the rpms:

cd /opt/phpki/html/
rm -f index.php 
rm -f setup.php
ln -s main.php index.php
cat config.php.rpmsave > config.php
cd ca
rm -f index.php
ln -s main.php index.php
cd /opt/phpki/
chown phpki:phpki -R phpki-store 
chown root:phpki -R html/config.php


Please raise bugs under the SME-Contribs section in bugzilla

For the old smeserver-phpki select the smeserver-phpki component or use this link

"No open bugs found."

For the new smeserver-phpki-ng select the smeserver-phpki-ng component or use this link

IDProductVersionStatusSummary (4 tasks)
12198SME Contribs10.0CONFIRMEDremove folder /var/log/httpd-pki/
11873SME Contribs10.0CONFIRMEDremove phpki from logfiles2timestamp
11439SME Contribs10betaCONFIRMEDsmeserver-phpki-ng allow remote access for crl
10903SME ContribsFuturCONFIRMEDSave certificate bundle for ovpn configs

Use this for bugs phpki-ng itself this link

IDProductVersionStatusSummary (2 tasks)
11440SME Contribs10betaCONFIRMEDphpki-ng autopopulate base URL
11438SME Contribs10betaCONFIRMEDphpki-ng setup does not detect openvpn - missing takey static key