Category Archives: PHP

Install Varnish with Apache on FreeBSD 9.2

Today I want to try to install Varnish on FreeBSD. A few scenarios  on my mind. Install varnish with nginx, lighttpd or cherokee with different port under Apache as front end. Due to lack of experience with Varnish I’ll start with Varnish using Apache first. Others will follow :-)

Lets get started

Check Apache installation

# pkg_info | grep apache
apache22-2.2.26     Version 2.2.x of Apache web server with prefork MPM.

Check location of varnish

# whereis varnish
varnish: /usr/ports/www/varnish

Install varnish

# cd /usr/ports/www/varnish && make install

……….

===> SECURITY REPORT:
This port has installed the following files which may act as network
servers and may therefore pose a remote security risk to the system.
/usr/local/sbin/varnishd
/usr/local/bin/varnishtest

This port has installed the following startup scripts which may cause
these network services to be started at boot time.
/usr/local/etc/rc.d/varnishncsa
/usr/local/etc/rc.d/varnishd
/usr/local/etc/rc.d/varnishlog

If there are vulnerabilities in these programs there may be a security
risk to the system. FreeBSD makes no guarantee about the security of
ports included in the Ports Collection. Please type ‘make deinstall’
to deinstall the port if this is a concern.

For more information, and contact details about the security
status of this software, see the following webpage:
http://www.varnish-cache.org/
Great.

Check it

# pkg_info | grep varnish
varnish-3.0.4       The Varnish high-performance HTTP accelerator

Configure Varnish

Add varnish on rc.conf

# echo 'varnishd_enable=YES' >> /etc/rc.conf

Starting Varnish

# /usr/local/etc/rc.d/varnishd start
Starting varnishd.
Classic hash: 16383 buckets

Check if varnish really run?

# /usr/local/etc/rc.d/varnishd status
varnishd is not running.

Ok…ok..ok.

View varnish configuration

# ee /usr/local/etc/varnish/default.vcl

Inside the file I see these :

 # Default backend definition.  Set this to point to your content
# server.
#
# backend default {
#     .host = “127.0.0.1”;
#     .port = “8080”;
# }

It means the content need to run on port 8080.

Remove all # mark to be like this :

backend default {
.host = “127.0.0.1”;
.port = “8080”;
}

save the file.

Change apache configuration to run on port 8080.

# ee /usr/local/etc/apache22/httpd.conf

change

Listen 80

to

Listen 8080

save the fle.

Restart apache

# /usr/local/etc/rc.d/apache22 restart
Performing sanity check on apache22 configuration:
Syntax OK
Stopping apache22.
Waiting for PIDS: 770.
Performing sanity check on apache22 configuration:
Syntax OK
Starting apache22.

# ps -ax | grep httpd
944 ??  Ss    0:00.11 /usr/local/sbin/httpd -DNOHTTPACCEPT
945 ??  S     0:00.00 /usr/local/sbin/httpd -DNOHTTPACCEPT
946 ??  I     0:00.00 /usr/local/sbin/httpd -DNOHTTPACCEPT
947 ??  I     0:00.00 /usr/local/sbin/httpd -DNOHTTPACCEPT
948 ??  I     0:00.00 /usr/local/sbin/httpd -DNOHTTPACCEPT
949 ??  I     0:00.00 /usr/local/sbin/httpd -DNOHTTPACCEPT

Retry to run varnish

# /usr/local/etc/rc.d/varnishd start
Starting varnishd.
Classic hash: 16383 buckets

Check varnish
# ps -ax | grep varnish
963 ??  Ss    0:00.00 varnishd: Varnish-Mgr freebsd92.rasyid.net (varnishd)
964 ??  S     0:00.03 varnishd: Varnish-Chld freebsd92.rasyid.net (varnishd)
966  0  R+    0:00.00 grep varnish

Check Varnish

Check via phpinfo file, I can see it run on Varnish :

varnish_freebsd92

Interesting. I’ll continue this experiment with different web server as soon as possible.

