Tag Archives: php

Backup MySQL Databases

If you are running a database driven website then your data sitting in MySQL database id most important for you. In most of shared hosting there is no provision for scheduled backup of databases. So I have written a script to take backup of all databases associated with the account.

Install LAMP in UBUNTU 12.10 / 13.04 / 13.10

I installed Ubuntu 12.10 on my new laptop and now I have to setup LAMP on it. To setup LAMP I need to install Apache Web Server, PHP and MySQL.
For installation issue following commands:

Above command will download and install Apache Web Server. It will ask for permission to download the setup file. After completion of above command open the browser and browse following URL:

If it is opening properly, your web server is installed properly. Now we will install PHP:

Above command will download and install PHP and apache integration library. It will ask for permission to download the setup file.
To check the installation of php issue following command:

Write following code in this file and save it:

In the browser open following URL:

It will display PHP configuration details. We have installed PHP and integrated it with Apache Web Server.
If you are not getting required page the you need to restart Apache:

Our next task is to install MySQL server and PHP-MySQL connector. For this issue following command:

If you are running Ubuntu 13.10, issue following command:

It will download and install MySQL Server. After installation it will ask to setup root password for database server.
Now we have installed Apache Web Server, PHP and MySQL. For database management you may need phpMyAdmin. To install phpMyAdmin issue following command:

After installation open following URL:

You will get the login screen of phpMyAdmin.

Congrats, You are done!!

CakePHP to Red Hat’s Openshift

There is only 6 easy steps to deploy your application to cloud.

Step 1 : Sign Up

Just visit to openshift and sign up a new account.

Step 2 : Install client tool

For installation instruction of client visit here

Step 3 : Create domain

Domain is the unique namespace for every account. Execute following command to create your domain

Step 4 : Create application

app name is the name of your application ant app type is the type of application you want to create. For a php application we execute following command:

Step 5 : Add MySQL to your application

Step 6 : Deploy your application to cloud
Once the application is created, it needs to deployed to cloud. After execution of step 4, a folder with the application name is created in current directory. Goto current directory and add cakephp to it.

 

You can access your application from the URL :

http://mycake-mydomain.rhcloud.com

File Upload in CakePHP

In this post I will describe how to upload images in CakePHP. It will automatically upload and move the uploaded file to the wanted location. It will automatically rename the file if there is another file with same name exist. A lot of other features are also available.

  • Download Upload Component file and copy it to the location app/Controller/Component/UploadComponent.php
  • Initialize
  • Your add action would looks like:
  • We have setup our controller. Now its time to setup view file add.ctp. The file file should look like following:
  • All done.

UploadComponent class file is well document so you can always find all configuration setting for the uploaded images.

Setting Auth & ACL in CakePHP

In last few days I learned CakePHP and now I am finding it very interesting. I learned the basics about creation of models and their relationships. Now its time to move ahead. I am exploring more features and I started with inbuilt Auth component of CakePHP which I found very interesting. Let me tell you one thing that if you are following the conventions you can save a lot of time.

To set up Auth and ACL for my application I followed Mark Story’s post which is very helpful. I followed the tutorial and I was easily able to setup Auth & ACL for my application.

But in my application every user belongs to some group and it must inherit permission from that group only. There should not be any user wise permission. This case is not handled in the above tutorial. So, whenever I add new user a new ARO record is being created in aros table, which is not required. I dont want any ARO record for my users as they are inheriting permission from their group. To achieve this functionality I modified $actAs variable as follows:

Look at the declaration carefully as I am passing two parameters type and enabled. Second parameter enabled tells the behaviour class not to look for ARO record for User model if there is already a ARO record of parent Group model. Now we have to define a function bindNode to tell that this user is bind to which ARO node. This function must return a reference to group model. So our bindNode function would look like: