Thursday, July 4, 2013

Adding MCRYPT to your OSX based PHP server setup


Fire up your terminal and do this;
php --version
Now you will see the version number of your PHP; you will need to match the source version with this. Mine is 5.3.15 for PHP and I downloaded the 2.5.8 version of mcrypt. If you use different versions, then substitute the correct versions.
mkdir /tmp/source && cd /tmp/source
curl --location -s http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download | tar -zx
curl --location -s http://nl3.php.net/get/php-5.3.15.tar.gz/from/nl1.php.net/mirror  | tar -zx

Installation

cd /tmp/source/libmcrypt-2.5.8
MACOSX_DEPLOYMENT_TARGET=10.8 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64'  ./configure --disable-dependency-tracking
make -j6
sudo make install

cd /tmp/source/php-5.3.15/ext/mcrypt/
phpize
MACOSX_DEPLOYMENT_TARGET=10.8 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64'  ./configure --with-php-config=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/bin/php-config
make -j6
sudo make install

Possible errors


You may encounter a problem during build if some C modules aren’t available. If you get an error like this
error: 'PHP_FE_END' undeclared here (not in a function)

. You can avoid this by editing the file mentioned in the error message and replace all occurrences of PHP_FE_END with {NULL,NULL,NULL} .

Same thing might happen with function ZEND_MOD_END .

After fixing, issue the commands
make -j6
sudo make install


This should build now.

I have no idea what effect this will have on the end-result, but at least it builds :)


Cleanup


now remove the temporary files
cd ~ && rm -rf /tmp/source

Activation


Edit your PHP configuration
sudo nano /etc/php.ini


if “New file” is shown, please copy php.ini-dist to php.ini and try again. Use google for this one :)

other tutorials tell you to set
enable_dl=on
but do NOT, I repeat NOT do that; the DL function is deprecated and limited to a few extensions anyway, so you do NOT need this. Just add this line on the bottom of your php.ini;
extension=mcrypt.so


Now restart your Apache
sudo apachectl restart

in your terminal type
php --info | grep crypt
you should see:
mcrypt support => enabled
Now you’re done!

Friday, May 17, 2013

Fix mysql.sock connection problem PHP, MySQL in Mac Mountain Lion

I was setting up a PyroCMS site on my Mac (Mountain Lion) and I had this error:

A Database Error Occurred
Unable to connect to your database server using the provided settings.

Filename: core/Loader.php

Line Number: 1191

So I followed the instruction of this forum: http://ellislab.com/forums/viewthread/207916/
Changing the 'db_debug'  => true, to false on the database.php file.

After doing this I tested again the site and this errors appear:

A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 0

Filename: core/MY_Controller.php

Line Number: 97

A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 0

Filename: core/MY_Controller.php

Line Number: 113

An Error Was Encountered [ 500 ]
Unable to load the requested language file: language//choice_lang.php

So I kept on searching and then I found this link: http://stackoverflow.com/questions/4219970/warning-mysql-connect-2002-no-such-file-or-directory-trying-to-connect-vi/7264459#7264459

I didn't have /var/mysql/mysql.sock file, so I followed the instructions:

If you have /tmp/mysql.sock but no /var/mysql/mysql.sock then...

cd /var 
mkdir mysql
cd mysql
ln -s /tmp/mysql.sock mysql.sock

If you have /var/mysql/mysql.sock but no /tmp/mysql.sock then

cd /tmp
ln -s /var/mysql/mysql.sock mysql.sock

You will need permissions to create the directory and link, so just prefix the commands above with sudo if necessary.

And it works!

Monday, May 13, 2013

How to set up Multiple SSH account for Github


Step 1 – Create a New SSH Key

We need to generate a unique SSH key for our second GitHub account.


ssh-keygen -t rsa -C "your-email-address"


Be careful that you don’t over-write your existing key for your personal account. Instead, when prompted, save the file as id_rsa_SECOND. In my case, I’ve saved the file to ~/.ssh/id_rsa_cristianfierro.

Step 2 – Attach the New Key

Next, login to your second GitHub account, browse to “Account Overview,” and attach the new key, within the “SSH Public Keys” section. To retrieve the value of the key that you just created, return to the Terminal, and type: clip < ~/.ssh/id_rsa_cristianfierro.pub. That copies public key, and then you have to paste this into the GitHub textarea. Feel free to give it any title you wish.
Next, because we saved our key with a unique name, we need to tell SSH about it. Within the Terminal, type: ssh-add ~/.ssh/id_rsa_SECOND. If successful, you’ll see a response of “Identity Added.”
If you are using Windows maybe you will get this error: “Could not open a connection to your authentication agent”


