Build SSL certificate

im trying to build a script to give me the SSL Certificate and Key so I can add them into Apache for a vHost as Im trying to build my own hosting site.

Ive got most of my app working, but Im stuck with creating the SSL. I found the article which suggests the following code:-
// Fill in data for the distinguished name to be used in the cert
// You must change the values of these keys to match your name and
// company, or more precisely, the name and company of the person/site
// that you are generating the certificate for.
// For SSL certificates, the commonName is usually the domain name of
// that will be using the certificate, but for S/MIME certificates,
// the commonName will be the name of the individual who will use the
// certificate.
$dn = array(
    "countryName" => "UK",
    "stateOrProvinceName" => "Somerset",
    "localityName" => "Glastonbury",
    "organizationName" => "The Brain Room Limited",
    "organizationalUnitName" => "PHP Documentation Team",
    "commonName" => "Wez Furlong",
    "emailAddress" => ""

// Generate a new private (and public) key pair
$privkey = openssl_pkey_new();

// Generate a certificate signing request
$csr = openssl_csr_new($dn, $privkey);

// You will usually want to create a self-signed certificate at this
// point until your CA fulfills your request.
// This creates a self-signed cert that is valid for 365 days
$sscert = openssl_csr_sign($csr, null, $privkey, 365);

// Now you will want to preserve your private key, CSR and self-signed
// cert so that they can be installed into your web server, mail server
// or mail client (depending on the intended use of the certificate).
// This example shows how to get those things into variables, but you
// can also store them directly into files.
// Typically, you will send the CSR on to your CA who will then issue
// you with the "real" certificate.
openssl_csr_export($csr, $csrout) and var_dump($csrout);
openssl_x509_export($sscert, $certout) and var_dump($certout);
openssl_pkey_export($privkey, $pkeyout, "mypassword") and var_dump($pkeyout);

// Show any errors that occurred here
while (($e = openssl_error_string()) !== false) {
    echo $e . "\n";

Open in new window

However Im getting:-

( ! ) Warning: openssl_csr_sign(): cannot get CSR from parameter 1 in index.php on line 29
( ! ) Warning: openssl_csr_export() expects parameter 1 to be resource, boolean given in index.php on line 38
( ! ) Warning: openssl_x509_export(): cannot get cert from parameter 1 in index.php on line 39
( ! ) Warning: openssl_pkey_export(): cannot get key from parameter 1 in index.php on line 40

Im not really sure what Im doing here, I know I need to replace the demo array with real data, but this shouldnt be stopping the generation of the certificates surely?

Ive enabled the openSSL module in my php.ini so it should be working surely :-S

Any ideas?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

F PCommented:
var_dump out your $csr variable please and let me see the output after you've created it like this:

echo var_dump($csr); exit;

Open in new window

I'm wondering what the return value is.
F PCommented:
Basically, that seems like you're getting something to fail before it gets there, as in a parameter you're passing during the creation is returning FALSE, instead of the resource you expect, and it's either the $privkey or the $csr ... and without knowing how you installed the system, or verifying your installation with permissions on the openssl.conf file, that's the first step.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.