See you.

P.S : you can enable varnish log

# echo 'varnishlog_enable=YES' >> /etc/rc.conf
# /usr/local/etc/rc.d/varnishlog start
Starting varnishlog.

Deploy google app engine : appcfg.py

Deploy php script aka application to google app engine is interesting. I came from traditional ftp-ing (so 1999 hehehe), scp and cpanel. Google app engine provide 2 ways of deployment; through appcfg.py and via git. I’ll try to explore both options now.

Preparation

In this stage, application need to get register first to App Engine Administration Console. Visit this address to get it done :

https://appengine.google.com/

Selection_008

Choose google account to use for this purpose.

Selection_009

click “Create Application” button.

Selection_010

make sure to check name availability and quota application (max 10).

Selection_011

Google app engine will need grant access from your google account.

Selection_012

Click ‘Accept” button to get started.

 

Deployment using appcfg.py

$ google_appengine/appcfg.py –oauth2 update digitalfusi/

08:59 PM Application: difuphp; version: 1
08:59 PM Host: appengine.google.com
08:59 PM
Starting update of app: difuphp, version: 1
08:59 PM Getting current resource limits.
Your browser has been opened to visit:

https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&response_type=code&client_id=xxxxx6889yyy.apps.googleusercontent.com&access_type=offline

If your browser is on a different machine then exit and re-run this
application with the command-line parameter

–noauth_local_webserver

(process:3287): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0′ failed
Authentication successful.
09:01 PM Scanning files on local disk.
09:01 PM Cloning 2 application files.
09:01 PM Uploading 2 files and blobs.
09:01 PM Uploaded 2 files and blobs
09:01 PM Compilation starting.
09:01 PM Compilation completed.
09:01 PM Starting deployment.
09:01 PM Checking if deployment succeeded.
09:01 PM Deployment successful.
09:01 PM Checking if updated app version is serving.
09:01 PM Completed update of app: difuphp, version: 1

Testing the result by visit http://difuphp.appspot.com

Selection_013

appcfg.py is very straightforward command. Combine with oauth option I can upload all my php script to google infrastructure. Awesome.

 

install php sdk for google app engine on ubuntu 13.04

Another need for try php on google app engine make install all required stuff :

Install python

$ sudo apt-get install python

Check version :

$ python -V
Python 2.7.4

Install PHP CGI

Download latest php 5.4 from download page :

$ wget -c http://au1.php.net/get/php-5.4.22.tar.gz/from/this/mirror -O php-5.4.22.tar.gz

$ tar xvzf php-5.4.22.tar.gz

$ cd php-5.4.22/

$ sudo apt-get install gcc libmysqlclient-dev libxml2-dev

$ ./configure --prefix=$PWD/installdir --enable-bcmath --with-mysql

$ make install

Check version :

$ pwd

/home/alamsyah/php-5.4.22

using absolute path

$ /home/alamsyah/php-5.4.22/installdir/bin/php-cgi -v

PHP 5.4.22 (cgi-fcgi) (built: Nov 23 2013 11:22:27)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

Google APP engine SDK for PHP

Download latest version from here.

$ cd

$ wget -c http://googleappengine.googlecode.com/files/google_appengine_1.8.8.zip

$ unzip google_appengine_1.8.8.zip

MySQL Server

$ sudo apt-get install mysql-server-5.5 mysql-client-5.5

check :

$ dpkg -l | grep mysql

ii  libdbd-mysql-perl                         4.021-1                                i386         Perl5 database interface to the MySQL database
ii  libmysqlclient-dev                        5.5.34-0ubuntu0.13.04.1                i386         MySQL database development files
ii  libmysqlclient18:i386                     5.5.34-0ubuntu0.13.04.1                i386         MySQL database client library
ii  mysql-client-5.5                          5.5.34-0ubuntu0.13.04.1                i386         MySQL database client binaries
ii  mysql-client-core-5.5                     5.5.34-0ubuntu0.13.04.1                i386         MySQL database core client binaries
ii  mysql-common                              5.5.34-0ubuntu0.13.04.1                all          MySQL database common files, e.g. /etc/mysql/my.cnf
ii  mysql-server-5.5                          5.5.34-0ubuntu0.13.04.1                i386         MySQL database server binaries and system database setup
ii  mysql-server-core-5.5                     5.5.34-0ubuntu0.13.04.1                i386         MySQL database server binaries

