Tuesday, February 17, 2009

Installing LAMP (Linux,Apache,MySQL,PHP) on Suse 11 in the "pain in the ass" way

The acronym LAMP refers to a solution stack of software, usually free and open source software, used to run dynamic Web sites or servers. The original expansion is as follows:

*Linux, referring to the operating system;
*Apache, the Web server;
*MySQL or mSQL, the database management system (or database server);
*PHP or others, i.e., Perl, Python, the programming languages.
 
The combination of these technologies is used primarily to define a web server infrastructure, define a programming paradigm of developing software, and establish a software distribution package.Though the originators of these open source programs did not design them all to work specifically with eachother, the combination has become popular because of its low acquisition cost and because of the ubiquity of its components (which come bundled with most current Linux distributions). When used in combination they represent a solution stack of technologies that support application servers.
 
Enough for chit-chat, and move on to the "pain in the ass" part, download all three files below and get some coffee, you will need it.
 
wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.31.tar.gz/from/http://mysql.oss.eznetsols.org/
wget http://apache.cbn.net.id/httpd/httpd-2.2.11.tar.gz
wget http://id2.php.net/get/php-5.2.8.tar.gz/from/this/mirror
 
and then unpack the compression using this following command:
 
tar -zxvf mysql-5.1.31.tar.gz
tar -zxvf httpd-2.2.11.tar.gz
tar -zxvf php-5.2.8.tar.gz
 
after that enter the following directory:
 
/usr/local/src/php-4.4.6
/usr/local/src/apache_1.3.37
/usr/local/src/mysql-4.1.22
 
Installing MySQL
 
before installing mysql u must add a user that have privilege to run mysql
 
groupadd mysql
useradd -g mysql -c "MySQL Server" mysql

follow each of this command
 
cd /usr/local/src/mysql-5.1.31
chown -R root.root *
 
./configure \
--prefix=/usr/local/mysql \
--localstatedir=/usr/local/mysql/data \
--disable-maintainer-mode \
--with-mysqld-user=mysql \
--with-unix-socket-path=/tmp/mysql.sock \
--without-comment \
--without-debug \
--without-bench
 
make && make install

./scripts/mysql_install_db

chown -R root:mysql /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql/data

cp support-files/my-medium.cnf /etc/my.cnf
chown root:sys /etc/my.cnf
chmod 644 /etc/my.cnf

echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
ldconfig

 
this command below is about adding the mysql daemon to the rc.d folder
 
cp ./support-files/mysql.server /etc/rc.d/init.d/mysql
chmod +x /etc/rc.d/init.d/mysql
/sbin/chkconfig --level 3 mysql on

cd /usr/local/mysql/bin
for file in *; do ln -s /usr/local/mysql/bin/$file /usr/bin/$file; done

cd ~
/etc/rc.d/rc3.d/S90mysql start

/etc/rc.d/init.d/mysql start
/etc/rc.d/init.d/mysql stop
 
 
To run a quick test, use the command line program mysql:
 
mysql -u root -p
 
and enter your new root user password when prompted. You will then see the MySQL prompt:
 
mysql>
 
First, while we're in here, we'll take care of another security issue and delete the sample database test and all default accounts except for the MySQL root user. Enter each of these lines at the mysql> prompt:
 
drop database test;
use mysql;
delete from db;
delete from user where not (host="localhost" and user="root");
flush privileges;
 
As another security measure, I like to change the MySQL administrator account name from root to something harder to guess. This will make it that much harder for someone who gains shell access to your server to take control of MySQL.
 
MAKE SURE YOU REMEMBER THIS NEW NAME, AND USE IT WHEREVER
YOU SEE "root" IN OTHER DIRECTIONS, WEBSITES, ETC.
 
ONCE YOU DO THIS STEP, THE USERNAME "root" WILL CEASE TO
EXIST IN YOUR MYSQL CONFIGURATION!
 
update user set user="sqladmin" where user="root";
flush privileges;
 
Now, on with the "standard" testing... First, create a new database:
 
create database foo;
 
You should see the result:
 
Query OK, 1 row affected (0.04 sec)
mysql>
Delete the database:
drop database foo;
 
You should see the result:
 
Query OK, 0 rows affected (0.06 sec)
mysql>
To exit from mysql enter \q:
\q
 
Build and Install Apache (with DSO support)
 
The advantage to building Apache with support for dynamically loaded modules is that in the future, you can add functionality to your webserver by just compiling and installing modules, and restarting the webserver. If the features were compiled into Apache, you would need to rebuild Apache from scratchevery time you wanted to add or update a module (like PHP). Your Apache binary is also smaller, which means more efficient memory usage.
 
The downside to dynamic modules is a slight performance hit compared to having the modules compiled in.
 
