Tuesday, September 23, 2014

My Apache Experience 2

When I ran
/etc/init.d/apache2 restart
but the simple error was displayed like below
ERROR: apache2 failed to start

Finally, I found a way to find out the failure reason,
/etc/init.d/apache2 -d -v start

From the console output the progress message, 

+ '[' 10 -lt 15 ']'
+ '[' -e /var/run/apache2.pid ']'
+ sleep 1

the startup program will check /var/run/apache2.pid existed or not,
but from the configuration file
/etc/apache2/modules.d/00_mpm.conf
the pid file is stored in /run/apache2.pid

so I modified the configuration file to update the pid file to /var/run.
Retry again /etc/init.d/apache2 and finally it is ok right now.

 * Stopping apache2 ...                                                                                         [ ok ]
 * Starting apache2 ...                                                                                         [ ok ]

Reference:
http://wonkabar.org/2012/09/10/gentoo-openrc-apache-and-monit-proper-starting-and-stopping/

Sunday, September 21, 2014

Integrate PHP and Apache2 in Gentoo by emerge

My experience to integrate PHP and apache in Gentoo by emerge

It is an easy way to install PHP in gentoo by "emerge --ask php", but it will not integrate PHP and Apache.

My solution is

in /etc/portage/package.use, add
dev-lang/php apache2

lets again "emerge --ask php",

The following USE changes are necessary to proceed:
#required by dev-lang/php-5.6.0, required by php (argument)
>=app-admin/eselect-php-0.7.1-r3 apache2

Use --autounmask-write to write changes to config files (honoring CONFIG_PROTECT).

The error is like to ask to install an external application, so the final solution is

in /etc/portage/package.usage, add
dev-lang/php apache2
>=app-admin/eselect-php-0.7.1-r3 apache2

So the result of "emerge --ask php" is like

localhost ~ # ls -l /usr/lib/apache2/modules/
total 1204
lrwxrwxrwx 1 root root     31 Sep 21 16:16 libphp5.so -> ../../php5.5/apache2/libphp5.so

in /etc/conf.d/apache2
APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP5"

Finally,
/etc/init.d/apache2 restart

Install Apache in Gentoo by emerge

My experience of installing Apache in Gentoo by emerge.

By emerge to install apache in gentoo is very straightforward, just "emerge --ask apache" and done.
But the default, there is no any mod_auth_digest.so.

lets build mod_auth_digest.so for apache.

localhost ~ # emerge -pv apache

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R    ] www-servers/apache-2.2.27-r4:2  USE="ssl -debug -doc -ldap (-selinux) -static -suexec -threads" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias -asis -auth_digest -authn_dbd -cern_meta -charset_lite -dbd -dumpio -ident -imagemap -log_forensic -proxy -proxy_ajp -proxy_balancer -proxy_connect -proxy_ftp -proxy_http -proxy_scgi -reqtimeout -substitute -version" APACHE2_MPMS="-event -itk -peruser -prefork -worker" 0 kB

Total: 1 package (1 reinstall), Size of downloads: 0 kB

 * IMPORTANT: 5 news items need reading for repository 'gentoo'.
 * Use eselect news to read news items.


From the output of "emerge -pv apache", the "-auth_digest" means the auth_digest is not enable.
So a way to enable it is,

in /etc/portage/make.conf, add

APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias auth_digest"

Lets check again.

[Check 1]
localhost ~ # emerge --ask apache

 * IMPORTANT: 5 news items need reading for repository 'gentoo'.
 * Use eselect news to read news items.


These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R    ] www-servers/apache-2.2.27-r4  APACHE2_MODULES="auth_digest*"

[Check 2]
localhost ~ # emerge -pv apache

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R    ] www-servers/apache-2.2.27-r4:2  USE="ssl -debug -doc -ldap (-selinux) -static -suexec -threads" APACHE2_MODULES="actions alias auth_basic auth_digest* authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias -asis -authn_dbd -cern_meta -charset_lite -dbd -dumpio -ident -imagemap -log_forensic -proxy -proxy_ajp -proxy_balancer -proxy_connect -proxy_ftp -proxy_http -proxy_scgi -reqtimeout -substitute -version" APACHE2_MPMS="-event -itk -peruser -prefork -worker" 0 kB

Total: 1 package (1 reinstall), Size of downloads: 0 kB

 * IMPORTANT: 5 news items need reading for repository 'gentoo'.
 * Use eselect news to read news items.

Lets run "emerge --ask apache" again, and the result is like

