Data Convertion.
- To String: String.valueOf(data);
- To Integer: Integer.valueOf(data);
Stringified(Serialized) JSON to Apex Data.
private static void doSomething(String JSONString) {
Map<String, Object> myJSON = (Map<String, Object>) JSON.deserializeUntyped(JSONString);
Integer something = myJSON.get('key');
}
Execute Apex Class from Browser Client.
Apex Class:
Global with sharing class SomeClass {
// Dummy constructer
public SomeClass() {}
// Important, without RemoteAction, it wont work
@RemoteAction
public static String someFunction() {
return 'success';
}
}
Browser Client Side(JavaScript):
<apex:page controller="SomeClass">
<script>
SomeClass.someFunction(function(result, event) {
console.log(result); // outputs 'success';
});
</script>
</apex:page>
To be continue...?
Wednesday, 2 December 2015
Monday, 16 November 2015
PHP-FPM on Apache HTTPD (CentOS 7)
This basically guides you on implementing PHP-FPM on Apache HTTPD.
The following installation steps are all done on CentOS 7.
Previous version of CentOS might not work as previous Apache HTTPD's fast cgi mod are a bit, "challenging".
Specification:
CentOS 7+
Apache HTTPD 2.4+
PHP 5.6+ (Remi Repository)
(After fresh installation of CentOS)
Step 1, Update system, install Remi repository, install PHP and HTTPD
# yum update
# cd /tmp
# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
# rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
# yum install httpd httpd-devel
# yum install --enablerepo=remi, remi-php56 php php-devel php-fpm <any-extra-php-modules-you-need-example-php-mbstring>
Step 2, setup new directory
# cd /var/www/html
# mkdir php-fpm
# printf '<?php\n phpinfo();' > php-fpm/index.php
Step 3, Add a new HTTPD configuration points to the new directory
(A configuration that assign all calls to the directory passes it to php-fpm, on a virtual host)
# vi /etc/httpd/conf.d/php-fpm.conf
# Config Content
<VirtualHost *:80>
ServerName your-servername.com
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/php-fpm/$1
DocumentRoot /var/www/html/php-fpm
<Directory /var/www/html/php-fpm>
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/fpm_error.log
CustomLog /var/log/httpd/fpm_access.log combined
</VirtualHost>
Before proceeding, make sure you added rules to firewalld to allow access.
Step 4, Bring up PHP-FPM and HTTPD
(The steps below disables firewalld and selinux, remember it is important not to disable them on the production server)
# service firewalld stop
# setenforce 0
# service php-fpm start
# service httpd start
Now, access to your server, you will see the php-info, with php-fpm being active in the cgi-fcgi section.
If you want to begin your development on the directory, go on =)
But you might want to concern on the systemd-private-temp configuration if your site allow file uploads.
(CentOS 7 new feature, the "PrivateTemp" option that store in /usr/lib/systemd/system/php-fpm.service)
// Thoughts
It is so much easy on setting up PHP-FPM on CentOS 7 compare to previous CentOS. You need to install mod_fcgi, load it, pass it, very troublesome on virtual host, etc...
Totally a mess.
But it is easy on NGINX. Just around 4 lines and you are done.
I'm basically used to HTTPD, so I will try to stick with it.
NGINX was not that bad either.
It depends on what your site serves.
The following installation steps are all done on CentOS 7.
Previous version of CentOS might not work as previous Apache HTTPD's fast cgi mod are a bit, "challenging".
Specification:
CentOS 7+
Apache HTTPD 2.4+
PHP 5.6+ (Remi Repository)
(After fresh installation of CentOS)
Step 1, Update system, install Remi repository, install PHP and HTTPD
# yum update
# cd /tmp
# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
# rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
# yum install httpd httpd-devel
# yum install --enablerepo=remi, remi-php56 php php-devel php-fpm <any-extra-php-modules-you-need-example-php-mbstring>
Step 2, setup new directory
# cd /var/www/html
# mkdir php-fpm
# printf '<?php\n phpinfo();' > php-fpm/index.php
Step 3, Add a new HTTPD configuration points to the new directory
(A configuration that assign all calls to the directory passes it to php-fpm, on a virtual host)
# vi /etc/httpd/conf.d/php-fpm.conf
# Config Content
<VirtualHost *:80>
ServerName your-servername.com
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/php-fpm/$1
DocumentRoot /var/www/html/php-fpm
<Directory /var/www/html/php-fpm>
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/fpm_error.log
CustomLog /var/log/httpd/fpm_access.log combined
</VirtualHost>
Before proceeding, make sure you added rules to firewalld to allow access.
Step 4, Bring up PHP-FPM and HTTPD
(The steps below disables firewalld and selinux, remember it is important not to disable them on the production server)
# service firewalld stop
# setenforce 0
# service php-fpm start
# service httpd start
Now, access to your server, you will see the php-info, with php-fpm being active in the cgi-fcgi section.
If you want to begin your development on the directory, go on =)
But you might want to concern on the systemd-private-temp configuration if your site allow file uploads.
(CentOS 7 new feature, the "PrivateTemp" option that store in /usr/lib/systemd/system/php-fpm.service)
// Thoughts
It is so much easy on setting up PHP-FPM on CentOS 7 compare to previous CentOS. You need to install mod_fcgi, load it, pass it, very troublesome on virtual host, etc...
Totally a mess.
But it is easy on NGINX. Just around 4 lines and you are done.
I'm basically used to HTTPD, so I will try to stick with it.
NGINX was not that bad either.
It depends on what your site serves.
Subscribe to:
Posts (Atom)