wp-safari-push icon indicating copy to clipboard operation
wp-safari-push copied to clipboard

How to properly set up the plugin

Open monecchi opened this issue 10 years ago • 3 comments

Hello. This is not and issue, but rather a request for detailed instructions on how to properly set up the plugin.

Although I've read all the plugin's documentation as also further instructions on https://github.com/surrealroad/Safari-Push-Notifications, I still can't get the plugin to work as intended. I run a seld-managed vps and I use a SSL (HTTPS) server, signed by a recognised authority (Comodo).

I'd really appreciate any help from the experts. P.S: As I'm not a developer I apologize for any noob terms I might be using here...Thanks in advance for your attention.

What I've done until now:

  • [x] I installed and activated safari push plugin and filled up the main settings, here's a screenshot: https://cloudup.com/cfOcB5FzvmT - I've left some fields blank as I don't know what to put in there.

I've successfully created the certificates on Apple's Provisioning Portal following the steps:

  • I created a Certificate Signing Request on Mac;
  • I Created a Website Push ID with the reverse domain: web.com.br.mydomain.myappname
  • After choosing the Website Push ID I've created earlier, I uploaded the CSR file I've created on Mac on Apple's Provisioning Portal to generate Apple's website_aps_production.cer certificate file.

Back to the Mac:

  • I downloaded the website_aps_production.cer certificate file, then I added the file to the Mac's Keychain.app and I exported the certificate right from the Keychain.app as a .p12 certificate file and named it mysite_webpush.p12

On the server side:

  • I uploaded the certificates files (website_aps_production.cer and mysite_webpush.p12) to my server's root directory and then on Terminal I executed the following command to convert the website_aps_production.cer file to a .pem format: openssl x509 -in website_aps_production.cer -inform DER -out apns-cert.pem -outform PEM - which resulted on a new file named apns-cert.pem
  • I created a new database using the push.sql file
  • I successfully renamed the config-sample.php to config.php and set it up as per the database information
  • I replaced the images in pushPackage.raw/icon.iconset/

Directory structure and file organization

Finally I created the folders /v1/push/ under my WordPress website root directory on my server and moved all the following files to the /push/ directory. 1 - config.php 2 - createPushPackage.php 3 - index.php 3 - desktop.php 4 - mysqli.inc.php 5 - And the /pushPackage.raw/ folder

My server's directory structure for my WordPress installation is a bit different as follows: I have the WordPress installed under a directory named /site/ which lies on my website's root directory that is /www/, meaning my WP website runs on /www/site/ - This is an ordinary nginx server and I have no issues regarding the ssl certificate from Comodo or the WP website itself.

I confess I'm totally lost here, so after moving the aforementioned files to the server I placed the certificates mysite_webpush.p12 and apns-cert.pem right within the /v1/ directory while the rest of the files I uploaded to the /push/ directory.

Here's a example of the organization I've done.

/www/site/v1/ ---> Here I placed the certificates mysite_webpush.p12 and apns-cert.pem /www/site/v1/push/ ---> Here I placed all the files config.php, createPushPackage.php, index.php, desktop.php, mysqli.inc.php and the /pushPackage.raw/ folder.

The config.php set up

I've set up the config.php as follows:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for storing device ids */
define('DB_NAME', 'mydb_name');

/** MySQL database username */
define('DB_USER', 'mydb_user');

/** MySQL database password */
define('DB_PASSWORD', 'mydb_password');

/** MySQL hostname */
define('DB_HOST', 'localhost');

// ** Push server site settings ** //
/* Web Service Base URL */
define('WEBSERVICE_URL', 'https://pizzariameurancho.com.br/site/');

/* Website Push ID unique identifier */
define('WEBSITE_UID', 'web.com.br.pizzariameurancho_myapp');

/* Website Name */
define('WEBSITE_NAME', 'Pizzaria Meu Rancho');

/* Allowed Domains, must be comma-seperated and quoted */
define('ALLOWED_DOMAINS', '"https://pizzariameurancho.com.br",     "https://www.pizzariameurancho.com.br"');

/* URL string format for links */
define('URL_FORMAT', 'https://pizzariameurancho.com.br/site/');


// ** Certificate settings - certificates provided by Apple ** //
define('CERTIFICATE_PATH', './mysite_webpush.p12');     // Change this to the path where your     certificate is located
define('CERTIFICATE_PASSWORD', ''); // Change this to the certificate's import password
define('PRODUCTION_CERTIFICATE_PATH', './apns-cert.pem'); // Change this to the path to your Website Push ID Production Certificate


// ** Authorisation code for requesting push notifications to be sent ** //
define('AUTHORISATION_CODE', '');

// ** APNS Settings, probably don't need to be changed ** //
define('APNS_HOST', 'gateway.push.apple.com');
define('APNS_PORT', 2195);

Could anyone please point out what I'm missing. This has been a total puzzle to me. Thanks a lot for your attention.

Regards,

Adriano.

monecchi avatar Aug 27 '14 00:08 monecchi

Ok a few things you need to look at:

  • Your push service must be in the root (ie. /www/ not /www/site/)
  • You should not create a /v1/ subfolder, this will be handled via the .htaccess file (this and the last point are two reasons why you might want to set up a separate push site from your main one)
  • You are using nginx instead of apache, which the instructions were written for, you may have to reconfigure the .htaccess file accordingly (sorry I can't help more but I have no experience using nginx)
  • You need to set a value in the config file for AUTHORISATION_CODE, this can be any password you like
  • Put the same authorization code in the plugin settings (web service authorization code)
  • Web service push URL should be "urlargs" in most cases (I'll check to see why it isn't filled in by default)

surrealroad avatar Aug 27 '14 08:08 surrealroad

Hello. Thanks for your tips and explanation. I'll set up a subdomain on my server and create a new nginx server block (such as an apache virtual host) for this purpose only.

Regarding the .htaccess configuration part, where is it handled? Do you mean the true .htaccess file which lies on the root directory of most apache servers or the htaccess configuration is manipulated on one of the php files? I'm afraid things are handle differently on nginx, but I'll ask for help on stackoverflow's serverfault/wp dev sites and make a research by myself too.

That's a good hint about the authorization code, I had a huge doubt about it the first time I adjusted the plugin settings.

So do you mean I should put 'urlargs' inside of this line such as follows? define('WEBSERVICE_URL', 'urlargs');

For now I say thanks a lot for your help. I'll update here if I succeed.

Regards,

Adriano.

monecchi avatar Aug 27 '14 15:08 monecchi

The .htaccess file is included in the reference push service: https://github.com/surrealroad/Safari-Push-Notifications/blob/master/.htaccess it just lives in the root folder (you shouldn't need to edit it if you're using Apache)

Put urlargs in the WordPress plugin settings page, in the field "Web Service Push URL Arguments Tag" (you wrote on the image that this field was left empty).

You should probably have define('WEBSERVICE_URL', 'https://pizzariameurancho.com.br/site/'); in the config file

surrealroad avatar Aug 28 '14 12:08 surrealroad