Showing posts with label apache. Show all posts
Showing posts with label apache. Show all posts

2011/09/30

PHP mail does not work

The OS is linux, and the webserver is apache, and in php.ini file the mail is set as 'sendmail_path = /usr/sbin/sendmail -t -i'. The problem is that php mail() function does not work, although it returns 1 like it's successful. In this case you will not find any help by looking into apache error log. The debugging should start from maillog, which is located at /var/log/ if you are not specify the different loction in the php.ini. I saw the errors like,
delay=00:00:06, xdelay=00:00:02, mailer=relay, pri=120481, relay=*****, dsn=4.5.0, stat=Operating system error
sendmail[24572]: ruleset=try_tls, arg1=mail.***.com, relay=mail.***.com, reject=451 4.3.0 Temporary system failure. Please try again later.
which is actually hard to tell what's going on. I actually tested it mail function thru command line. Accidentally I found if I am root, I was able to send the mail. And I dig more into mail log, I found some useful error logs (note that those logs were generated by the test through url, not command line), like
sendmail[24572]: p8S0pDSY024569: SYSERR(apache): db_map_open: cannot pre-open database /etc/mail/access.db: Permission denied
So then the issue is clear. I checked the /etc/mail/access.db, the mod was 640, so changed to 644, and it sloved the problem.

2009/03/20

Some https conf for sercurity

#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of:  On | Off | EMail
#
ServerSignature Off
#Fri Mar 20 09:19:57 EDT 2009: per OReilly
ServerTokens ProductOnly

#
# Timeout: The number of seconds before receives and sends time out.
#
#Fri Mar 20 09:12:45 EDT 2009: Timeout 180  (reduced  per O'Reilly recommendation for DOS protection)
Timeout 60

2009/03/03

Apache built-in funtion, server-status

There is mod_status built into Apache web server to get server status from web browser. With this module you can easily find out how well your server is performing.
You can turn in on in httpd.conf file, like below,
<Location /server-status>
    SetHandler server-status
    AuthType Basic
    AuthName "Admin Area"
    AuthUserFile /var/www/passwd/passwords
    Require user admin
    Order deny,allow
    Deny from all
    Allow from 172.16
    Satisfy any
</Location>
All reports are generated in a html format. You can easily find out following type of information:
   1. Total number of worker serving requests
   2. Total number of of idle worker
   3. Find the status of each worker, the number of requests that worker has performed and the total number of bytes served by the worker
   4. Total number byte count served
   5. Other information such as CPU usage, number of requests per second,current hosts and requests being processed etc.
For example, you may see 1&2 like below,
233 requests currently being processed, 13 idle workers
Here, 233 is simultaneously running requests, which cannot access the maximum number you set up. Depend on how busy your server is, you may make this number bigger. The default number is 256.
Usually, you can set this in your http.conf file, like below,
<IfModule prefork.c>
StartServers       8
MinSpareServers    5
MaxSpareServers   20
ServerLimit      512
MaxClients       512
MaxRequestsPerChild  4000
</IfModule>

2006/09/06

Enable SSI

Enable SSI (Server Side Includes) by edit httpd.conf.

1. Add folowing code:

<Location />
AddType text/html .shtml
AddHandler server-parsed .shtml
Options Indexes FollowSymLinks Includes
</Location/>


2. restart Apache:

apachectl graceful

2006/08/21

Set up public_html and CGI

By default, http://exaple.com will be translated to the file path '/var/www/index.html' or default apache page if index.html does not exist. Also, all files in ‘/var/www/cgi-bin’ will be reconginzed as being eligible for execution rather than process as normal document, no matter the file name (in the other word, the file can be ‘anyname.anyexten’).

Of course, the ordinary user can also have 'http' and 'cgi' supported. Just follow the below steps:

Prerequisites:
1. You must have ‘root’ privilege
2. Apache has been installed and started, in my machine I use following commands to check

/usr/sbin/httpd status (check the Apache status)
/usr/sbin/httpd –h (help file of httpd command)


Step one: create public_html and cgi-bin at a user’s home directory, change mods to 755

Step two: edit server configuration file, in my machine it is ‘/etc/httpd/conf/httpd.conf’

vi /etc/httpd/conf/httpd.conf

a. Set the file path with UserDir

UserDir public_html

b. Enable a cgi directory for a user

<Directory /home/*/public_html/cgi-bin/>
Options ExecCGI
SetHandler cgi-script
</Directory>

You can see http://httpd.apache.org/docs/2.0/howto/public_html.html for detail.

IMPORTANT:
You need to restart Apache to invoke the change. I use below command:

/usr/sbin/httpd - k restart

NOTE:
1. Every file in cgi-bin will be executed as a script, every file in public_html will be executed as normal documents
2. Don’t need to change other perameter in httpd.conf, which you may think need to be changed, such as ‘AddHandler cgi-script .cgi’, ect. I will explain how to use them in next.

OK! Now it is the time to write a simple html file, for example index.html, in public_html, and write a simple cig/perl file in cgi-bin you created before. Set permission of those files to 755. You should be able to run them from browser.

You may want to run script everywhere instead of the scripts in cgi-bin. You can do this by following steps:

Step one: edit server configuration file.

vi /etc/httpd/conf/httpd.conf

Add a line, or just move the ‘#”,

Addhandler cgi-script .cgi .pl

.cgi and .pl means the file with those extention will be executed as script

Step two: search for the line that says "<directory>" in the file. It should look something like this:

<Directory>
Options FollowSymLinks
AllowOverride None
<Directory/>


Add "+ExecCGI" to the options list. The line now looks like this:

Options FollowSymLinks +ExecCGI

Note:
1. You need to restart Apache to invoke the change.
2. Doing this does not affect the file in cgi-bin. In the other word, every file in cgi-bin is still treated as scripts no matter what file extension.
3. When you find the problem, you can check the error logs by

cat /var/log/httpd/error_log