Posts Tagged Linux

Compiling Debian Wheezy Kernel for LinkStation LS421DE

After successfully replacing Buffalo stock firmware with Debian Wheezy, now it’s time to compile our own kernel. You need Ubuntu box to do cross compiling.

Preparation

Install required softwares:

$ sudo apt-get install build-essential git

Clone linkstation mod tools using Git:

$ mkdir ~/lsmod
$ cd ~/lsmod
$ git clone https://github.com/tohenk/linkstation-mod.git .

If you just want to update the tools, issue:

$ cd ~/lsmod && git pull

Prepare toolchain (as of 13c5db1):

Toolchains are availables from Linaro. New toolchain can be downloaded and prepared as follow:

$ mkdir -p ~/lsmod/lskernel/toolchain
$ cd ~/lsmod/lskernel/toolchain
$ wget http://releases.linaro.org/components/toolchain/binaries/5.3-2016.02/arm-linux-gnueabihf/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf.tar.xz
$ xzcat gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf.tar.xz | tar -xvf -

To configure which toolchain to use, issue:

$ cd ~/lsmod
$ ./lskernel/build-ls-kernel.sh --toolchain

Cloning Linux Git Repository

Issue the following command to clone Linux Git repository:

$ cd ~/lsmod
$ ./lskernel/build-ls-kernel.sh --download

The Linux Git Repository sized about 900 MB, so it may take more minutes depend on your connection speed. Next time, to update the repository issue command:

$ ./lskernel/build-ls-kernel.sh --update

Cross Compiling

As of commit de80705, now you can choose which kernel version to use:

$ ./lskernel/build-ls-kernel.sh --kver

Customize kernel configuration:

$ ./lskernel/build-ls-kernel.sh --config

Compile kernel image, modules, and DTB (as of commit 30d24d7):

$ ./lskernel/build-ls-kernel.sh --all

Package the kernel:

$ sudo ./lskernel/build-ls-kernel.sh --package

The resulting kernel is ls-kernel-3.18.tar.gz in the current directory.

Installing Kernel

Transfer packaged kernel to LinkStation (replace lsbox with your LinkStation ip address or hostname):

$ scp ls-kernel-3.18.tar.gz root@lsbox:/root/

Now on your LinkStation, issue commands:

$ cd ~
$ cp /boot/uImage.buffalo /boot/uImage.buffalo-$(uname -r)
$ tar --overwrite -xvf ls-kernel-3.18.tar.gz -C /

Restart LinkStation to use the new kernel:

$ reboot

Here is kernel log:

Booting Linux on physical CPU 0x0
Linux version 4.4.6-ls421de (toha@Dev-PC) (gcc version 5.3.1 20160113 (Linaro GCC 5.3-2016.02) ) #1 SMP Sat Mar 26 23:12:34 WIB 2016
CPU: ARMv7 Processor [561f5811] revision 1 (ARMv7), cr=10c5387d
CPU: PIPT / VIPT nonaliasing data cache, PIPT instruction cache
Machine model: Buffalo LinkStation LS421DE
Memory policy: Data cache writeback
On node 0 totalpages: 131072
free_area_init_node: node 0, pgdat c0dc8d80, node_mem_map dfbf8000
  Normal zone: 1024 pages used for memmap
  Normal zone: 0 pages reserved
  Normal zone: 131072 pages, LIFO batch:31
