Search This Blog

Friday, February 19, 2010

how to enable xmlwriter in php

By install php-xml, you may enable it.
[root@localhost html]# yum install php-xml

check:
[root@localhost html]# php -m
[PHP Modules]
bz2
calendar
ctype
curl
date
dbase
dom
exif
ftp
gettext
gmp
hash
iconv
libxml
mime_magic
mysql
mysqli
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
posix
pspell
Reflection
session
shmop
SimpleXML
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
zlib

how to redirect root to a specified path?

I want to redirect all incoming traffic from http://www.example.com https://www.example.com
to https://www.example.com/new

Step 1: enable overwrite in httpd.conf



    Options FollowSymLinks
    #AllowOverride None
    AllowOverride all


Step 2, generate .htaccess under root /




[root@localhost html]# pwd
vim /var/www/html/.htaccess




RewriteEngine On
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(/)?$  https://www.example.com/new/$1 [R,L]

error message - RewriteEngine not allowed here

If you try to redirect your root to a folder and got this error msg
for example:
redirect www.example.com/  www.example.com/new/

You may update https.conf


    Options FollowSymLinks
    #AllowOverride None
    AllowOverride all



mysql create use with read privilege

mysql> CREATE USER 'alice'@'localhost' IDENTIFIED BY 'passw0rd';
Query OK, 0 rows affected (0.07 sec)

mysql> GRANT SELECT ON mydb.* TO 'alice'@'localhost';
Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

How to Password Protect a Directory on Your Website - linux apache

This is for linux apache only, if you use windows, iis, it doesn't  apply your case.

There are two way you can do it.
1, update httpd.conf file.
For example, if you want to protect download folder and your www path is /var/www/html/,
you can add following code into httpd.conf file:


=================================

  AuthType Basic
  AuthName "Restricted Files"
  AuthUserFile /var/password/downloadpassword
  Require valid-user

=================================


You need to use htpasswd command to generate a downloadpassword file

htpasswd -c downloadpassword   greg



After change the file, need to restart the httpd service.

/etc/init.d/httpd restart

You need to restart apache service after you update httpd.conf file every time. Sometimes, it is not easy to restart the service. So, you may use the other way - .htaccess file

2, use .htaccess
If you want to protect this folder /var/www/html/download
create a file .htaccess

vim .htaccess

AuthType Basic
AuthName "Password Required"
AuthUserFile /var/password/downloadpassword
Require valid-user
Options +Indexes


You need to use htpasswd command to generate a downloadpassword file

htpasswd -c downloadpassword   greg


No need to restart httpd service.

Some security hints
1, you should put the password in a different folder, not www public folder
2, if you have to put password file in the same folder, name it with dot ., like .htmypasswd.







htaccess password not working

Make sure Apache is configured to use .htaccess file

Here is the /etc/httpd/conf/httpd.conf
=============================

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride AuthConfig

#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all





===============================
After save the file, restart apache httpd service:
[root@localhost try]# /etc/init.d/httpd restart