Cent OS 6.5 Phalcon PHP Production Server 32bit

featureimage

1 เดือนที่ผ่านมา พัฒนาระบบด้วย Phalcon จนได้ออกมาเป็น Product 1 ตัว ซึ่ง Development Environment เป็น OS X Mavericks แต่ตอน Production จำเป็นต้องทำงานบน Cent OS และมีข้อจำกัดคือต้องเป็น Cent OS แบบ 32bit ปกติลง Server บ่อยจนเข้าเส้น แต่ไม่เคย fix package 32bit แบบนี้ เลยเอามาบันทึกไว้เผื่อคราวหน้าจำเป็นต้องทำอีก

Install with Basic Server

Config Network

[root@Phoenix ~]# system-config-network

Disable firewall

[root@Phoenix ~]# system-config-firewall-tui

Disable SELinux

[root@Phoenix ~]# vim /etc/selinux/config
SELINUX=disabled  

Reboot

[root@Phoenix ~]# reboot

Enable Additional Repositories And Install Some Software

[root@Phoenix ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
[root@Phoenix ~]# rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
[root@Phoenix ~]# cd /tmp
[root@Phoenix tmp]# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.i686.rpm
[root@Phoenix tmp]# rpm -ivh rpmforge-release-0.5.3-1.el6.rf.i686.rpm
[root@Phoenix tmp]# rpm --import https://fedoraproject.org/static/0608B895.txt
[root@Phoenix tmp]# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
[root@Phoenix tmp]# rpm -ivh epel-release-6-8.noarch.rpm
[root@Phoenix tmp]# yum install yum-priorities

Edit Repos

[root@Phoenix tmp]# vim /etc/yum.repos.d/epel.repo
priority=10  

Update Packages

[root@Phoenix tmp]# yum update
[root@Phoenix tmp]# yum groupinstall 'Development Tools'

Install Quota

[root@Phoenix ~]# yum install quota
[root@Phoenix ~]# vim /etc/fstab

add ,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0 after / option

It's gonna be

/dev/mapper/vg_phoenix-lv_root /                       ext4    defaults,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0        1 1

Apply quota

[root@Phoenix ~]# mount -o remount /  
[root@Phoenix ~]# quotacheck -avugm  
[root@Phoenix ~]# quotaon -avug  

Install nessessary package

[root@Phoenix ~]# yum install perl httpd httpd-devel gcc gcc-c++ make ntp curl curl-devel perl-libwww-perl ImageMagick libxml2 libxml2-devel mod_fcgid

Setup Apache

add auto start

[root@Phoenix ~]# chkconfig httpd on

Setting Virtual host
replace {youruser} and {yourproject} to correct value (the example for port is 9000)

Listen 9000  
NameVirtualHost *:9000  
<VirtualHost *:9000>  
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/home/{youruser}/{yourproject}/public/"

    <Directory "/home/{youruser}/{yourproject}/public/">
       Options -Indexes +FollowSymLinks
       Allow From All
       AllowOverride All
    </Directory>
    ErrorLog "logs/{yourproject}-error_log"
    CustomLog "logs/{yourproject}-access_log" common
</VirtualHost>  

Download and Install MySQL (32bit)

[root@Phoenix ~]# cd /tmp
[root@Phoenix tmp]# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-shared-compat-5.6.21-1.el6.i686.rpm
[root@Phoenix tmp]# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-server-5.6.21-1.el6.i686.rpm
[root@Phoenix tmp]# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-client-5.6.21-1.el6.i686.rpm

re-check download file

[root@Phoenix tmp]# ls -l
total 74984  
-rw-r--r--  1 root root 17813608 Sep 12 15:25 MySQL-client-5.6.21-1.el6.i686.rpm
-rw-r--r--  1 root root 54611632 Sep 12 15:26 MySQL-server-5.6.21-1.el6.i686.rpm
-rw-r--r--  1 root root  4141488 Sep 23 21:01 MySQL-shared-compat-5.6.21-1.el6.i686.rpm

uninstall shipped MySQL (5.1.73) and then install MySQL 5.6.21 from .rpm

[root@Phoenix tmp]# yum remove mysql mysql-*
[root@Phoenix tmp]# rpm -ivh MySQL-shared-compat-5.6.21-1.el6.i686.rpm
[root@Phoenix tmp]# rpm -ivh MySQL-server-5.6.21-1.el6.i686.rpm
[root@Phoenix tmp]# rpm -ivh MySQL-client-5.6.21-1.el6.i686.rpm

Grab MySQL 5.6 root password (in version 5.6, MySQL will create root password automatic)

[root@Phoenix tmp]# cat /root/.mysql_secret
# The random password set for the root user at Fri Oct  3 10:44:51 2014 (local time): crmRknaNHqSQ7Jbs

Start mysql service

[root@Phoenix tmp]# /etc/init.d/mysql start
Starting MySQL. SUCCESS!  

Improve MySQL Installation Security with mysqlsecureinstallation

[root@Phoenix tmp]# mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL  
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current  
password for the root user.  If you've just installed MySQL, and  
you haven't set the root password yet, the password will be blank,  
so you should just press enter here.

Enter current password for root (enter for none):  
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL  
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n]  
New password:  
Re-enter new password:  
Password updated successfully!  
Reloading privilege tables..  
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone  
to log into MySQL without having to have a user account created for  
them.  This is intended only for testing, and to make the installation  
go a bit smoother.  You should remove them before moving into a  
production environment.