CPU: All CPU(s) started in SVC mode.
PERCPU: Embedded 13 pages/cpu @dfbdc000 s23616 r8192 d21440 u53248
pcpu-alloc: s23616 r8192 d21440 u53248 alloc=13*4096
pcpu-alloc: [0] 0 
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 130048
Kernel command line: console=ttyS0,115200 root=/dev/sda2 rw initrd=0x2600040 panic=5 BOOTVER=0.13 UBOOT_DATE=2013/08/28 mtdparts=armada-nand:0x2000000(boot),0x1e000000(rootfs)
PID hash table entries: 2048 (order: 1, 8192 bytes)
Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
Memory: 503300K/524288K available (8715K kernel code, 950K rwdata, 3968K rodata, 488K init, 737K bss, 20988K reserved, 0K cma-reserved, 0K highmem)
Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
    vmalloc : 0xe0800000 - 0xff800000   ( 496 MB)
    lowmem  : 0xc0000000 - 0xe0000000   ( 512 MB)
    pkmap   : 0xbfe00000 - 0xc0000000   (   2 MB)
    modules : 0xbf000000 - 0xbfe00000   (  14 MB)
      .text : 0xc0008000 - 0xc0c6b178   (12685 kB)
      .init : 0xc0c6c000 - 0xc0ce6000   ( 488 kB)
      .data : 0xc0ce6000 - 0xc0dd3a70   ( 951 kB)
       .bss : 0xc0dd3a70 - 0xc0e8c1f0   ( 738 kB)
Hierarchical RCU implementation.
	Build-time adjustment of leaf fanout to 32.
	RCU restricting CPUs from NR_CPUS=4 to nr_cpu_ids=1.
RCU: Adjusting geometry for rcu_fanout_leaf=32, nr_cpu_ids=1
NR_IRQS:16 nr_irqs:16 16
L2C: DT/platform modifies aux control register: 0x12086300 -> 0x1a086302
Aurora cache controller enabled, 4 ways, 256 kB
Aurora: CACHE_ID 0x00000100, AUX_CTRL 0x1a086302
Switching to timer-based delay loop, resolution 53ns
sched_clock: 32 bits at 18MHz, resolution 53ns, wraps every 114532461029ns
clocksource: armada_370_xp_clocksource: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 101933890472 ns
Console: colour dummy device 80x30
Calibrating delay loop (skipped), value calculated using timer frequency.. 37.50 BogoMIPS (lpj=187500)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
CPU: Testing write buffer coherency: ok
CPU0: thread -1, cpu 0, socket -1, mpidr 0
Setting up static identity map for 0x82a0 - 0x82f8
mvebu-soc-id: MVEBU SoC ID=0x6710, Rev=0x1
mvebu-pmsu: Initializing Power Management Service Unit
Brought up 1 CPUs
SMP: Total of 1 processors activated (37.50 BogoMIPS).
CPU: All CPU(s) started in SVC mode.
devtmpfs: initialized
VFP support v0.3: implementor 56 architecture 2 part 20 variant 9 rev 6
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
xor: measuring software checksum speed
   arm4regs  :  1106.000 MB/sec
   8regs     :  1018.400 MB/sec
   32regs    :  1024.800 MB/sec
