MYSQL, PHP and Apache DOs and DON’Ts
May 2nd, 2009 // 10:30 pm @ Arad Gharagozli
There are many obstacles on developer’s way when they are trying to setup their Apace and PHP for the first time, I know there are couple dozen articles about this basic setup but this article is not about setting up PHP and Apache but its highlighting couple hidden tricks that usually comes to a problem.
1– Windows Environment Variable Setting:
PHP is a service for Apache but never forget that it HAS to be added into your platform’s Environment variables, For adding a PHP into the OS E.V you just need to find the patch the you installed or Unzipped your PHP package into, I have this patch in my server “C:\server\PHP”, so
if I browse this rout I should find the file “PHP.ini” in it. Copy the whole link and go to
Environment Variable section {Start/ Right click On my computer/ Properties / Advanced tab /
and finally click on Environment Variable}. In System Variable section, locate “Path” and click
Edit. You should see a long list of paths, find the last Variable Value and add a “;” to the end and
paste your PHP path that we copied before after it. We added PHP to our Environment variables now.
Note: To make sure that we did everything right add a “\” to the end of the path
Example: “C:\Program Files\Windows Imaging\;C:\Program
Files\NetManage\Windows;C:\server\php\”
2– SMTP Setting:
If you are trying to send e-mail through your PHP service you need to enable SMTP service in the PHP.INI file. Go to your PHP directory and find PHP config file, scroll down about the half of the page, (Or use search function for “SMTP”), look for *mail function+ section, but please note that
this section is ONLY available if you download the ZIP package from PHP website, I personally found too many missing services in MSI (Windows installer) version in PHP module’s folder and php.ini’s module control sections, like this SMTP function, so if you don’t see this section I
recommend you to download the ZIP package and use the php.ini in that package, you even can
see the difference in the weight on the file, there is at least ~25 KB difference, that is too much for a text file.
Ok let’s back to our configuration, first bar is how PHP has preconfigured the SMTP service and
2nd one should be the way that setting has to be.
NOTE: these setting are applicable only for Win32 platform; you can look up my Linux article to find out more.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Figure-1
[mail function]
; For Win32 only.
;SMTP = /*/
;smtp_port = 25
; For Win32 only.
;sendmail_from = me@example.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Figure-2
[mail function]
; For Win32 only.
SMTP = admiral89.arad.com smtp_port = 25
; For Win32 only.
sendmail_from = no_reply@arad.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So if look closer we can see the differences between the first bar and the 2nd one, first of all
remove 3 semicolons “;” before SMTP, smtp_port and Sendmail_from.
NOTE: some users ignore the “Sendmail_from” part, but keep this mind PHP needs this function
to be available as an “Identification method”, I know it doesn’t sound right because you can use
any address you want but it has to be something, some older versions of PHP would go with that
but in recent versions specially 5.3.2 it’s better if you specify an address.
SMTP: Ok now we specified to PHP that witch option has to be enabled, now it’s time to direct
PHP to our SMTP server, in the SMTP section type your SMTP Server address,
NOTE: I use a local network with exchange servers and SMTP servers but 80% of users don’t
have this option and they use dedicated servers and or hosting companies, if you are from the
2nd group, you usually have 2 options use “localhost” that most hosting companies will allow that if not ask your hosting company about the SMTP server address, however 99.99% of the time this function is already configured in your php.ini file when you buy hosting plans. (If you
use Cpanel you can check this in the PHP Configuration section to make sure).
Smtp_port: after setting up our SMTP destination we need to specify the port to SMTP server
the default port for SMTP is 25 and it’s usually available unless you ISS policy is different, then
you need to get a hold of your network administrator.
Thanks for reading this article and I hope you all enjoyed it.
Arad