Remove anonymous users? [Y/n]  
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This  
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]  
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can  
access.  This is also intended only for testing, and should be removed  
before moving into a production environment.

Remove test database and access to it? [Y/n]  
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far  
will take effect immediately.

Reload privilege tables now? [Y/n]  
 ... Success!




All done!  If you've completed all of the above steps, your MySQL  
installation should now be secure.

Thanks for using MySQL!


Cleaning up...  

Make sure that this new MySQL server is enabled to auto start when server restarts.

[root@Phoenix tmp]# chkconfig mysql --level 2345 on

config MySQL

[root@Phoenix tmp]# vim /usr/my-new.cnf 

[mysqld]
user = mysql  
pid-file = /var/run/mysqld/mysqld.pid  
socket = /var/run/mysqld/mysqld.sock  
port = 3306  
basedir = /usr  
datadir = /var/lib/mysql  
tmpdir = /tmp  
language = /usr/share/mysql/English

skip-external-locking  
key_buffer_size = 384M  
max_allowed_packet = 10M  
table_open_cache = 512  
sort_buffer_size = 2M  
read_buffer_size = 2M  
read_rnd_buffer_size = 8M  
myisam_sort_buffer_size = 64M  
thread_cache_size = 8  
query_cache_size = 32M  
thread_concurrency = 4  
character-set-server   = utf8

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES  

restart MySQL

[root@Phoenix tmp]# /etc/init.d/mysql restart
[root@Phoenix tmp]# chkconfig mysql on

Install remi repository to install PHP 5.4, phpMyadmin 4.2.9 (PHP from remi, phpMyadmin from webtatic )

[root@Phoenix tmp]# rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
[root@Phoenix tmp]# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm 

edit file to enable repo

[root@Phoenix tmp]#  vim /etc/yum.repos.d/remi.repo
enabled=1  

install PHP 5.4, phpMyadmin 4.2.9

[root@Phoenix tmp]# yum install --skip-broken php php-devel php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-pecl-apc php-mbstring php-mcrypt php-mssql php-snmp php-soap php-tidy curl curl-devel perl-libwww-perl ImageMagick libxml2 libxml2-devel mod_fcgid php-cli httpd-devel phpmyadmin

[root@Phoenix tmp]# yum  install phpmyadmin

Config phpMyAdmin

[root@Phoenix tmp]# vim /etc/httpd/conf.d/phpMyAdmin.conf
<Directory /usr/share/phpMyAdmin/>  
   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
       Require ip 127.0.0.1
       Require ip ::1
     </RequireAny>
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
    # Order Deny,Allow
    # Deny from All
    # Allow from 127.0.0.1
    # Allow from ::1
     Order Allow,Deny
     Allow from All
   </IfModule>
</Directory>  

Install Xdebug

[root@Phoenix tmp]# pecl install Xdebug
[root@Phoenix tmp]# vim /etc/php.ini
[xdebug]
zend_extension=/usr/lib/php/modules/xdebug.so  
xdebug.remote_enable = 1  

Install Phalcon

[root@Phoenix tmp]# yum install php-devel php-mysqlnd gcc libtool git
[root@Phoenix tmp]# git clone --depth=1 git://github.com/phalcon/cphalcon.git
[root@Phoenix tmp]# cd cphalcon/build
[root@Phoenix tmp]# ./install

Add the extension to your php.ini:
Add a file called phalcon.ini in /etc/php.d/ with this content:

[root@Phoenix tmp]# vim /etc/php.d/phalcon.ini
extension=phalcon.so  

Install input.rc

[root@superlibrary tmp]# vim ~/.inputrc.txt

grab .inputrc content from gist (https://gist.github.com/pangpond/#file-inputrc) or use wget

[root@superlibrary tmp]# wget -c https://gist.githubusercontent.com/pangpond/a1e5c4a8f5d6e89541e4/raw/cf6002920a9e8e29d948880901392de79c7f587e/.inputrc
[root@superlibrary tmp]# mv .inputrc ~/.inputrc
[root@superlibrary tmp]# chmod +x ~/.inputrc

logout from terminal and login again