Tag Archives: php

[SOLVED] Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0

While trying to run a single-file php script in my Fedora 15 installation, I got a very strange error:

Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0

Fatal error: Unknown: Failed opening required ‘/var/www/html/test/filename.php’ (include_path=’.:/usr/share/pear:/usr/share/php’) in Unknown on line 0

To get rid of this error, right click and go to Properties. Then, in Permissions, make sure it is readable by other users and it has a SELinux context httpd_user_content_t. That should do it.

[HOWTO] Compile Facebook hiphop-php in Fedora 15

HipHop for PHP is a source code transformer which transforms PHP code to C++ and compiles it with gcc/g++. I wanted to experiment with it and tried to install in on my PC with Fedora 15. Here is how I did it and how you can do it ( hopefully 🙂 ). Please note that this did not work and I will update the article soon.

Install Dependencies Available in the Repos
In the terminal, run the following command:

su -c 'yum -y install git cmake boost pcre-devel libicu-devel libmcrypt-devel oniguruma-devel mysql-devel gd-devel boost-devel libxml2-devel libcap-devel binutils-devel flex bison expat-devel re2c tbb libmemcached-devel tbb-devel bzip2-devel openldap-devel readline-devel libc-client-devel pam-devel gcc-c++ memcached'

Setup build environment
I compiled it in dev folder of home directory. Change directory in subsequent commands if you are doing it somewhere else. Run the following commands:

cd
mkdir -p dev/local

Download hiphop-php

cd
cd dev
git clone git://github.com/facebook/hiphop-php.git

Download, patch and compile libcurl and libevent
Use these versions because as of current, patches for these versions are only available in hiphop git.

cd
cd dev

wget http://curl.haxx.se/download/curl-7.20.0.tar.bz2
wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz
tar xvzf libevent-1.4.13-stable.tar.gz
tar xvjf curl-7.20.0.tar.bz2

export CMAKE_PREFIX_PATH=`pwd`/local

cd libevent-1.4.13-stable
cp ../hiphop-php/src/third_party/libevent-1.4.13.fb-changes.diff .
patch < libevent-1.4.13.fb-changes.diff
./configure --prefix=`pwd`/../local
make install
cd ..

cd curl-7.20.0
cp ../hiphop-php/src/third_party/libcurl.fb-changes.diff .
patch -p0 < libcurl.fb-changes.diff #see note-1 below

Note-1: While patching curl, you may be asked paths to the files. Enter includes/curl/multi.h and lib/multi.c respectively.

Now, you will need to make a small change in Makefile for it to compile properly. To do that open the file src/Makefile in gedit or any text editor, find the line that has the following:

curl_LDADD = $(top_builddir)/lib/libcurl.la -lz

and append -lrt so that the line looks like the following:

curl_LDADD = $(top_builddir)/lib/libcurl.la -lz -lrt

Now, run the following in the terminal:

cd
cd dev/curl-7.20.0
./configure --prefix=`pwd`/../local
make install
cd ..

Compile hiphop-php

cd
cd dev
export CMAKE_PREFIX_PATH=`pwd`/local
cd hiphop-php
git submodule init
git submodule update
export HPHP_HOME=`pwd`
export HPHP_LIB=`pwd`/bin
cmake . #see note-2 below
make #see note-3 below

Note-2: You may get errors while running cmake. This may be because of dependencies I might have missed above. In that case, please let me know the output of cmake in the comments so that I might be able to help.
Note-3: If you encounter any errors while using make, remove CMakeCache.txt and run make clean, cmake and make again.

This should have worked, but I am getting the following error:

