Hosting: Enabling Redis class on MediaTemple’s gridserver (gs)

Here's how I enabled access to a Redis server from my (GS) gridserver:

1. Store your SITEID in a variable:

export SITEID=`pwd | awk -F\/ '{ print $3 }'`

 

2. Create a folder to store the redis.so module

mkdir /home/$SITEID/data/lib
mkdir /home/$SITEID/data/lib/php/

 

3. Get the Redis PECL package (2.2.4 is the latest as of now)

wget http://pecl.php.net/get/redis-2.2.4.tgz

 

4. Uncompress it

tar -xvzf redis-2.2.4.tgz
cd redis-2.2.4

 

5. Compile it. I've set my (gs) to use PHP 5.5.5; change your accordingly

./configure --with-php-config=/usr/local/php-5.5.5/bin/php-config
make

 

6. "install" the module

cp modules/*.so /home/$SITEID/data/lib/php

 

7. Add the following to your /home/SITEID/etc/php.ini

;PECL
extension_dir=/home/97042/data/lib/php/
;redisphp
extension=redis.so

 

Check it:

Visit http://SITEID.gridserver.com/gs-bin/phpinfo.php-latest

 

redis-2-2-4-module

References

  • https://kb.mediatemple.net/questions/1682/Installing+PECL+extensions#gs
  • https://github.com/nicolasff/phpredis/issues/42
  • http://pecl.php.net/package/redis

Raspberry Pi: installing a LAMP server

Let's put the Raspberry Pi to good use:

 

1. Install Mysql

sudo pacman -S mysql

2. Start your server

# systemctl start mysqld

3. Secure your mysql installation

# /usr/bin/mysql_secure_installation

——————-

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 … Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 … Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 … Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 – Dropping test database…
 … Success!
 – Removing privileges on test database…
 … Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 … Success!

Cleaning up…

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

———————-

 

# nano /etc/mysql/my.cnf

 

[mysqld]

bind-address=127.0.0.1

 

 

Restart mysql

systemctl restart mysqld

 

 

================

Install PHP

 

pacman -S php php-apache libmcrypt libtool

 

nano /etc/php/php.ini

 

 

 

======================

 

nano /etc/locale.gen

enable:

en_US.UTF-8 UTF-8
en_US ISO-8859-1

 

save and generate your locales

# locale-gen

 

 

Install and Configure PostgreSQL

pacman -S postgresql

 

# mkdir -p /var/lib/postgres/data

# chown httpd:httpd -Rv /var/lib/postgres/

 

Configure Postgresql data dir

# su – postgres -c "initdb –locale en_US.UTF-8 -D '/var/lib/postgres/data'"

———————–

The files belonging to this database system will be owned by user "httpd".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

fixing permissions on existing directory /var/lib/postgres/data … ok
creating subdirectories … ok
selecting default max_connections … 100
selecting default shared_buffers … 24MB
creating configuration files … ok
creating template1 database in /var/lib/postgres/data/base/1 … ok
initializing pg_authid … ok
initializing dependencies … ok
creating system views … ok
loading system objects' descriptions … ok
creating collations … ok
creating conversions … ok
creating dictionaries … ok
setting privileges on built-in objects … ok
creating information schema … ok
loading PL/pgSQL server-side language … ok
vacuuming database template1 … ok
copying template1 to template0 … ok
copying template1 to postgres … ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
–auth-local and –auth-host, the next time you run initdb.

Success. You can now start the database server using:

    postgres -D /var/lib/postgres/data
or
    pg_ctl -D /var/lib/postgres/data -l logfile start
 

——————————————

 

Enable the service

# systemctl enable postgresql

Start if you want to use it before rebooting

# systemctl start postgresql

 

Facebook: Creating your first APP in PHP

So you finally decided you want to create a Facebook app to make your million dollar idea pay off a million dollars! Great!

 

Cutting to the chase:

 

1. Install the Developers App so you can get started creating apps on Facebook.

https://developers.facebook.com/

and click Allow

2. Create and Configure your App

Click on Apps and then "Create New App"

Configure your App

 

3. Download the SDK

Get the PHP SDK here

https://developers.facebook.com/docs/reference/php/

Extract the contents to a /facebook/ folder in your public html folder on your server

 

 

4. Create your minimum App (Who needs a Hello World?)

TO-DO

5. Enhance your App

TO-DO

6. Make it work outside Facebook

TO-DO

7. Make a mobile version

TO-DO

8. Make millions

TO-DO

9. Send me stuff 🙂

 

 

PHP 5: Mass Virtual Hosting points $_SERVER[‘DOCUMENT_ROOT’] to wrong folder

When I set up mass virtual hosting for my servers, it seems PHP won’t get the right $_SERVER[‘DOCUMENT_ROOT’]

Here’s the solution I found:

1.Edit your php.ini (the file location depends on  how you have PHP setup)

2. Edit this section

; Automatically add files before PHP document.
; http://php.net/auto-prepend-file
auto_prepend_file = /home/httpd/prepend.php

3. Create the prepend file:

<?php
$_SERVER['DOCUMENT_ROOT'] = str_ireplace($_SERVER['SCRIPT_NAME'], '', $_SERVER['SCRIPT_FILENAME']);

4. Restart your httpd server. I have done this for both Apache 2 and NGINX. (It probably doesn’t matter as it’s a PHP issue)

Great way to integrate SwiftMailer and Kohana 3

Just found this post:

http://www.flynsarmy.com/2010/06/integrating-swift-mailer-into-kohana-3/

by Flynsarmy

showing the simplest way to integrate SwiftMailer and Kohana 3

Create the following files/folders:
/modules/swiftmailer
/modules/swiftmailer/init.php
/modules/swiftmailer/classes

Inside /modules/swiftmailer/classes/ drop the official latest build of Swift Mailer.

Enter the following into init.php.

<?php
require Kohana::find_file('classes', 'Swift-4.0.6/lib/swift_required');

There. Wasn’t that easy? Remember to enable the module by adding it to your bootstrap.php file!

My current methods while using Kohana 3.0.8 – part 1

I’ve finally decided to get started on documenting how I’ve been using this wonderful framework.

So if you’re patient enough to deal with my crazy schedule (meaning this series may take a while to be finish), fasten your seatbelt:

First of all:

  • Know your environment (your public html folder, a private [but still accessible] folder; permissions etc);
  • Know the difference between server side and client side programming;
  • Download Kohana (http://kohanaframework.org/) 🙂
  • Have your favorite source code editor and ftp client close to you

For the sake of whoever wants to get started with Kohana, I’ll go over the basics (not programming) and I’ll also cover everything that got me breaking my head, so I have a copy outside my brain.

[To-Do: find short video of Sean Connery’s character explaining to Harrison Ford’s character why he wrote everything down on a book]

Kohana v3.03 reset

Download Kohana v3.0.3

Upload files to your server

Fix these paths inside index.php:

$application = '../application';
$modules = '../modules';
$system = '../system';

Try accessing to make sure you installed correctly:

http://kohanav3.portnumber53.com/

Some tweaks:

Inside application/bootstrap.php:

date_default_timezone_set('America/Los_Angeles');
kohana::init(array(
 'base_url' => '/',
 'index_file' => '',
));

Now create: application/classes/controller/layout.php

Now extend the previous controller: application/classes/controller/website.php

And create a controller to handle content: application/classes/controller/content.php

Weird: FCK loses first line of formatted text when submitting

Last night (Oct, 28th), I was fixing a very weird problem where text edited using FCK, submitted via jQuery was losing the very first line when it was formatted (color, style) but not every single time… randomly it seemed.

At first, I thought it would be something wrong with FCK editor and checked if there was an updated version. I was using 2.5.x on my site and 2.6.5 is current in the 2.x series (and 3.0.1 was just released, note: checking that for another website [http://thirdgenerationco.com]).

Since I didn’t want to introduce new features (cause my client freaks out when I do without letting him know), I thought I’d give 2.6.5 a try. That did not solved my problem.

My next logical step was checking how jQuery was encoding the text to preserve quotes and double quotes and making sure PHP was getting that right. Which both were.

Next, I tried adding slashes and stripping them down, which also did not work.

At this point, I thought about changing my Ajax approach…..  but before that I’d though I’d give JSON a try.  🙂

So this is the changes I’ve made in my coding:

Javascript side (My text is edited inside a dialog window (created using jQuery-UI) and then posted using Ajax, from the main window.

var new_text = $('#frame_frontpage').contents().find('#previewMyStoreMessageBoard').html();
$("#previewFrontPageText").html(new_text);
$("#frontpage_text").val(new_text);
var str = $("#form_frontpage_text").serialize();
var This = this;
$.post('/member/store_home_page/ajax_save_frontpage_text', str,
$.post('/member/store_home_page/ajax_save_frontpage_text', {frontpage_text: new_text},
  function(text) {
    if (text == "success") {
    alert("Store Description Text submitted successfully.");
    $(This).dialog('close');
  } else {
    alert(text);
  }
}
);

Besides that I just added addslashes() and stripslashes() to preserve double quotes to/from the database.
And it’s now working 😀

Working with Kohana PHP Framework v2.3.4

Let’s start working with Kohana (I’ve actually been working with it for a while and thought would be nice to share my experiences)!

First thing you want to do is download it and extract it to a folder on your webserver.

You can read about it and download it at: http://www.kohanaphp.com/

Right after extracting Kohana to your webserver folder, you should see the following when accessing it:

Kohana 2.3.4 - environment tests

Kohana 2.3.4 - environment tests

If you don’t see the output above, check your server settings and logs to help you figure what’s wrong. Feel free to drop me a message, if you need more help after that.

After you remove install.php like required above, refresh the page and you should see this:

Kohana 2.3.4 - Welcome to Kohana

Kohana 2.3.4 - Welcome to Kohana

Please take some time to go over the documentation at http://docs.kohanaphp.com/ so you don’t feel totally lost. 🙂

As time allows me, I will be writing more stuff about Kohana. This is just a first post to get people started.

http://www.kohanaphp.com/You
  • IGlr