cd /usr/local/src/httpd-2.2.11

./configure \
--prefix=/usr/local/apache \
--enable-shared=max \
--enable-module=rewrite \
--enable-module=so

make && make install

Build and Install PHP
 
This section has only been tested with PHP v4.x. If you are trying to build PHP 5.x, I do not have experience with this yet, and do not provide free
support for you to get it working. Please note that there are many options which can be selected when compiling PHP. Some will have library dependencies, meaning certain software may need to be already installed on your server before you start building PHP. You can use the command
 
./configure --help | less
 
once you change into the PHP source directory. This will show you a list of all possible configuration switches. For more information on what these switches are, please check the PHP website documentation.
 
cd /usr/local/src/httpd-2.2.11

./configure \
--with-apxs=/usr/local/apache/bin/apxs \
--disable-debug \
--enable-ftp \
--enable-inline-optimization \
--enable-magic-quotes \
--enable-mbstring \
--enable-mm=shared \
--enable-safe-mode \
--enable-track-vars \
--enable-trans-sid \
--enable-wddx=shared \
--enable-xml \
--with-dom \
--with-gd \
--with-gettext \
--with-mysql=/usr/local/mysql \
--with-regex=system \
--with-xml \
--with-zlib-dir=/usr/lib

make && make install

cp php.ini-dist /usr/local/lib/php.ini
 
I like to keep my config files all together in /etc. I set up a symbolic link like this:
 
ln -s /usr/local/lib/php.ini /etc/php.ini
 
Then I can just open /etc/php.ini in my editor to make changes. Recommended reading on securing your PHP installation is this article at SecurityFocus.com.
 
Edit the Apache Configuration File (httpd.conf)
 
I like to keep all my configuration files together in /etc, so I set up a symbolic link from the actual location to /etc:
 
ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf
 
Now open /etc/httpd.conf in your favorite text editor, and set all the basic Apache options in accordance with the official Apache instructions (beyond thescope of this HOWTO).
Also recommended is the article on securing Apache. To ensure your PHP files are properly interpreted, and not just downloaded as text files, remove the # at the beginning of the lines which read:
 
#AddType application/x-httpd-php .php
#AddType application/x-httpd-php-source .phps
 
If the AddType lines above don't exist, manually enter them (without the leading # of course) after the line
 
AddType application/x-tar .tgz
 
or anyplace within the section of httpd.conf.
 
If you wish to use other/additional extensions/filetypes for your PHP scripts instead of just .php, add them to the AddType directive:
 
AddType application/x-httpd-php .php .foo
AddType application/x-httpd-php-source .phps .phtmls
 
An example: if you wanted every single HTML page to be parsed and processed like a PHP script, just add .htm and .html:
 
AddType application/x-httpd-php .php .htm .html
 
There will be a bit of a performance loss if every single HTML page is being checked for PHP code even if it doesn't contain any. But if you want to use PHP but be "stealthy" about it, you can use this trick. Add index.php to the list of valid Directory Index files so that your "default page" in a directory can be named index.php.
 
    DirectoryIndex index.php index.htm index.html
 
You can add anything else you want here too. If you want foobar.baz to be a valid directory index page, just add the .baz filetype to the AddType line, and add foobar.baz to the DirectoryIndex line.
 
Start Apache
 
We want to set Apache up with a normal start/stop script in /etc/rc.d/init.d so it can be auto-started and controlled like other system daemons. Set up a symbolic link for the apachectl utility (installed automatically as part of Apache):
 
ln -s /usr/local/apache/bin/apachectl /etc/rc.d/init.d/apache
 
Then set up auto-start for runlevel 3 (where the server will go by default):
 
ln -s /etc/rc.d/init.d/apache /etc/rc.d/rc3.d/S90apache
 
Then start the daemon:
 
/etc/rc.d/init.d/apache start
 
You can check that it's running properly by doing:
 
ps -ef
 
and look for the httpd processes.
 
Thanks to Bruce Timberlake, none of this could be done without him :)
 
AdamAji

Thursday, February 12, 2009

Apache : konfigurasi Virtual Host ing OpenSuse 11.

>>Pambagyo harjo<<

Virtual host kuwi nggunaake sak nomer IP kanggo 2 utawa luwih domain secara virtual, corone gampang, mung ngedit /etc/apache2/httpd.conf koyo ing ngisor iki.

edit bagian include /etc/apache2/listen.conf terus dikek'i comment (#).
tambahkan skrip Listen 80

# IP addresses / ports to listen on >> comment
#Include /etc/apache2/listen.conf
Listen 80 >> script tambahan
# predefined logging formats
Include /etc/apache2/mod_log_config.conf