xor: using function: arm4regs (1106.000 MB/sec)
pinctrl core: initialized pinctrl subsystem
NET: Registered protocol family 16
DMA: preallocated 256 KiB pool for atomic coherent allocations
cpuidle: using governor ladder
cpuidle: using governor menu
sram soc:sa-sram: found no memory resource
sram: probe of soc:sa-sram failed with error -22
hw-breakpoint: debug architecture 0x4 unsupported.
raid6: int32x1  gen()   170 MB/s
raid6: int32x1  xor()   218 MB/s
raid6: int32x2  gen()   265 MB/s
raid6: int32x2  xor()   248 MB/s
raid6: int32x4  gen()   307 MB/s
raid6: int32x4  xor()   252 MB/s
raid6: int32x8  gen()   349 MB/s
raid6: int32x8  xor()   233 MB/s
raid6: using algorithm int32x8 gen() 349 MB/s
raid6: .... xor() 233 MB/s, rmw enabled
raid6: using intx1 recovery algorithm
vgaarb: loaded
SCSI subsystem initialized
libata version 3.00 loaded.
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
Advanced Linux Sound Architecture Driver Initialized.
Bluetooth: Core ver 2.21
NET: Registered protocol family 31
Bluetooth: HCI device and connection manager initialized
Bluetooth: HCI socket layer initialized
Bluetooth: L2CAP socket layer initialized
Bluetooth: SCO socket layer initialized
clocksource: Switched to clocksource armada_370_xp_clocksource
NET: Registered protocol family 2
TCP established hash table entries: 4096 (order: 2, 16384 bytes)
TCP bind hash table entries: 4096 (order: 3, 32768 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
UDP hash table entries: 256 (order: 1, 8192 bytes)
UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
PCI: CLS 0 bytes, default 64
Trying to unpack rootfs image as initramfs...
Freeing initrd memory: 1448K (c2600000 - c276a000)
hw perfevents: enabled with armv7_cortex_a9 PMU driver, 7 counters available
futex hash table entries: 256 (order: 2, 16384 bytes)
VFS: Disk quotas dquot_6.6.0
VFS: Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
squashfs: version 4.0 (2009/01/31) Phillip Lougher
Installing knfsd (copyright (C) 1996 okir@monad.swb.de).
ntfs: driver 2.1.32 [Flags: R/W].
jffs2: version 2.2. (NAND) \xffffffc2\xffffffa9\xffffffa9 2001-2006 Red Hat, Inc.
fuse init (API version 7.23)
SGI XFS with ACLs, security attributes, realtime, no debug enabled
async_tx: api initialized (async)
Block layer SCSI generic (bsg) driver version 0.4 loaded (major 252)
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
armada-370-pinctrl d0018000.pin-ctrl: registered pinctrl driver
irq: Cannot allocate irq_descs @ IRQ41, assuming pre-allocated
irq: Cannot allocate irq_descs @ IRQ73, assuming pre-allocated
irq: Cannot allocate irq_descs @ IRQ105, assuming pre-allocated
mvebu-pcie soc:pcie-controller: PCI host bridge to bus 0000:00
pci_bus 0000:00: root bus resource [io  0x1000-0xfffff]
pci_bus 0000:00: root bus resource [mem 0xf8000000-0xffdfffff]
pci_bus 0000:00: root bus resource [bus 00-ff]
pci 0000:00:01.0: [11ab:6710] type 01 class 0x060400
pci 0000:00:02.0: [11ab:6710] type 01 class 0x060400
PCI: bus0: Fast back to back transfers disabled
pci 0000:00:01.0: bridge configuration invalid ([bus 00-00]), reconfiguring
pci 0000:00:02.0: bridge configuration invalid ([bus 00-00]), reconfiguring
pci 0000:01:00.0: [1912:0015] type 00 class 0x0c0330
pci 0000:01:00.0: reg 0x10: [mem 0x40000000-0x40001fff 64bit]
pci 0000:01:00.0: PME# supported from D0 D3hot D3cold
PCI: bus1: Fast back to back transfers disabled
pci_bus 0000:01: busn_res: [bus 01-ff] end is updated to 01
PCI: bus2: Fast back to back transfers enabled
pci_bus 0000:02: busn_res: [bus 02-ff] end is updated to 02
pci 0000:00:01.0: BAR 8: assigned [mem 0xf8000000-0xf80fffff]
pci 0000:01:00.0: BAR 0: assigned [mem 0xf8000000-0xf8001fff 64bit]
pci 0000:00:01.0: PCI bridge to [bus 01]
pci 0000:00:01.0:   bridge window [mem 0xf8000000-0xf80fffff]
pci 0000:00:02.0: PCI bridge to [bus 02]
pci 0000:00:01.0: enabling device (0140 -> 0142)
mv_xor d0060800.xor: Marvell shared XOR driver
mv_xor d0060800.xor: Marvell XOR (Registers Mode): ( xor cpy intr )
mv_xor d0060900.xor: Marvell shared XOR driver
mv_xor d0060900.xor: Marvell XOR (Registers Mode): ( xor cpy intr )
Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
console [ttyS0] disabled
d0012000.serial: ttyS0 at MMIO 0xd0012000 (irq = 19, base_baud = 12500000) is a 16550A
console [ttyS0] enabled
brd: module loaded
loop: module loaded
sata_mv d00a0000.sata: version 1.28
sata_mv d00a0000.sata: slots 32 ports 2
scsi host0: sata_mv
scsi host1: sata_mv
ata1: SATA max UDMA/133 irq 28
ata2: SATA max UDMA/133 irq 28
pxa3xx-nand d00d0000.nand: This platform can't do DMA on this device
nand: device found, Manufacturer ID: 0xad, Chip ID: 0xdc
nand: Hynix H27U4G8F2DTR-BC
nand: 512 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64
pxa3xx-nand d00d0000.nand: ECC strength 1, ECC step size 512
Bad block table found at page 262080, version 0x01
Bad block table found at page 262016, version 0x01
nand_read_bbt: bad block at 0x0000059c0000
nand_read_bbt: bad block at 0x0000061e0000
nand_read_bbt: bad block at 0x00000d9c0000
nand_read_bbt: bad block at 0x00000d9e0000
nand_read_bbt: bad block at 0x00000e1c0000
nand_read_bbt: bad block at 0x00000e1e0000
nand_read_bbt: bad block at 0x00001d1e0000
nand_read_bbt: bad block at 0x00001d840000
nand_read_bbt: bad block at 0x00001d860000
nand_read_bbt: bad block at 0x00001e6c0000
nand_read_bbt: bad block at 0x00001e6e0000
nand_read_bbt: bad block at 0x00001e840000
nand_read_bbt: bad block at 0x00001e860000
nand_read_bbt: bad block at 0x00001edc0000
nand_read_bbt: bad block at 0x00001ede0000
nand_read_bbt: bad block at 0x00001f380000
nand_read_bbt: bad block at 0x00001f3a0000
nand_read_bbt: bad block at 0x00001f840000
nand_read_bbt: bad block at 0x00001f860000
3 ofpart partitions found on MTD device pxa3xx_nand-0
Creating 3 MTD partitions on "pxa3xx_nand-0":
0x000000000000-0x000000100000 : "spi-flash"
0x000000100000-0x000002100000 : "boot"
0x000002100000-0x000020000000 : "rootfs"
libphy: Fixed MDIO Bus: probed
libphy: orion_mdio_bus: probed
mvneta d0074000.ethernet eth0: Using device tree mac address 10:6f:3f:cd:58:8b
PPP generic driver version 2.4.2
NET: Registered protocol family 24
ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
ehci-pci: EHCI PCI platform driver
ehci-orion: EHCI orion driver
orion-ehci d0050000.usb: EHCI Host Controller
orion-ehci d0050000.usb: new USB bus registered, assigned bus number 1
orion-ehci d0050000.usb: irq 25, io mem 0xd0050000
orion-ehci d0050000.usb: USB 2.0 started, EHCI 1.00
usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
usb usb1: Product: EHCI Host Controller
usb usb1: Manufacturer: Linux 4.4.6-ls421de ehci_hcd
usb usb1: SerialNumber: d0050000.usb
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 1 port detected
orion-ehci d0051000.usb: EHCI Host Controller
orion-ehci d0051000.usb: new USB bus registered, assigned bus number 2
orion-ehci d0051000.usb: irq 26, io mem 0xd0051000
orion-ehci d0051000.usb: USB 2.0 started, EHCI 1.00
usb usb2: New USB device found, idVendor=1d6b, idProduct=0002
usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
usb usb2: Product: EHCI Host Controller
usb usb2: Manufacturer: Linux 4.4.6-ls421de ehci_hcd
usb usb2: SerialNumber: d0051000.usb
hub 2-0:1.0: USB hub found
hub 2-0:1.0: 1 port detected
xhci_hcd 0000:01:00.0: xHCI Host Controller
xhci_hcd 0000:01:00.0: new USB bus registered, assigned bus number 3
xhci_hcd 0000:01:00.0: hcc params 0x014051cf hci version 0x100 quirks 0x00000090
usb usb3: New USB device found, idVendor=1d6b, idProduct=0002
usb usb3: New USB device strings: Mfr=3, Product=2, SerialNumber=1
usb usb3: Product: xHCI Host Controller
usb usb3: Manufacturer: Linux 4.4.6-ls421de xhci-hcd
usb usb3: SerialNumber: 0000:01:00.0
hub 3-0:1.0: USB hub found
hub 3-0:1.0: 2 ports detected
xhci_hcd 0000:01:00.0: xHCI Host Controller
xhci_hcd 0000:01:00.0: new USB bus registered, assigned bus number 4
usb usb4: We don't know the algorithms for LPM for this host, disabling LPM.
usb usb4: New USB device found, idVendor=1d6b, idProduct=0003
usb usb4: New USB device strings: Mfr=3, Product=2, SerialNumber=1
usb usb4: Product: xHCI Host Controller
usb usb4: Manufacturer: Linux 4.4.6-ls421de xhci-hcd
usb usb4: SerialNumber: 0000:01:00.0
hub 4-0:1.0: USB hub found
hub 4-0:1.0: 2 ports detected
usbcore: registered new interface driver cdc_acm
cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
usbcore: registered new interface driver usblp
usbcore: registered new interface driver cdc_wdm
usbcore: registered new interface driver usb-storage
usbcore: registered new interface driver usbserial
usbcore: registered new interface driver usbserial_generic
usbserial: USB Serial support registered for generic
usbcore: registered new interface driver pl2303
usbserial: USB Serial support registered for pl2303
mousedev: PS/2 mouse device common for all mice
i2c /dev entries driver
rtc-rs5c372 0-0032: rs5c372a found, 24hr, driver version 0.6
rtc rtc0: invalid alarm value: 2016-3-27 37:85:0
rtc-rs5c372 0-0032: rtc core: registered rtc-rs5c372 as rtc0
gpio-fan gpio-fan: GPIO fan initialized
md: linear personality registered for level -1
md: raid0 personality registered for level 0
md: raid1 personality registered for level 1
md: raid10 personality registered for level 10
ata1: SATA link up 3.0 Gbps (SStatus 123 SControl F300)
md: raid6 personality registered for level 6
md: raid5 personality registered for level 5
md: raid4 personality registered for level 4
device-mapper: ioctl: 4.34.0-ioctl (2015-10-28) initialised: dm-devel@redhat.com
ata1.00: ATA-9: WDC WD40EFRX-68WT0N0, 82.00A82, max UDMA/133
ata1.00: 7814037168 sectors, multi 0: LBA48 NCQ (depth 31/32)
ata1.00: configured for UDMA/133
scsi 0:0:0:0: Direct-Access     ATA      WDC WD40EFRX-68W 0A82 PQ: 0 ANSI: 5
marvell-cesa: probe of d0090000.crypto failed with error -22
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
sd 0:0:0:0: [sda] 7814037168 512-byte logical blocks: (4.00 TB/3.64 TiB)
sd 0:0:0:0: [sda] 4096-byte physical blocks
sd 0:0:0:0: Attached scsi generic sg0 type 0
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Mode Sense: 00 3a 00 00
oprofile: using arm/armv7-ca9
NET: Registered protocol family 10
sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
NET: Registered protocol family 17
bridge: automatic filtering via arp/ip/ip6tables has been deprecated. Update your scripts to load br_netfilter if you need this.
l2tp_core: L2TP core driver, V2.0
l2tp_ip: L2TP IP encapsulation support (L2TPv3)
l2tp_netlink: L2TP netlink interface
l2tp_eth: L2TP ethernet pseudowire support (L2TPv3)
l2tp_ip6: L2TP IP encapsulation support for IPv6 (L2TPv3)
8021q: 802.1Q VLAN Support v1.8
ThumbEE CPU extension supported.
Registering SWP/SWPB emulation handler
input: gpio-keys as /devices/platform/gpio-keys/input/input0
rtc-rs5c372 0-0032: setting system clock to 2016-03-27 01:53:05 UTC (1459043585)
ALSA device list:
  No soundcards found.
 sda: sda1 sda2 sda3 sda4 sda5 sda6
sd 0:0:0:0: [sda] Attached SCSI disk
ata2: SATA link up 3.0 Gbps (SStatus 123 SControl F300)
ata2.00: ATA-9: WDC WD40EFRX-68WT0N0, 80.00A80, max UDMA/133
ata2.00: 7814037168 sectors, multi 0: LBA48 NCQ (depth 31/32)
ata2.00: configured for UDMA/133
scsi 1:0:0:0: Direct-Access     ATA      WDC WD40EFRX-68W 0A80 PQ: 0 ANSI: 5
sd 1:0:0:0: [sdb] 7814037168 512-byte logical blocks: (4.00 TB/3.64 TiB)
sd 1:0:0:0: [sdb] 4096-byte physical blocks
sd 1:0:0:0: Attached scsi generic sg1 type 0
sd 1:0:0:0: [sdb] Write Protect is off
sd 1:0:0:0: [sdb] Mode Sense: 00 3a 00 00
sd 1:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
 sdb: sdb1 sdb2 sdb3 sdb4 sdb5 sdb6
sd 1:0:0:0: [sdb] Attached SCSI disk
md: Waiting for all devices to be available before autodetect
md: If you don't use raid, use raid=noautodetect
md: Autodetecting RAID arrays.
md: Scanned 0 and added 0 devices.
md: autorun ...
md: ... autorun DONE.
EXT4-fs (sda2): couldn't mount as ext3 due to feature incompatibilities
EXT4-fs (sda2): mounted filesystem with ordered data mode. Opts: (null)
VFS: Mounted root (ext4 filesystem) on device 8:2.
devtmpfs: mounted
Freeing unused kernel memory: 488K (c0c6c000 - c0ce6000)
udevd[1570]: starting version 175
random: nonblocking pool is initialized
Adding 999992k swap on /dev/sda5.  Priority:-1 extents:1 across:999992k 
EXT4-fs (sda2): re-mounted. Opts: (null)
EXT4-fs (sda2): re-mounted. Opts: (null)
EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: (null)
EXT4-fs (sda6): mounted filesystem with ordered data mode. Opts: (null)
IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
mvneta d0074000.ethernet eth0: Link is Up - 1Gbps/Full - flow control off
IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
NFSD: Using /var/lib/nfs/v4recovery as the NFSv4 state recovery directory
NFSD: starting 90-second grace period (net c0db3740)
XFS (sdb6): Mounting V4 Filesystem
XFS (sdb6): Ending clean mount

Things currently not working

  1. reboot command behave as poweroff.
  2. poweroff doesn’t halt the LinkStation, you need to turn off the power manually (fixed in kernel 4.4).

Important

The LinkStation kernel build script may changed regularly. You need to update the script by issuing:

$ cd ~/lsmod
$ git pull

Save pending works and change branch to master:

$ cd lskernel/linux
$ git stash save -a
$ git checkout master

Then recompile the kernel by following cross-compiling steps above.

, , , , ,

24 Comments

Hacking Symfony Application in A Shared Hosting

In a shared hosting environment, you may not have a full access to the server. Everything has already been installed. But a least they provide a secure shell (SSH).

I have successfully deploy a syfmony 1.2 application in a shared hosting, surely with a hacking.

PDO Hack

Symfony 1.2 at least need PHP 5.2.4 and above. So if your PHP version is 5.2.0 and you’re using MySQL database, make sure to activate PDO::MYSQL_ATTR_USE_BUFFERED_QUERY for buffered MYSQL Api.

Edit your databases.yml:

dev:
  propel:
    param:
      classname:  DebugPDO

all:
  propel:
    class:        sfPropelDatabase
    param:
      dsn:        mysql:dbname=your_db;host=localhost
      username:   root
      password:   your_password
      encoding:   utf8
      persistent: true
      pooling:    true
      classname:  PropelPDO
      options:
        MYSQL_ATTR_USE_BUFFERED_QUERY:  {value: on}

Symfony CLI Hack

Usually, we can customize the php.ini file for web server, but not for the PHP CLI. Unfortunately, the PDO extension for PHP CLI is not enabled by default. As in shared hosting environment, there are no write access to system configuration.

Try this:

$ php -i | grep PDO

If you got an output telling about PDO extensions has been enabled then, you don’t need this hack.

First, we can create our own php.ini file to be passed to the PHP CLI, and put in a writable directory, for example in the home directory:

# ~/php.ini
extension=pdo.so
extension=pdo_mysql.so
memory_limit=64M

Wrap the symfony command to make sure PHP CLI is using our custom php.ini, create the script and name it symfony.sh. Put in home directory for ease the access:

# ~/symfony.sh
cd /path/to/myproject
php -c ~/php.ini -f symfony -- $*

Make sure the script is executable:

$ chmod u+x ~/symfony.sh

Now you can launch the symfony CLI from within your home directory by issuing:

$ ./symfony.sh [command]

, , , , ,

6 Comments

Bringing Up Symfony Application into Linux Shared Hosting

Our application development has been finished, now the time we put the application alive on the web. On shared hosting, directory structure for a html files has already been specified according to the server.

First step, is to figure out what it looks like and where to put html files. Below is a sample:

root/                         <- your hosting root
  home/
  etc/
  public/
  sites/
    www.example.com/
      www/                    <- this is where html files reside,
                                 it can also be html instead www

As we know, the only published part of symfony application is the web folder. So be prepared to put the symfony library and our application files into a folder. You can put the files in home folder for example, or in the public folder (see structure). Lets assume we are using the public folder. The directory structure should looks like:

root/                         <- your hosting root
  home/
  etc/
  public/
    myproject/                <- here are our application files
    symfony/                  <- the symfony library
  sites/
    www.example.com/
      www/                    <- this is where html files reside,
                                 it can also be html instead www

Before transferring all those files, make sure your project config file include the symfony library using relative path.

Symfony 1.0 (myproject/config/config.php):

<?php

// symfony directories
$sf_symfony_lib_dir  = realpath(dirname(__FILE__).'/../../symfony/lib');
$sf_symfony_data_dir = realpath(dirname(__FILE__).'/../../symfony/data');

Symfony 1.1 and up (myproject/config/ProjectConfiguration.class.php):

<?php

require_once dirname(__FILE__).'/../../symfony/lib/autoload/sfCoreAutoload.class.php';
sfCoreAutoload::register();

class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {
    // ...
  }
}