Solution:
In the CMD window, type the following command:
cd path-to-Git/bin (for example,cd C:\Program Files\Git\bin)
bash
exec ssh-agent bash
ssh-add path/to/.ssh/id_rsa_cristianfierro


Step 3 – Create a Config File

We’ve done the bulk of the workload; but now we need a way to specify when we wish to push to our personal account, and when we should instead push to our company account. To do so, let’s create a config file.
touch ~/.ssh/config
vim config
If you’re not comfortable with Vim, feel free to open it within any editor of your choice. Paste in the following snippet.

#default account
Host github.com
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa

This is the default setup for pushing to our personal GitHub 
account. Notice that we’re able to attach an identity file to the host. 
Let’s add another one for the company account. Directly below the code 
above, add:

#cristianfierro account
Host cristianfierro.github.com
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_cristianfierro
 
This time, rather than setting the host to github.com, we’ve named it as SECOND.github.com. The difference is that we’re now attaching the new identity file that we created previously: id_rsa_SECOND. Save the page and exit!

Step 4 – Try it Out

It’s time to see if our efforts were successful.

When you want to clone a repository with the SECOND account, instead of using:

git clone git@github.com:second/secondsproject.git


You should use :


git clone git@second.github.com:second/secondsproject.git

In my case:

git clone git@cristianfierro.github.com:cristianfierro/project.git



Step 5 – Change User Information

After all you have to change the information of the second repo
cd my_other_repo
# Changes the working directory to the repository you need to switch info for
git config user.name "Different Name"
# Sets the user's name for this specific repository
git config user.email "differentemail@email.com"
# Sets the user's email for this specific repository

Wednesday, April 10, 2013

How to set SVN repository on Bluehost


Step 1

Make sure that svn is installed on your web host. Just ssh into your account and type

which svn

Step 2

Create your repository.
To create the repository, issue the following command:

svnadmin create ~/myrepository

Step 3

Create your SVN user:
Simply open the svnserve.conf file in the editor of your choice:

vim ~/myrepository/conf/svnserve.conf

and add the following:

anon-access = none
auth-access = write
password-db = passwd


Now you'll need to create a password file:

vim ~/myrepository/conf/passwd

Add a line in that file for your user in the format =

exampleuser = examplepassword

Step 4

Create ssh keys

Windows: Using PuTTYgen, save public and private key, and copy the public key from the box

Step 5

Add your public key to the authorized file

Create .ssh directory if you don't have it

mkdir .ssh
chmod 700 .ssh
touch authorized_keys
chmod 600 authorized_keys
vim authorized_keys

Enter "i" to edit and insert:

command="svnserve -t --tunnel-user=svnuser",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty KEY_FROM_PUTTYGEN

All in one line

Step 6

For Windows use Pageant and add the Private Key you created with PuTTYgen and try to checkout your repository

svn+ssh://[sshuser]@[primary_domain]/[home_path]/[repo_path]

For checkout inside the Bluehost server:

svn co file:///home/svn/project




Tuesday, April 9, 2013

Remove the @ from file in Mac Mountain Lion


Let say we want to remve the @ from the files


You can run the command:

xattr -rd com.apple.quarantine Symfony


Setting Mac Mountain Lion Server PHP and Apache


SOURCE: http://todsul.com/lamp-mac-os-x-lion

1. Configure Apache

Use vi to configure the httpd.conf file.
sudo vi /etc/apache2/httpd.conf
Enable PHP and virtual hosts by uncommenting these lines:
LoadModule php5_module libexec/apache2/libphp5.so
Include /private/etc/apache2/extra/httpd-vhosts.conf
Include /private/etc/apache2/extra/httpd-ssl.conf
Give your user permissions.
sudo vi /etc/apache2/users/[username].conf
<Directory />
    Options FollowSymLinks Indexes MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

2. Install & Configure Git

Download the latest verion of Git for Mac here.
reboot
git config --global user.name 'username'
git config --global user.email 'email'
Initialize the Git directory and pull the latest code.
cd /path/to/website
git init
git remote add origin https://github.com/path/to/repo.git
git pull origin master
Use the OSX Keychain to save the password.
curl -s -O http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain
chmod u+x git-credential-osxkeychain
which git
sudo mv git-credential-osxkeychain /usr/local/git/bin/
git config --global credential.helper osxkeychain

3. Configure Virtual Hosts

