Category Archives: Wamp

Install PostgreSQL and phpPgAdmin in Windows with Wamp

All the PHP developers out here, who use Windows is familiar with WAMP. I the WAMP stack we get a lot of packages like sqlbuddy and phpmyadmin. But a project came to me that uses PostgreSQL. So I had to install PostgreSQL in Wamp. Well it was a tricky job to do. At last I did it. So today in this topic I am going to share this with the developers who need to use PostgreSQL in Windows and Wamp.

In this article I am going to use,

  1. WampServer 2.1. Download it from Here.
  2. PostgreSQL 9.1. Download it from Here.
  3. phpPgAdmin 5.0.2. Download it from Here.

It is assumed that, you have installed the WampServer already. Now, let us proceed with the new Installations.

  1. First, install the PostgreSQL. It is a simple installation procedure. Just click Next Until, when you come to the screen where you give the installation directory. Make it to your suitable directory. I installed it in “C:wampappsPostgreSQL”. Then provide the Data path according to “C:wampappsPostgreSQL9.1data”.
  2. Then you will be presented a Password Screen where you can give the main login password. I have made it as “root“.
  3. Then in the next screen you will be prompted with the Port number. Make sure it does not conflict with the MySQL port 3306. So I used the default as 5432.
  4. Set the Locale as the Default Locale.
  5. Now click on Next and it will start the installation.
  6. Next click on Finish. And we are done with the installations.
  7. Check installation of PostgreSQL by clicking Start ->Programs ->PostgreSQL 9.1 ->PgAdmin III.
  8. Click on Server(1) and Right Click on PostgreSQL Database Server 9.1 (localhost:5432) and Select Connect to obtain a connection to server and give password. It will connect to Database server.
  9. Now it is time to bridge PHP to it. So Go on the task bar and Left Click on the Wamp Tray icon. Navigate to PHP > PHP extension. Then enable,
    1. php_pgsql
    2. php_pdo_pgsql extension.
  10. Restart the Wampserver. This time you will probably see some errors saying like,
    1. PHP Warning:  PHP Startup: Unable to load dynamic library  ‘C:wampbinphpphp5.3.5extphp_pdo_pgsql.dll’ – The specified module could not be found.
    2. PHP Warning:  PHP Startup: Unable to load dynamic library ‘C:wampbinphpphp5.3.5extphp_pgsql.dll’ – The specified module could not be found.
  11. To eleminate them you need to copy libpq.dll from wampbinphpphp5.3.5 to  wampbinapacheApache2.2.17bin. Again restart the Wamp Server. By now we are done with the php configuration. Next we will install phpPgAdmin and use it.
  12. So download phpPgAdmin and copy it in C:wampapps assuming, Wampserver is in C Drive. So the path will be, C:wampappsphpPgAdmin-5.0.2.
  13. To make a shortcut in Wamp Index page in the Your Aliases section create a file called, phppgadmin.conf in C:wampalias. And copy paste the following,
    Alias /phppgadmin "C:/wamp/apps/phpPgAdmin-5.0.2/" 
    
    <Directory "C:/wamp/apps/phpPgAdmin-5.0.2/">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
            Order Deny,Allow
    	Allow from all
    </Directory>
  14. Restart the Wamp server and go to http://localhost/. You will see a link came under Your Aliases  as phppgadmin. Click on that link and you will see the following screen.
    Login phppgadmin
  15. Then click on the PostgreSQL link on the left hand side. You will be prompted for the username and the password. By default postgrey creates an user called postgres. So give it in the username field and give the password same as you have entered in the time of the installation. For me it is root.
    pgadmin login username and password
  16. Last we will see the following screen after successful login.
    phppgadmin database browser screen
  17. Last is is time to test a simple database connection PHP script. So to do that, create a database called test and create a php page with the following code in it.
    <?php
    $con="host=localhost port=5432 dbname=test user=postgres password=root";
    $db=pg_connect($con) or die('connection failed');
    echo 'Connected to: ', pg_dbname($db);
    ?>

    If it does not show any error, then we are good to go. We can use PostgreSQL.

  18. If you face any problem then you can write to me. I will try to solve the problem.

Step by Step Instructions to Assign Multiple Virtual Domain Names and Websites to Your Localhost

With the help of this tutorial you can assign a virtual domain name to your localhost.

