Showing posts with label server. Show all posts
Showing posts with label server. Show all posts

Jan 4, 2011

How To Install PHP on IIS 6.0

4thSeptember2007

How To Install PHP on IIS 6.0

posted in IIS 6.0PHP |
I recently decided to experiment with hosting my own blog and after looking at the various packages available decided that I wanted to use WordPress. However, when it came to installing WordPress, I found that there was a lack of really good documentation available if you wanted to use IIS 6.0 as your web server. I also found quite a bit of contradictory information regarding the installation of PHP and MySQL on Windows 2003 - so I decided to write my own. This is the first of a series of articles which will provide a complete walkthrough enabling you to install PHP, MySQL and WordPress on an IIS 6.0 web server.
At the time of writing, the latest stable version of PHP is 5.1.4. Start by downloading the zip package and the Collection of PECL modules from here :http://www.php.net/downloads.php
#Note: You can use the Windows Installer package but it only installs and configures the CGI version of PHP which is not the best solution for an IIS web server; you should try to use the ISAPI version - if you really want to know more about why this ISAPI is preferable to CGI then I suggest you watch this IIS webcast :
TechNet Webcast: Comparing CGI and ISAPI in IIS 6.0 - Level 300
Install and Configure PHP
Start by creating a directory into which you will extract the downloaded PHP files (php-5.1.4-Win32.zip). In this example I’m going to use C:\PHP as my installation directory. Then extract the files from php-5.1.4-Win32.zip into C:\PHP
If you need to use the additional PECL modules then extract the files from ‘pecl-5.1.4-Win32.zip’ into the C:\PHP\ext directory.
Fig. 1
Next locate the file ‘php.ini-recommended’ in C:\PHP and rename it to ‘php.ini’ (without the quotes of course)
Fig. 2
Open the ‘php.ini’ file and find the line which reads extension_dir = “./” and change it to extension_dir = “C:\PHP\ext”. This tells PHP where the various extensions are located and as you can see the default path in the ‘php.ini-recommended’ file which ships with PHP points to the wrong location, so you need to change it.
You also need to add the location of your PHP directory to the server’s PATH environment variable so that Windows knows where to look for any PHP related executables (such as the PHP extension DLL‘s). To do this Right-click on My Computer, click Properties and on the Advanced tab click Environment Variables. In the Environment Variables dialog box, under System variables highlight the Path variable and click Edit.
Fig. 3
Add ‘;C:\PHP’ (be sure to include the semi-colon separator) as shown here and click OK. You need to re-boot the server for this change to take effect.
Fig. 4
If you browse through the ‘php.ini’ file you will see an entry describing the ‘cgi.force_redirect’ property. You will also see a statement telling you that if you are using IIS you ‘MUST’ turn this off. However, this only applies if you are using the CGI version of PHP (i.e. php-cgi.exe) Since we are using the ISAPI version of PHP we can safely ignore this - more details here : http://www.php.net/release_4_1_2_win32.php
You may have also seen various IIS and PHP HowTo guides which suggest that you need to copy your ‘php.ini’ and some other PHP related files to the C:\Windows\System32 directory - this is not actually necessary, as I shall demonstrate later in this walkthrough.

Jul 13, 2010

Uploading Photos on server with PHP

I have tried to upload pictures on my site. For that I have created one small class in PHP. I keep the name of the picture after that is uploaded. And, also, the extension. But, I transform the extension from uppercase (eg. .JPG will be .jpg).


Bellow you'll find my class. In this class I have used on small function (getextension) which I have find on the internet.

class Galerie {

function aa(){
echo 'aa';
}

function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
} //function getExtension()



function foto_upload(){
//incarcare poza pentru galeria foto
$locatie = "galerie";

$categorie = $_POST['categorie'];
$descriere = $_POST['descriere'];

//get the original name of the file from the clients machine
$filename = stripslashes($_FILES['poza']['name']);
//get the extension of the file in a lower case format
$extension = strtolower($this->getExtension($filename));
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
//print error message
$mesaj = $mesaj."
Fisierul imagine trebuie sa fie .jpg, sau .gif, sau .png
";
} else {
$numefisier = explode(".".$extension, $filename);
$numeimagine = $numefisier[0];
$newname = "../uploads/".$locatie."/".$numeimagine.".".$extension;

$copied = copy($_FILES['poza']['tmp_name'], $newname);
$fisier = $numeimagine . "." . $extension;
//echo $copied;

if(!$copied){
$mesaj = $mesaj."

Fisierul ".$fisier." nu a fost urcat pe server!";
//$imagine = "";
} else {
//salvez numele fisierului in baza de date

//mai intai calculez maximul de pozitii
if($pozitia == 0) {
$sPoz = "SELECT MAX(pozitia) AS M FROM imagini_galerie";
$rPoz = mysql_fetch_array(mysql_query($sPoz));
$pozitia = 1 + $rPoz['M']; //noua pozitie
//echo $sPoz."
".mysql_error();
}
$sql_fisier = "INSERT INTO imagini_galerie(photo, categorie, descriere, pozitia)
VALUES('".$fisier."', '" . $categorie . "', '" . $descriere . "', $pozitia)";
$rez_fisier = mysql_query($sql_fisier);

if($rez_fisier) {
echo "
Imaginea a fost incarcata!
";
//header('Location:?p=galerie');

//echo "

 

 

 

 

 

 

";
} else {
echo $sql_fisier;
echo "

 

";
echo "
Eroare la incarcarea imaginii!
";
}
} //if $copied
}

}//function foto_upload()





function foto_del($id){
//sterge imaginea din galerie
$id=(integer)$id;
$sql = "SELECT * FROM imagini_galerie WHERE id=$id";
$rnd = mysql_fetch_array(mysql_query($sql));
unlink('../uploads/galerie/'.$rnd['photo']);

$sqlSterg = "DELETE FROM imagini_galerie WHERE id=$id";
mysql_query($sqlSterg);
} //end foto_del()





} //end class Galerie