sudo vi /etc/hosts
Add a virtual hostname for each website.
127.0.0.1 [example].localhost
Configure directories and logs for apache.
sudo vi /etc/apache2/extra/httpd-vhosts.conf
Configure HTTP virtual hosts.
<VirtualHost *:80>
    DocumentRoot "/path/to/web/folder"
    ServerName [example].localhost
</VirtualHost>

4. Setup Self-Signed SSL Certificate

cd /etc/apache2
sudo ssh-keygen -f server.key
sudo openssl req -new -key server.key -out request.csr
sudo openssl x509 -req -days 365 -in request.csr -signkey server.key -out server.crt
sudo openssl rsa -in server.key -out server.nopass.key
sudo vi /etc/apache2/extra/httpd-ssl.conf
Configure HTTPS virtual hosts.
DocumentRoot "/path/to/web/folder"
ServerName [example].localhost
SSLCertificateFile "/etc/apache2/server.crt"
SSLCertificateKeyFile "/etc/apache2/server.nopass.key"

5. Install & Configure MySQL

  • Download the Mac OS X package from the MySQL download page
  • Make sure it's the 64-bit DMG archive version
  • Install MySQL, the pref pane and the startup scripts.
Create config, set timezone to UTC and set storage to ramdisk.
sudo cp /usr/local/mysql/support-files/my-small.cnf /etc/my.cnf
sudo vi /etc/my.cnf
[mysqld]
...
default_time_zone = '+00:00'
datadir = /Volumes/ramdisk/data
innodb_flush_log_at_trx_commit = 2
innodb_data_home_dir = /Volumes/ramdisk/data
Add the mysql path to your profile.
sudo vi ~/.bash_profile
Add this line to the file:
export PATH="/usr/local/mysql/bin:$PATH"
Reload the profile.
su - [username]
Run the ramdisk script found here.

6. Configure php.ini

Enable the php.ini file and open it for editing.
sudo cp /etc/php.ini.default /etc/php.ini
sudo vi /etc/php.ini
Change the timezone and uni socket path for MySql to ramdisk:
date.timezone = UTC
...
pdo_mysql.default_socket=/tmp/mysql_ram.sock
...
detect_unicode = Off (at end, doesn't yet exist)

7. Start Services

sudo apachectl restart
cd /usr/local/mysql
./bin/mysqld_safe

8. Dev Extras

Remove sudo password.
sudo visudo
[username] ALL=(ALL) NOPASSWD: ALL
Install composer.
curl -s http://getcomposer.org/installer | php
php composer.phar install
Set permissions on cache and logs.
sudo rm -rf app/cache/*
sudo rm -rf app/logs/*
sudo chmod +a "www allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
Install Java by initiating the installer.
java -version

Wednesday, March 13, 2013

Setting up Virtual Hosts with XAMPP running on Windows 7

The Steps
  1. First I am going to assume you’re using a Windows machine and have XAMPP installed.
  2. Open the XAMPP control panel application and stop Apache. Be aware that late Windows machines might run it as a service, so check the box to the left of the Apache module.
  3. Navigate to C:/xampp/apache/conf/extra or wherever your XAMPP files are located.
  4. Open the file named httpd-vhosts.conf with a text editor.
  5. Around line 19 find # NameVirtualHost *:80 and uncomment or remove the hash.
  6. At the very bottom of the file paste the following code:


    <VirtualHost *:80>
        DocumentRoot "C:/xampp/htdocs"
        ServerName localhost
    </VirtualHost>



  7. Then after that you can copy this code:


    <VirtualHost *:80>
        ServerName zf2-tutorial.localhost
        DocumentRoot "C:/xampp/htdocs/zf2-tutorial/public"
        SetEnv APPLICATION_ENV "development"
        <Directory "C:/xampp/htdocs/zf2-tutorial/public">
            DirectoryIndex index.php
            AllowOverride All
            Order allow,deny
            Allow from all
        </Directory>
    </VirtualHost>



Tuesday, January 8, 2013

Functions for obtain get parameters

Functions for obtain get parameters

While I was searching how to obtain GET parameters from the URL using only Javascript, I found this code. But I don't remember the source of it.

$.extend({
 getUrlVars: function(){
  var vars = [], hash;
  var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
  for(var i = 0; i < hashes.length; i++)
  {
   hash = hashes[i].split('=');
   vars.push(hash[0]);
   vars[hash[0]] = hash[1];
  }
  return vars;
 },
 getUrlVar: function(name){
  return $.getUrlVars()[name];
 }
});