Transfer all files to those folder using either ftp client, rsync (which I am prefer) , or using your Hosting Control Panel. For Windows users, you can try using CwRsync which already include a ssh client.

The visible files for symfony application are:

  • index.php, production front controller.
  • .htaccess, for url rewriting and others apache stuffs.
  • images, the images folder.
  • css, the stylesheets folder.
  • js, the javascripts folder.
  • sf, the symfony assets folder.
  • uploads, the uploads folder.
  • Plus the plugin assets.

So now you can open a remote shell to symlink all those files and directory to be published under the web using a ssh client. Most of web server hosting already include a secure shell server, but you can check if it’s already enabled in your Control Panel. As an alternative client, you can use putty either. Here are the sample command to be issued:

> ssh myuser@example.com

$ cd /path/to/sites/www.example.com/www
$ ln -s /path/to/public/myproject/web/index.php index.php
$ ln -s /path/to/public/myproject/web/.htaccess .htaccess
$ ln -s /path/to/public/myproject/web/images images
$ ln -s /path/to/public/myproject/web/css css
$ ln -s /path/to/public/myproject/web/js js
$ ln -s /path/to/public/myproject/web/uploads uploads
$ ln -s /path/to/public/myproject/web/sfPlugin sfPlugin <- the plugin assets
$ ln -s /path/to/public/symfony/data/web/sf sf

Repeat the command for all others files needed by your application, for example, plugins assets. Then, let’s continue by fixing the file permission.

$ cd /path/to/public/myproject
$ chmod u+x symfony                    <- make symfony executable
$ ./symfony fix-perms                  <- symfony 1.0
$ ./symfony project:permissions        <- symfony 1.1 and up

Some times, we also must fix the permission for the front controller, 0755 is satisfied.

$ chmod 0755 index.php
$ chmod 0755 .htacess

You’re done, try browsing your server.

Most of shared web hosting will redirect error log to stdout neither to a log file, so the error will be visible to the user. To avoid this, you need to comment the error_log() method call in symfony/lib/exception/sfException.class.php and symfony/lib/exception/sfError404Exception.class.php (symfony 1.1 and up).

Next time if you update your application, just transfer the changes (which handled by rsync), fix the permissions, and no need to do symlink again.

, , ,

5 Comments