Great, client and server installed.

At this stage all requirement has installed correctly. I need php editor and I choose sublime text 2.

Install Sublime Text 2

$sudo add-apt-repository ppa:webupd8team/sublime-text-2

$sudo apt-get update

$sudo apt-get install sublime-text

Selection_005


					

Install Laravel 4 on Windows 7

Working with laravel Shirt I want to learn new things and it seem a lot of changes already happened. Specially PHP. First time I learn about this lang I see 4.0 version. Today, I see PHP already reach 5.3, 5.4 and so on. I don’t know about OOP in PHP so I decide to learn about OOP by doing it on project.

Laravel is my option after CodeIgniter . As usual, installation is big thing for me and my netbook run on Windos 7 starter.

Steps for Laravel installation on Windows 7 :

Download latest laravel version 

In time of writing I got 4.0.4 version.

Put it on Xampp htdocs directory.

I rename it to laravel after extract its content.

install_laravel_windows7_1

 

Install Git

Git work ‘distribution system control‘ . It will work together with composer.

Download latest version of Git for Windows from here.

Installation is straightforward. A few notes during installation :

– Make sure to choose “Run Git from the Windows Command Prompt” on adjusting your PATH environment section.

Checkout Window style,commit unix-style line endings on Configuring the line ending conversion section.

Install Composer for Windows

Get latest version from here. Install it as usual. Nothing serious here :-)

Configuration

In this section we just need to check if everything is work.

1. Check php version
C:\Users\pc>php -v

PHP 5.4.7 (cli) (built: Sep 12 2012 23:48:31)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

C:\Users\pc>

2. Check Git version

Continue reading

Downgrade php version from 5.3 to 5.2 on Ubuntu 10.10 x86

New Server has come and again I must downgrade php version to 5.2 due to some problem on web application. I use same method I use for Ubuntu 10.04 for Ubuntu 10.10 x86.

Let start

Download required files for PHP 5.2 from Ubuntu Karmic repository

#cd /etc/apt/sources.list.d

#wget http://randyfay.com/sites/default/files/karmic_0.list

# cd /etc/apt/preferences.d/

#wget http://randyfay.com/sites/default/files/php_1.

# mv php_1. php

Find out installed PHP version

# php -v

PHP 5.3.3-1ubuntu9.1 with Suhosin-Patch (cli) (built: Oct 15 2010 14:00:18)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
#

# dpkg –get-selections | grep php
libapache2-mod-php5                             install
php-db                                          install
php-pear                                        install
php5                                            install
php5-cli                                        install
php5-common                                     install
php5-gd                                         install
php5-mcrypt                                     install
php5-mysql                                      install
php5-xsl                                        install

Delete those PHP with apt-get remove

# apt-get remove libapache2-mod-php5 php-db php-pear php5 php5-cli php5-common php5-gd php5-mcrypt php5-mysql php5-xsl

# apt-get autoremove

Add php5-mcrypt

# nano /etc/apt/preferences.d/php

put these lines :

Package: php5-mcrypt
Pin: release a=karmic
Pin-Priority: 991

at the bottom.

Update repository and reinstall PHP

#apt-get update

#apt-get install php5 libapache2-mod-php5 php-db php5-cli php5-common php5-xsl php5-gd php-pear php5-mysql php5-curl php5-memcache php5-mcrypt

Check PHP version

# php -v

PHP 5.2.10-2ubuntu6 with Suhosin-Patch 0.9.7 (cli) (built: Oct 23 2009 16:30:10)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
#

Great.

PHP successfully downgrade to 5.2.10 on Ubuntu 10.10 x86