edit bagian include /etc/apache2/vhosts.d/*.conf trus di kek'i comment (#).

#Include /etc/apache2/vhosts.d/*.conf >> comment
# Note: instead of adding your own configuration here, consider
# adding it in your own file (/etc/apache2/httpd.conf.local)
# putting its name into APACHE_CONF_INCLUDE_FILES in
# /etc/sysconfig/apache2 -- this will make system updates
# easier :)

tambahkan skrip koyo ing ngisor iki

NameVirtualHost 208.99.198.188:80


ServerAdmin webmaster@emocoreltd.com
DocumentRoot /srv/www/htdocs/emocoreltd/public_html
ServerName emocoreltd.com
# ErrorLog /var/log/httpd/domainsatu.com-error_log
# CustomLog /var/log/httpd/domainsatu.com-access_log common



ServerAdmin webmaster@kazamaaji.com
DocumentRoot /srv/www/htdocs/mishimaltd/public_html
ServerName kazamaaji.com
# ErrorLog /var/log/httpd/domainsatu.com-error_log
# CustomLog /var/log/httpd/domainsatu.com-access_log common

Monday, February 9, 2009

Bind: Carane nyeting NS 1 karo NS 2 sing kanggo backup neng OpenSuSE 11

>> Mukodimah <<

Poro pamiyarso sakwijining dino ono bocah sing jenenge DNS (Domain Name System) sing gaweane kuwi nerjemahke alamat IP neng Domain utawa walikane. Iso diumpamakke koyo phonebook nenggone hape. Lha umpamane awake ndewe kon ngeling-eling kabeh entry neng phonebook mau dalam bentuk nomer kan yo iso ra doyan mangan pitung dino pitung wengi tho??, Lha mangkane digawe contact sing isine jeneng karo nomer lan liyoliyane,ben mayar tur ora ngelu sirahe.

Salah sijine aplikasi sing kanggo nggawe DNS mau jenenge BIND. Ono ing tutorial ngisor iki aku nganggo OS OpenSuSE 11.

Kaping sepisan yo kuwi kudu nginstall BIND ndisik nganggo command ing ngisor iki:
adam:~ # YaST2 -i bind*

Sakwise kuwi banjur ngedit file-file konfigurasi neng ngisor iki:

############################
#### /etc/resolv.conf ######
############################
nameserver 208.99.198.188
nameserver 208.99.198.180 ##>>> nameserver nomer loro iki ditambahke neng konfigurasi ono ing server nomer 2

##################################################
#### /var/lib/named/emocoreltd.com.zone ##### NS 1
##################################################

$TTL 86400
@ IN SOA emocoreltd.com. root.emocoreltd.com. (
100 ; serial
1H ; refresh
1M ; retry
1W ; expiry
1D ) ; minimum
@ IN NS ns1.emocoreltd.com.
@ IN A 208.99.198.188
ns1 IN A 208.99.198.188
@ IN NS ns2.emocoreltd.com.
@ IN A 208.99.198.180
ns2 IN A 208.99.198.180
@ IN MX 10 mail.emocoreltd.com.
mail IN A 208.99.198.188
WWW IN A 208.99.198.188

###############################################################
#### emocoreltd.com.zone #### NS 2 dadi auto kopi dr nomer siji
###############################################################

###############################################################
/var/lib/named/198.99.208.rev
###############################################################

$TTL 86400
@ IN SOA emocoreltd.com. root.emocoreltd.com. (
100 ; serial
1H ; refresh
1M ; retry
1W ; expiry
1D) ; minimum
@ IN NS ns1.emocoreltd.com.

****catatan penting : intine update dari ns 1 ke ns 2 yo kuwi nomer serial ing konfigurasi neng nduwur iki, dadi nek meh ng-update kudu ngudakke serial neng ns siji ben iso luwih dhuwur ketimbang ns 2,so iso update okeh???

####################################################################
command neng ngisor iki dijalanke neng ns 2 so ns 1 ne iso overwrite ke ns dua gt lohh
#################################################################################

Change permission file /var/named

[root@rhesa2 ~]# chmod 777 -Rvf /var/named/
mode of `/var/named/’ changed to 0777 (rwxrwxrwx)
mode of `/var/named/named.zero’ changed to 0777 (rwxrwxrwx)
mode of `/var/named/localhost.zone’ changed to 0777 (rwxrwxrwx)
mode of `/var/named/data’ changed to 0777 (rwxrwxrwx)
mode of `/var/named/named.local’ changed to 0777 (rwxrwxrwx)
mode of `/var/named/named.ca’ changed to 0777 (rwxrwxrwx)
mode of `/var/named/named.ip6.local’ changed to 0777 (rwxrwxrwx)
mode of `/var/named/localdomain.zone’ changed to 0777 (rwxrwxrwx)
mode of `/var/named/named.broadcast’ changed to 0777 (rwxrwxrwx)
mode of `/var/named/slaves’ changed to 0777 (rwxrwxrwx)


############################################################
###### /etc/named.conf ###### NS1 dan NS2 deloken komentare
############################################################
# Copyright (c) 2001-2004 SuSE Linux AG, Nuernberg, Germany.
# All rights reserved.
#
# Author: Frank Bodammer, Lars Mueller
#
# /etc/named.conf
#
# This is a sample configuration file for the name server BIND 9. It works as
# a caching only name server without modification.
#
# A sample configuration for setting up your own domain can be found in
# /usr/share/doc/packages/bind/sample-config.
#
# A description of all available options can be found in
# /usr/share/doc/packages/bind/misc/options.

options {

# The directory statement defines the name server's working directory

directory "/var/lib/named";

# Write dump and statistics file to the log subdirectory. The
# pathenames are relative to the chroot jail.

dump-file "/var/log/named_dump.db";
statistics-file "/var/log/named.stats";

# The forwarders record contains a list of servers to which queries
# should be forwarded. Enable this line and modify the IP address to
# your provider's name server. Up to three servers may be listed.

#forwarders { 192.0.2.1; 192.0.2.2; };

# Enable the next entry to prefer usage of the name server declared in
# the forwarders section.

#forward first;

# The listen-on record contains a list of local network interfaces to
# listen on. Optionally the port can be specified. Default is to
# listen on all interfaces found on your system. The default port is
# 53.

#listen-on port 53 { 127.0.0.1; };

# The listen-on-v6 record enables or disables listening on IPv6
# interfaces. Allowed values are 'any' and 'none' or a list of
# addresses.

listen-on-v6 { any; };

# The next three statements may be needed if a firewall stands between
# the local server and the internet.

#query-source address * port 53;
#transfer-source * port 53;
#notify-source * port 53;

# The allow-query record contains a list of networks or IP addresses
# to accept and deny queries from. The default is to allow queries
# from all hosts.

#allow-query { 127.0.0.1; };

# If notify is set to yes (default), notify messages are sent to other
# name servers when the the zone data is changed. Instead of setting
# a global 'notify' statement in the 'options' section, a separate
# 'notify' can be added to each zone definition.

notify no;

allow-transfer {208.99.198.188/32;};///// neng ns loro ditambahi opsi iki nggo refer to NS1

};

# To configure named's logging remove the leading '#' characters of the
# following examples.
#logging {
# # Log queries to a file limited to a size of 100 MB.
# channel query_logging {
# file "/var/log/named_querylog"
# versions 3 size 100M;
# print-time yes; // timestamp log entries
# };
# category queries {
# query_logging;
# };
#
# # Or log this kind alternatively to syslog.
# channel syslog_queries {
# syslog user;
# severity info;
# };
# category queries { syslog_queries; };
#
# # Log general name server errors to syslog.
# channel syslog_errors {
# syslog user;
# severity error;
# };
# category default { syslog_errors; };
#
# # Don't log lame server messages.
# category lame-servers { null; };
#};

# The following zone definitions don't need any modification. The first one
# is the definition of the root name servers. The second one defines
# localhost while the third defines the reverse lookup for localhost.

#zone "." in {
# type hint;
# file "root.hint";
#};

#zone "localhost" in {
# type master;
# file "localhost.zone";
#};

#zone "0.0.127.in-addr.arpa" in {
# type master;
# file "127.0.0.zone";
#};

zone "emocoreltd.com" IN {
type master;
file "/var/lib/named/emocoreltd.com.zone";
allow-update { none; };/// di kek'i komen neng nggon ns2
allow-transfer {208.99.198.188/32;};/// ditamabahi neng ns2
masters { 208.99.198.188 ; };/// iki yo iyo
};

zone "198.99.208.in-addr.arpa" IN {
type master;
file "/var/lib/named/198.99.208.rev";
allow-update { none; };/// di kek'i komen neng nggon ns2
allow-transfer {208.99.198.188/32;};/// ditamabahi neng ns2
masters { 208.99.198.188 ; };/// iki yo iyo
}:

# Include the meta include file generated by createNamedConfInclude. This
# includes all files as configured in NAMED_CONF_INCLUDE_FILES from
# /etc/sysconfig/named

#include "/etc/named.conf.include";

# You can insert further zone records for your own domains below or create
# single files in /etc/named.d/ and add the file names to
# NAMED_CONF_INCLUDE_FILES.
# See /usr/share/doc/packages/bind/README.SUSE for more details.

####################################
Running service named>> bar kuwi restart service neng ns1 karo ns2

adamaji:~ # service named restart
Stopping named: [ OK ]
Starting named: [ OK ]