Archive | Technical RSS feed for this section

Installing LAMP on Ubuntu

6 Sep

So I been getting rather annoyed with CentOs recently, mainly due to the lack of PHP support above 5.1.6, especially with all the cool features of 5.3. Also I always seem to have massive trouble installing anything like Mcypt or Memcache.

So I thought I’d give Ubuntu a go and I’m now a convert! Everything went smoothly, not one issue or problem. The support forums are brilliant and almost all questions have already been answered. I dont know whether I’ve just got lucky (I guess only time will tell) but Ubuntu is now my first port of call when setting up a new server.

Below is a line by line tutorial on how I got setup with Ubuntu 10.04 Lucid. I don’t go into too much details on how to edit the files using nano or vi but you can have a look on my previous posts or online, otherwise you can sftp in using root and change the files that way, (my preferred method).

Install Lamp on Ubuntu

sudo tasksel install lamp-server
You will need to enter a root mysql password for mysql

Change Apache Default Web Location on Ubuntu

If you need to change the default root location from /var/www to something else you can do so in the following file location. This is useful for using frameworks such as Zend Framework.

/etc/apache2/sites-available/default

Create file and add Fully Qualified Domain Name to Apache config (auto adds all in conf.d)

Create a new file call fqdn in:

/etc/apache2/conf.d/

In the top of the file write the following where mydomain.com is the domain name pointing to this server.

servername mydomain.com

Enable mod_rewrite on Ubuntu

a2enmod rewrite

Edit “AllowOverride None” for default site (usually the first 2 found on line 4 and line 10). Change to the following

AllowOverride All

Found in:

/etc/apache2/sites-available/default

Disable Directory Listing on Ubuntu

Inside: /etc/apache2/sites-available/default
Add "-" before the word Indexes

Options -Indexes

Restart Apache on Ubuntu

sudo /etc/init.d/apache2 restart

Install Memcached on Ubuntu

apt-get install memcached
apt-get install php5-memcache

Install Mcrypt on Ubuntu

sudo apt-get install php5-mcrypt

Install APC on Ubuntu

apt-get install php-apc
/etc/init.d/apache2 restart

When you get erros you need to type

apt-get install re2c
apt-get install gawk

Restart Apache

sudo /etc/init.d/apache2 restart

Other Useful Info on Ubuntu

PHP.ini Location in Ubuntu

/etc/php5/apache2/php.ini

Installing Memcached on Centos 5

31 Aug

The following post is a tutorial on how to install memcached and memcache php extension on Centos 5. Before you start there are a few useful points that might come in handing if you come across any errors.

php.ini file is kept in

/etc/php.ini

To find out where your php.ini file is kept you can type the following command

php -i | grep php.ini

The default extensions loaded are kept in this folder

/etc/php.d/

The actual php extensions are kept in

/usr/lib64/php/modules/

Install Memcached

Enable the following repository.

For i386 / i686

rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm

For x86_64

rpm -Uhv http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS//rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm

Use the command Yum to install memcached

yum -y install memcached

If no error popup then you have successfully installed memcache. You should then configure memcache by typing the following command.

vi /etc/sysconfig/memcached

you should see:

PORT="11211"    #define on which port to urn
USER="nobody"   #same as apache user
MAXCONN="1024"  #maximum number of connections allowed
CACHESIZE="64"   #memory used for caching
OPTIONS=""   #use for any custom options

Start memcached

/etc/init.d/memcached start

Check it running

/etc/init.d/memcached status

or

netstat -anp | grep 11211

To stop / restart memcache

service memcached stop
service memcached restart

To See Memory Memcached Slabs

 memcached-tool IP_ADDRESS:Port
 memcached-tool IP_ADDRESS:Port display
 memcached-tool 127.0.0.1:11211

To See Memory Memcached Stats

 memcached-tool IP_Address:Port stats
 memcached-tool 127.0.0.1:11211 stats

Install Memcache PHP Extension

Download and install lastest memcache version.

cd /usr/src
wget http://pecl.php.net/get/memcache-2.2.5.tgz
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5
phpize
./configure
make
make install

“configure: error: no acceptable C compiler found in $PATH”

If for some reason the above code errors saying something like you do not have a compiler installed run the following command.

yum install gcc

Add memcache extension to php.ini file (depending on your version of PHP you may not need this step)

vi /etc/php.ini

Press the key => i

Scroll don until you see a large block of code saying extension = …. Then add the following

extension = "memcache.so"