../../bin/libhphp_runtime.a(ext_mysql.cpp.o): In function `HPHP::php_mysql_do_query_general(HPHP::String const&, HPHP::Variant const&, bool)':
ext_mysql.cpp:(.text+0x8100): undefined reference to `cli_safe_read'
ext_mysql.cpp:(.text+0x826a): undefined reference to `net_field_length'
ext_mysql.cpp:(.text+0x83a0): undefined reference to `cli_safe_read'
ext_mysql.cpp:(.text+0x8712): undefined reference to `free_root'
collect2: ld returned 1 exit status
make[2]: *** [src/hphp/hphp] Error 1
make[1]: *** [src/hphp/CMakeFiles/hphp.dir/all] Error 2
make: *** [all] Error 2

It seems like a problem with mysql version in the Fedora repo. I will download and build mysql and update this post.

Further Reading
https://github.com/facebook/hiphop-php/wiki/running-hiphop

References
https://github.com/facebook/hiphop-php
http://www.ioncannon.net/programming/918/building-hiphop-php-for-fedora-12-on-64-bit-and-32-bit-systems/
http://comments.gmane.org/gmane.comp.web.curl.library/29278

[HOWTO] Setup MySQL, Apache and PHP in Fedora 15

This is a simple guide to setup LAMP (Linux, Apache, MySQL and PHP). I am assuming you have Linux (Fedora 15) installed. The following commands will install the necessary packages to run Apache, MySQL and PHP.

su #for root login, enter password when prompted
yum install mysql-server
service mysqld start
mysqladmin -u root password PASSWORD_HERE
yum install phpmyadmin

Now, you should have necessary packages installed.
To run the apache and mysql services, enter the following in command prompt. This should be done each time you need to use unless you want those services to start with your OS.

su #for root login, enter password when prompted
service mysqld restart
service httpd restart

The directory where you can put in your files is /var/www/html/ and you can access phpMyAdmin by navigating to http://localhost/phpmyadmin

If you want the services to start with your OS, you will need to run the following:

su #for root login, enter password when prompted
chkconfig --add httpd
chkconfig httpd on
chkconfig --add mysqld
chkconfig mysqld on

Hope this helps.

[HOWTO] Setup step debugging PHP in Netbeans on Windows with XAMPP

I am using Netbeans 6.9.1 on Windows 7 with XAMPP 1.7.4 installed. I wanted to enable step debugging for PHP like I do in my PC with Fedora (see here for Netbeans PHP step debugging for Fedora). To do that, I had to follow the following steps:

Edit the php.ini file (xampp\php\php.ini) in a text editor to uncomment (remove leading semicolon 😉 the following lines:

zend_extension = "D:\xampp\php\ext\php_xdebug.dll"
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "localhost"
xdebug.remote_port = 9000

Also, search for the line containing “xdebug.remote_enable” and change it to:

xdebug.remote_enable = On

Then restart apache service.

Now, open the file Program Files\NetBeans 6.9.1\etc\netbeans.conf and find the line containing “netbeans_default_options”. Add the text “-J-Dorg.netbeans.modules.php.dbgp.level=400” at the end of the line so that it looks like the following:

netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dorg.netbeans.modules.php.dbgp.level=400"

Now, restart Netbeans and select Debug>Debug Project. However, I have experienced it is very slow on Windows compared to the installation on Fedora.

Hope this helps.

[HOWTO] Insert widget inside content of CJuiTabs widget in Yii Framework

UPDATE: See the comment from “Mario De Weerd” below. Although it works in the same way, his technique seems more elegant.

I am using Yii PHP Framework 1.1.7 for developing a site. I needed to insert EColorPicker widget inside the content of a tab in CJuiTabs. If $this->widget returned the generated string for embedding a widget, I could use the following code to achieve this:

echo $this->widget('zii.widgets.jui.CJuiTabs', array(
        'tabs' => array(
            'Size' => array('ajax' => array('sizeselection')),
            'Background' => array('content' => $this->widget('application.extensions.colorpicker.EColorPicker',
              array(
                    'name'=>'cp',
                    'mode'=>'textfield',
                    'fade' => false,
                    'slide' => false,
                    'curtain' => true,
                   )
             );),
            //'Colors' => array('ajax' => array('colorselection')),
            'Text' => array('ajax' => array('textselection')),
        ),
        // additional javascript options for the tabs plugin
        'options' => array(
            'collapsible' => true,
        ),
    ));

However, since $this->widget() does not return the string and echoes it instead, I had to do the following to achieve this:

ob_start();
$this->widget('application.extensions.colorpicker.EColorPicker',
              array(
                    'name'=>'cp',
                    'mode'=>'textfield',
                    'fade' => false,
                    'slide' => false,
                    'curtain' => true,
                   )
             );
$colorPicker = ob_get_contents();
ob_end_clean();
    $this->widget('zii.widgets.jui.CJuiTabs', array(
        'tabs' => array(
            'Size' => array('ajax' => array('sizeselection')),
            'Background' => array('content' => $colorPicker),
            //'Colors' => array('ajax' => array('colorselection')),
            'Text' => array('ajax' => array('textselection')),
        ),
        // additional javascript options for the tabs plugin
        'options' => array(
            'collapsible' => true,
        ),
    ));

I don’t know if it is appropriate to use it like this, but in my case this worked fine.

Hope this helps.

[SOLVED] Warning: imagettftext() [function.imagettftext]: Invalid font filename in path\to\php\file.php on line NN

I am running XAMPP 1.7.4 with PHP 5.3.5 on Windows 7. When using any text related GD library functions such as imagettftext(), I get the following error:

[SOLVED] Warning: imagettftext() [function.imagettftext]: Invalid font filename in path/to/php/file.php on line NN

Normally, this happens when the font is missing in GDFONTPATH and can usually be resolved by using correct font folder, using correct font file and naming it properly in the PHP file. However, in this particular case, I’ve figured that this is the problem with GD Library or PHP because I am still getting the error even though I have done everything right. I tried WAMP but still in vain. When I tried the same in my Linux machine, everything was fine.

Here is what I did as a workaround. I removed the putenv line and referred to fonts by relative path. For example, the following sample code is the one that does not work

putenv('GDFONTPATH=' . realPath('fonts'));
$font="ariali";
imagettftext($image, $size, $angle, $xcordinate, $ycordinate, $text_color, $font, $text);

I have assumed that the fonts folder contains a file ariali.ttf and in that case, the code must have worked. However, it does not, so the workaround is to do the following:

//putenv('GDFONTPATH=' . realPath('fonts')); remove this line
$font="fonts/ariali.ttf"; //use relative path here instead
imagettftext($image, $size, $angle, $xcordinate, $ycordinate, $text_color, $font, $text);

The above code works and I guess this is how I will have to use fonts in PHP from now on.

[SOLVED] “417 – Expectation Failed” in PHP curl while submitting multi-part forms

I am using PHP Curl extension for a project which requires uploading file to a server I had no control over. However, I was getting HTTP Status 417 with error message Expectation Failed. I don’t know what this is supposed to do and why curl sends it, so I tried removing it by overriding it with the following code:

curl_setopt($curl,CURLOPT_HTTPHEADER,array("Expect:  "));

It worked and the file uploaded successfully.

Hope this helps.

[SOLVED] Selenium server not working in Netbeans 6.9.1

I am using Fedora Core 14 and have installed Selenium Module for PHP. I was not able to run PHPUnit tests on Yii Framework. I tried running Selenium server 1.0.1 and upgrade to 1.0.3 solved the problem.

I downloaded the Selenium Remote Control from here and extract the file selenium-server.jar, renamed it to selenium-server-1.0.1.jar and placed it in /home/myusername/.netbeans/6.9/modules/ext/selenium overwriting the old jar. Then I restarted Netbeans. Now, testing works.

Hope this helps.

PHP Error while running newly created Yii Application

If you are using PHP 5.3 and have created a new Yii! Framework 1.1 application, you will get the following error:

date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Your/Timezone' for 'Timezone Info' instead 

To get around this, just open up index.php of your application and in the first line, add the following:

date_default_timezone_set('Timezone/String');

You should replace the ‘Timezone/String’ with your timezone information. Since my timezone is Asia/Kathmandu, I used:

date_default_timezone_set('Asia/Kathmandu');

Hope this helps.

[HOWTO] Install Selenium Module for PHP in Netbeans 7.0 beta

If you are using Netbeans 7.0 beta, the plugin list may not show Selenium Module for PHP. To install it, navigate to Tools>Plugins>Settings and click on Add. Then, in the name field, enter something like “Netbeans 6.9 beta” and in the URL field, enter the following URL:

http://updates.netbeans.org/netbeans/updates/6.9/uc/final/beta/catalog.xml.gz

Now, reload the cataloge and you should be able to install Selenium Module for PHP.

Happy developing.