localhost ~ # ls /usr/lib/apache2/modules/
libphp5.so          mod_authn_anon.so     mod_authz_groupfile.so  mod_cgi.so       mod_dir.so         mod_filter.so      mod_mem_cache.so    mod_speling.so    mod_vhost_alias.so
mod_actions.so      mod_authn_dbm.so      mod_authz_host.so       mod_cgid.so      mod_disk_cache.so  mod_headers.so     mod_mime.so         mod_ssl.so
mod_alias.so        mod_authn_default.so  mod_authz_owner.so      mod_dav.so       mod_env.so         mod_include.so     mod_mime_magic.so   mod_status.so
mod_auth_basic.so   mod_authn_file.so     mod_authz_user.so       mod_dav_fs.so    mod_expires.so     mod_info.so        mod_negotiation.so  mod_unique_id.so
mod_auth_digest.so  mod_authz_dbm.so      mod_autoindex.so        mod_dav_lock.so  mod_ext_filter.so  mod_log_config.so  mod_rewrite.so      mod_userdir.so
mod_authn_alias.so  mod_authz_default.so  mod_cache.so            mod_deflate.so   mod_file_cache.so  mod_logio.so       mod_setenvif.so     mod_usertrack.so

So there is mod_auth_basic.so built.
But this is not enough.

in /etc/conf.d/apache2, add
...
APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D AUTH_DIGEST"
...

This setting will affect /etc/apache2/httpd.conf to load mod_auth_digest.so

in /etc/apache2/httpd.conf
...
LoadModule auth_digest_module modules/mod_auth_digest.so
...

Saturday, September 20, 2014

Install Gentoo in VM.

Write down my experience to install gentoo in vm.

1.
Boot from install-x86-minimal-20140902.iso

2.
mount /dev/sda1 /mnt/gentoo

3.
links http://www.gentoo.org/main/en/mirrors.xml

4.
mount -t proc proc /mnt/gentoo/proc
mount --rbind /dev /mnt/gentoo/dev
mount --rbind /sys /mnt/gentoo/sys
cp -L /etc/resolv.conf /mnt/gentoo/etc/
chroot /mnt/gentoo /bin/bash
source /etc/profile

5.
emerge gentoo-sources

6.
cd /usr/src/linux
make menuconfig
make -j2

7.
cp arch/x86/boot/bzImage /boot/kernel-$(uname -r)

8.
make modules_install

9.
emerge genkernel
genkernel --install --no-ramdisk-modules initramfs
(It will create initramfs-genkernel-x86-3.14.16-gentoo in /boot/.)

10.
cat /etc/fstab
/dev/sda1 / ext4 noatime 0 1

11.
change root password

12
emerge grub

13.
livecd ~ # grub2-install /dev/sda
Installation finished. No error reported.

livecd ~ # grub2-mkconfig -o /boot/grub/grub.cfg
Generating grub.cfg ...
Found linux image: /boot/kernel-3.14.16-gentoo
Found initrd image: /boot/initramfs-genkernel-x86-3.14.16-gentoo
done

14.
emerge dhcpcd

echo "modules = "dhcpcd"" > /etc/conf.d/net
echo "config_enp2s1="dhcp" >> /etc/conf.d/net

Problem:
scripts/mod/empty.c:1:0: error: CPU you selected does not support x86-64 instruction set

Solution:
When make menuconfig, make sure un-check 64-bit kernel.
[ ] 64-bit kernel

Problem:
/usr/bin/xz: /var/tmp/genkernel/initramfs-3.14.16-gentoo: Cannot allocate memory
ERROR: Compression (/usr/bin/xz -e --check=none -z -f -9) failed

Solution:
Increase memory for the VM. In my case, to 1GB.

Problem:
Could not find the root block device in UUID=XXX

Solution:
livecd ~# lspci
SCSI storage controller: LSI Logic / Symbios Logic 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)
Ethernet controller: Advanced Micro Devices, Inc. [AMD] 79c970 [PCnet32 LANCE] (rev 10)

When make menuconfig, make sure

Device Drivers  --->
SCSI device support  --->
[*] SCSI low-level drivers  --->
<*>   BusLogic SCSI support
[*] Fusion MPT device support  --->
<*>   Fusion MPT ScsiHost drivers for SPI
<*>   Fusion MPT ScsiHost drivers for FC
<*>   Fusion MPT ScsiHost drivers for SAS
<*>   Fusion MPT misc device (ioctl) driver

[*] Network device support  --->
[*]   Ethernet driver support  --->
<*>     AMD PCnet32 PCI support


Reference:
http://www.gentoo.org/doc/en/gentoo-x86-quickinstall.xml
http://www.360doc.com/content/13/1030/15/1956846_325320292.shtml