You can access your local website with your favourite name like http://mysite.web instead of http://localhost and also you can assign different virtual domain names to different local webistes.

Requirements:

  • Apache webserver installed. It would be nice if you have WAMP server. This tutorial is based on WAMP server. But it works on any Apache server.

Procedure:

Part 1:

        1. First go to location “C:WINDOWSsystem32driversetc” directory.(or where you installed windows).
            Then open “hosts” file with simple text editor like notepad.        2. You’ll see “127.0.0.1 localhost”at the end of the file.In the next line add your virtual domain name like the example shown below.
Here mysite.web is just my example. You can use anything you like.
127.0.0.1    mysite.web              #this is virtual domain name.

3. Now save the hosts file. mysite.web is just an example. You can add anything like mywebsite.local and you can use any extension or no extension at all.
You can simply add mysite also.

        4. Now test your virtual domain. Just type “http://mysite.web&#8221; You must see your wamp page or webservers defalut page. If not go through the process again.

NOTE: Don’t use any real domain name like http://www.google.com or your own domain name if you have any. If you did so, you cannot that access the original remote site. This is because, 127.0.0.1 is loopback address, anything with that address will never leave your computer.

Part 2- Now some difficult part. Assigning this virtual domain name to your web site in your local server.

1. Open your httpd.conf file in conf directory of Apache webserver folder.

If you are using WAMP click on WAMP icon, go to Apache menu and select httpd.conf there.

edit-httpd-wamp-web-server-virtual-domain

2. Create a new folder mysite in your C:>. And create a new page index.html. These are for testing purposes.
If you have a local website, specify the full path of website in below code.

3. Now add the following code at the end of the httpd.conf file.

NOTE: PLEASE TYPE IN THE CODE MANUALLY without comments, DON’T COPY AND PASTE.

 NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
   ServerName localhost
   DocumentRoot "C:/wamp/www"                      #this is default wamp root for websites,
</VirtualHost>

<VirtualHost 127.0.0.1>
   ServerName mysite.web                           #your virtual domain name
   DocumentRoot "C:/mysite"                        #location of your site, no extenison needed.

<Directory C:/mysite>                              #again location of your website
   Order Allow,Deny
   Allow from all
 </Directory>
 </VirtualHost>

Save this file. Restart your WAMP server. Now type http://mysite.web You’ll see the index page of mysite.

If you want another website, first add another virtual domain in hosts file as shown in part1.

And then copy and paste the following code at the end of httpd.conf file. Just change the virtual domain name, and locations of website.

<VirtualHost 127.0.0.1>
   ServerName mywebsite.web               #change this virtual domain name
   DocumentRoot "C:/mywebsite"            #location of your site, change this.

   <Directory C:/mywebsite>               #again location of your website, change this
   Order Allow,Deny
   Allow from all
   </Directory>
 </VirtualHost>

You can add as many websites as you wish. Just repeat the above procedure. And access all your local websites with your favorite name. It will be fun and will save lot of your time.

WAMP Send Email

How do you send emails using plain PHP mail on WAMP on Windows?

Normally, PHP mail works by using Sendmail which is installed on *nixes, so it doesn’t work on a Windows box. However, normally we just rewrite our code to using a SMTP server, but what about when we really don’t want to – or can’t – modify third-party code?

You need WAMP Server installed (of course!) and http://glob.com.au/sendmail/

Now, we need to edit C:wampsendmailsendmail.ini:

[php]

smtp_server=smtp.gmail.com
smtp_port=465
auth_username=user@gmail.com
auth_password=your_password

[/php]

Now we need to edit php.ini and set sendmail_path:
[php]sendmail_path = "C:wampsendmailsendmail.exe -t"[/php]

Now, restart Apache, and that is basically all you need to do. Now we can’t wait to test if it works!
[php]
$to      = ‘some@email.here’;
$subject = ‘Fake sendmail test’;
$message = ‘If we can read this, it means that our fake Sendmail setup works!’;
$headers = ‘From: your@email.here’ . "rn" .
‘Reply-To: your@email.here’ . "rn" .
‘X-Mailer: PHP/’ . phpversion();

if(mail($to, $subject, $message, $headers)) {
echo ‘Email sent successfully!’;
} else {
die(‘Failure: Email was not sent!’);
}
[/php]