To check memcache is correctly installed with php

php -i | grep memcache

Finally Restart Apache

/etc/init.d/apache2 restart

Special Thanks

This post would not have been possible without the follow tutorials and articles. I highly recommend you check them out as they list different techniques and include other information like how to start memcache as a service.


http://www.cyberciti.biz/faq/rhel-fedora-linux-install-memcached-caching-system-rpm/

http://codelikezell.com/how-to-install-memcached-on-centos/

http://www.lullabot.com/articles/installing-memcached-redhat-or-centos

http://www.sohailriaz.com/how-to-install-memcached-with-memcache-php-extension-on-centos-5x/

How to install Memcached on Xampp on Windows 7

26 Aug

For one of my Zend Framework web applications I’m going to install memcached. I am currently using file cache however think memcached is a much better way to go. This post is one in a series:

  1. Installing Memcached on Windows 7 and Xampp
  2. Setting up Memcached Cache in Zend Framework
  3. Installing Memcached on Centos 5.

Installing Memcached on Xampp and Windows 7

1a. Go to your php.ini file usually located in C:/xampp/php/php.ini
find this line:

;extension=php_memcache.dll

and replace it with:

extension=php_memcache.dll

1b. If you cannot find this line simply add the following line to below where all the ;extension= lines.

extension=php_memcache.dll

2.  Add the following to just below the new line

[Memcache]
memcache.allow_failover = 1
memcache.max_failover_attempts=20
memcache.chunk_size =8192
memcache.default_port = 11211

3. Download the necessary php_memecache.dll file from the following location.


http://downloads.php.net/pierre/

For windows 7 I used the following file:


http://downloads.php.net/pierre/php_memcache-cvs-20090703-5.3-VC6-x86.zip

4. Unzip the php_memcache.dll file and put it into your php ext folder. Usually C:/xampp/php/ext/

5. Download memcached for windows here (make sure it’s the win32 binary):


http://code.jellycan.com/memcached/

6. Unzip and put the memcache.exe file into a desired directory (e.g. c:/memcached/)

7. Open command line in Windows Administrator Mode.

Click start, type in ‘Search programs and Files’ box, wait for the program cmd.exe to appear, right hand click on the icon and select run as administrator

8. Install the memcache service

Type the following into the command line

c:\memcached\memcached.exe -d install

If you dont get any errors it means it’s worked.

9. Start memcached

Type the following into the command line

c:\memcached\memcached.exe -d start, or net start “memcached Server”

10. Restart Xampp Apache

11. Test Memcache

Create a php file and paste the following code. Then go to the page. If you do not see any errors then it has worked.

<?php
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");

$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";

$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;

$memcache->set('key', $tmp_object, false, 10) or 
die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)
<br/>\n";

$get_result = $memcache->get('key');
echo "Data from the cache:<br/>\n";

var_dump($get_result);
?>

12. Just in case it doesn’t work: One other thing I did was to run the C:/memcached/memcached.exe file as administrator. This opens the ports on the windows firewall which might solve some problems.

Enable mod_rewrite in xampp

25 Aug

For some reason my install of XAMPP didn’t have mod_rewrite automatically enabled? Not really sure why  but basically below are the instructions on how to enable .htaccess mod_rewrite in xampp.

1. Go to the directory of installation <C:\xampp>\apache\conf

2. Open and edit httpd.conf in a text editor

3. Find the line which contains

#LoadModule rewrite_module modules/mod_rewrite.so

and (uncomment) change to

LoadModule rewrite_module modules/mod_rewrite.so

4. Find all occurrences of

AllowOverride None

and change to

AllowOverride All

I think it appears 2 or 3 times on the configuration file.

5. Restart xampp

That’s it you should be good to go.

PHP Soap Server Error – Procedure not present

7 Jul

I’m currently building a soap service using zend framework. I am developing on a local windows envirment using xampp. When adding a new method to the web service class I was able to call it locally and everything worked a treat, however as soon as I uploaded it to the Centos box it broke with the following error:

"Procedure 'xxx' not present"

Error would look more or less like this:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring>Procedure 'gettwotandomitems' not present</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Basically PHP is caching the generated WSDL file and you need to delete the cache. All of the cached files for me where kept in /tmp however you can double check by looking in the phpinfo() file.

To fix that problem delete all of the cahced files, then try the soap call again and everything should work fine.

Hope it helps.

Credit goes to: http://artur.ejsmont.org/blog/content/php-soap-error-procedure-xxx-not-present