1. 첫번째 방법

AndroidManifest.xml 파일에 아래와 같이 설정


<activity android:name=".Activity"

android:label="@string/app_name"

android:screenOrientation="portrait" />





2. 두번째 방법

super.onCreate(savedInstanceState);

setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 

setContentView(R.layout.activity_indexviewpager);


블로그 이미지

엘로드넷

,

php 5.4 number_format

PHP 2016. 1. 27. 17:33

php5.3이전에는 number_format($var) 에서 $var값이 숫자이든 문자이든 에러를 발생시키지 않았으나,

php5.3이후부턴 오류 발생함


아래와 같이 변경


$var1 = 2000;

$var2 = 20.00;

$var3 = "20한글00";



1. 변수에 포함된 공백, 마침표, 쉼표, 문자 등 숫자 이외의 것들을 걸러낸다.


$output = preg_replace('/[^0-9]/', '', $var3);


2. number_format() 을 적용한다.

$output = number_format($output);


echo $output;



결과 값은  : 2,000



 






'PHP' 카테고리의 다른 글

페이징 및 함수이용  (0) 2016.03.01
MySQL 트랜잭션  (0) 2016.02.29
php 5.4 eregi to preg_match  (0) 2016.01.27
php 5.4 split to explode  (0) 2016.01.27
PHP 5.3이상에서 변경되는 함수들  (0) 2015.07.24
블로그 이미지

엘로드넷

,

php 5.4 eregi to preg_match

PHP 2016. 1. 27. 17:24


eregi 는 preg_match 로 변경



변경 전 : 

if (eregi("data/cheditor4/{$ym}/[^<>]*\.(gif|jpg|png|bmp)", $edit_img, $tmp)) { 



}



변경 후 :

if (preg_match("/data\/cheditor4\/{$ym}\/[^<>]*\.(gif|jpg|png|bmp)/", $edit_img, $tmp)) { 



}





'PHP' 카테고리의 다른 글

MySQL 트랜잭션  (0) 2016.02.29
php 5.4 number_format  (0) 2016.01.27
php 5.4 split to explode  (0) 2016.01.27
PHP 5.3이상에서 변경되는 함수들  (0) 2015.07.24
php, 아파치 에러로그 Use of undefined constant ~~~  (0) 2015.04.29
블로그 이미지

엘로드넷

,

php 5.4 split to explode

PHP 2016. 1. 27. 17:20

split 함수는 explode 로 변경



추가적인 작업 필요없이 함수만 변경하면된다.


블로그 이미지

엘로드넷

,

가. test.com 으로 접속한 것을 www.test.com 으로 리다이렉션하기


1. test.com 도메인 루트에 .htaccess 파일 생성하기


[root@localhost www.test.com]# vi .htaccess


파일 내용은 아래와 같다.


RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.kimhae.com$ [NC]

RewriteRule ^(.*)$ http://www.kimhae.com/$1 [L,R=301]

~                                                       



저장하고 빠져나온다.



2. httpd.conf 설정


 아래 부분에서 AllowOverride None 으로 되어 있는 것을 All 로 변경해 준다.


<Directory "/home/*">

    #

    # 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 All


    #

    # Controls who can get stuff from this server.

    #

    Order allow,deny

    Allow from all


</Directory>



저장하고 나온다.


아파치 재시작


test.com 으로 접속하면 url이 즉시 www.test.com 으로 바뀌는 것을 확인할 수 있다.





나. 반대로 www.test.com 을 test.com 으로 리다이렉션 시킬 경우는 아래와 같이


RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.test\.com$

RewriteRule ^/?$ "http\:\/\/test\.com\/" [R=301,L]

~                                                       




다. 특정 경로로 리다이렉션 하기


test.com 으로 접속하면 www.test.com/test.php 로 접속하기


RewriteEngine On

RewriteCond %{HTTP_HOST} ^test.com$

RewriteRule ^$ "http://www.test.com/test.php [L,R=301]

~                                                       





라. 다른 도메인으로 리다이렉션하기


test.com 을 www.test2.net 으로


RewriteEngine On

RewriteCond %{HTTP_HOST} !test.com$ [NC]

RewriteRule ^(.*)$ http://www.test2.net/$1 [L,R=301]

~                                                       






끝.








'Linux' 카테고리의 다른 글

top load average  (0) 2016.02.15
CentOS 7 SVN iptables  (0) 2016.01.29
Linux NFS iptables  (0) 2016.01.19
CentOS 7 아파치 2.4.6 한글깨짐 AddDefaultCharset  (0) 2016.01.15
CentOS 7 apache virtualhost  (2) 2016.01.15
블로그 이미지

엘로드넷

,

Linux NFS iptables

Linux 2016. 1. 19. 19:07

NFS Server : 192.168.0.1

NFS Client : 192.168.0.2

NFS Folder : /home/user/session






1. Server (192.168.0.1)


/etc/sysconfig/nfs 파일 수정


#vi /etc/sysconfig/nfs


LOCKD_TCPPORT=32803

# UDP port rpc.lockd should listen on.

LOCKD_UDPPORT=32769


MOUNTD_PORT=892




Server 공유폴더 지정


# vi /etc/exports 


/home/user/session 192.168.0.2(rw,sync,no_root_squash)



nfs시작


# service rpcbind start

# service nfs start




iptables



iptables -A INPUT -s 192.168.0.0/24 -d 192.168.0.0/24 -p udp -m multiport --dport 10053,111,2049,32769,875,892 -m state --state NEW,ESTABLISHED -j ACCEPT


iptables -A INPUT -s 192.168.0 0/24 -d 192.168.0 0/24 -p tcp -m multiport --dport 10053,111,2049,32803,875,892 -m state --state NEW,ESTABLISHED -j ACCEPT









2. Client (192.168.0.2)


/etc/sysconfig/nfs파일 수정


vi /etc/sysconfig/nfs


LOCKD_TCPPORT=32803

# UDP port rpc.lockd should listen on.

LOCKD_UDPPORT=32769


MOUNTD_PORT=892



iptables


iptables -A INPUT -s 192.168.0.0/24 -d 192.168.0 0/24 -p udp -m multiport --sport 10053,111,2049,32769,875,892,32769 -m state --state NEW,ESTABLISHED -j ACCEPT


iptables -A INPUT -s 192.168.0.0/24 -d 192.168.0 0/24 -p tcp -m multiport --sport 10053,111,2049,32803,875,892,32803 -m state --state NEW,ESTABLISHED -j ACCEPT




nfs시작


# service rpcbind start

# service nfs strt





NFS폴더 마움트


# mount -t nfs 192.168.0.1:/home/user/session /home/user/session





NFS 마운트 해제

# umount /home/user/session



NFS 마운트 강제 해제


# umount -f -l /home/user/session








블로그 이미지

엘로드넷

,

httpd 2.4.6 에서 기본 문자셋이 UTF-8 이어서 euc_kr 로 제작된 html에서 한글이 깨진다.


1. httpd.conf 에서 기본을 EUC-KR 으로 변경하고 utf8을 추가해 주기로 한다.



아래와 같이 


AddDefaultCharset EUC-KR

AddCharset UTF-8 .utf8






2. 아파치를 재시작한다.



[root@localhost httpd]# systemctl restart httpd.service





끝.

'Linux' 카테고리의 다른 글

아파치 리다이렉션 apache url redirection www .htaccess rewrite httpd.conf  (0) 2016.01.25
Linux NFS iptables  (0) 2016.01.19
CentOS 7 apache virtualhost  (2) 2016.01.15
CentOS 7 iptables 설정  (1) 2016.01.15
CentOS 7 APM yum 설치 MariaDB  (11) 2016.01.15
블로그 이미지

엘로드넷

,

CentOS 7 apache virtualhost

Linux 2016. 1. 15. 20:03


1. 가상호스트 설정파일을 만든다


[root@localhost conf.d]# vi /etc/httpd/conf.d/vhost.conf



파일 내용은 아래와 같다.



<VirtualHost *:80>


        DocumentRoot /home/testuser/a.test.com

        ServerName a.test.com

        ServerAlias a.test.com

        ErrorLog /var/log/httpd/a.test.com_error.log

        CustomLog /var/log/httpd/a.test.com_access.log combined


</VirtualHost>




2. userdir.conf 에서 testuser 폴더 권한을 지정해 준다.


[root@localhost conf.d]# vi /etc/httpd/conf.d/userdir.conf 



내용 끝에 아래와 같이 추가해 준다.


#

# UserDir: The name of the directory that is appended onto a user's home

# directory if a ~user request is received.

#

# The path to the end user account 'public_html' directory must be

# accessible to the webserver userid.  This usually means that ~userid

# must have permissions of 711, ~userid/public_html must have permissions

# of 755, and documents contained therein must be world-readable.

# Otherwise, the client will only receive a "403 Forbidden" message.

#

<IfModule mod_userdir.c>

    #

    # UserDir is disabled by default since it can confirm the presence

    # of a username on the system (depending on home directory

    # permissions).

    #

    UserDir disabled


    #

    # To enable requests to /~user/ to serve the user's public_html

    # directory, remove the "UserDir disabled" line above, and uncomment

    # the following line instead:

    #

    #UserDir public_html

</IfModule>


#

# Control access to UserDir directories.  The following is an example

# for a site where these directories are restricted to read-only.

#

<Directory "/home/*/public_html">

    AllowOverride FileInfo AuthConfig Limit Indexes

    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec

    Require method GET POST OPTIONS

</Directory>


<Directory "/home/testuser/*">

        Require all granted

</Directory>

"/etc/httpd/conf.d/userdir.conf" 38L, 1307C




3. 아파치를 재시작한다.


[root@localhost conf.d]# systemctl restart httpd.service





끝.




'Linux' 카테고리의 다른 글

Linux NFS iptables  (0) 2016.01.19
CentOS 7 아파치 2.4.6 한글깨짐 AddDefaultCharset  (0) 2016.01.15
CentOS 7 iptables 설정  (1) 2016.01.15
CentOS 7 APM yum 설치 MariaDB  (11) 2016.01.15
CentOS 7 MySQL-5.7.10 설치 boost  (0) 2016.01.11
블로그 이미지

엘로드넷

,

CentOS 7 iptables 설정

Linux 2016. 1. 15. 13:00

우선 방화벽을 중지한다.

[root@localhost log]# systemctl stop firewalld     

[root@localhost log]# systemctl mask firewalld       



iptables관련 패키지를 설치(업데이트)한다.

[root@localhost log]# yum install iptables-service    



부팅시 시작되도록 한다.

[root@localhost log]# systemctl enable iptables     



iptables 설정파일은 /etc/sysconfig/iptables 이다.


해당 파일을 편집한다.


1. 특정 IP 또는 IP블럭을 거부하고자 할 때,


-A INPUT -s 177.91.82.23 -j DROP

-A INPUT -s 177.91.82.0/24 -j DROP


와 같은 형태로 추가해 준다.



2. 특정 포는 특정 IP 또는 IP블럭에게만 허가하기


-A INPUT -s 192.168.0.0/24 -p tcp --dport 22 -j ACCEPT





iptables 상태확인


[root@localhost log]# systemctl status iptables

iptables.service - IPv4 firewall with iptables

   Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)

   Active: active (exited) since 수 2016-01-13 11:31:40 KST; 1 day 23h ago

  Process: 31836 ExecStop=/usr/libexec/iptables/iptables.init stop (code=exited, status=0/SUCCESS)

  Process: 31903 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS)

 Main PID: 31903 (code=exited, status=0/SUCCESS)

   CGroup: /system.slice/iptables.service


 1월 13 11:31:40 localhost.localdomain systemd[1]: Starting IPv4 firewall with iptables...

 1월 13 11:31:40 localhost.localdomain iptables.init[31903]: iptables: Applying firewall rules: [  OK  ]

 1월 13 11:31:40 localhost.localdomain systemd[1]: Started IPv4 firewall with iptables.



iptables 재시작


[root@localhost log]# systemctl restart iptables











'Linux' 카테고리의 다른 글

CentOS 7 아파치 2.4.6 한글깨짐 AddDefaultCharset  (0) 2016.01.15
CentOS 7 apache virtualhost  (2) 2016.01.15
CentOS 7 APM yum 설치 MariaDB  (11) 2016.01.15
CentOS 7 MySQL-5.7.10 설치 boost  (0) 2016.01.11
CentOS 7 network prefix  (0) 2015.12.04
블로그 이미지

엘로드넷

,

php5.6.x대로 올라가면서 소스컴파일시 libmysqlclient_r 관련 에러가 나고 설치가 잘 되지 않는다.

이유인즉 더 이상 번들로 제공되지 않는다는 것인데...


php7로도 시도해 봤지만 결과는 마찬가지다.



결론적으로 yum 을 이용한 설치로 진행하고자 한다.



설치순서는 MySQL5(MariaDB5) > Apache > PHP 이다.


yum으로 MySQL대신에 MariaDB를 설치하기로 한다. MySQL과 명령어는 동일하니깐..



1. mariadb


설치되는 버전은 5.5.44 이다.


[root@Cent7_64B ~]# yum -y install mariadb-server mariadb

[root@Cent7_64B ~]# systemctl start mariadb.service

[root@Cent7_64B ~]# systemctl enable mariadb.service


설치가 되었고 데몬도 시작하였다.


기본 디비와 루트비번을 설정한다.


[root@Cent7_64B ~]# mysql_secure_installation



root 비번 설정 후, 모두 엔터키로 넘어간다.


mariadb 설치 끝


root로 접속되는지 확인해 본다.


[root@Cent7_64B ~]# mysql -u root -p mysql

Enter password: 

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A


Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 3

Server version: 5.5.44-MariaDB MariaDB Server


Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


MariaDB [mysql]> 



접속이 된다.




2. Httpd (Apache) 


설치되는 버전은 2.4.6 이다.



[root@Cent7_64B ~]# yum -y install httpd

[root@Cent7_64B ~]# systemctl start httpd.service

[root@Cent7_64B ~]# systemctl enable httpd.service


방화벽 등록

[root@Cent7_64B ~]# firewall-cmd --permanent --zone=public --add-service=http

[root@Cent7_64B ~]# firewall-cmd --permanent --zone=public --add-service=https



직접 zone파일을 수정해도 된다.

[root@Cent7_64B zones]# vi /etc/firewalld/zones/public.xml



등록되어 있는지 확인해 보자.


아래는 public.xml 내용이다.


<?xml version="1.0" encoding="utf-8"?>

<zone>

  <short>Public</short>

  <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>

  <service name="dhcpv6-client"/>

  <service name="http"/>

  <service name="ssh"/>

  <service name="https"/>

  <port protocol="tcp" port="3306"/>

</zone>



service에 http와 https가 등록되어 있다.


방화벽을 재시작하여 적용한다.


[root@Cent7_64B zones]# firewall-cmd --reload



브라우저에서 접속해 본다.


아래와 같은 화면이 뜨면 된다.






Document Root 는 /var/www/html 이다.

httpd.conf 파일 위치는 /etc/httpd/conf/httpd.conf 이다.





3. PHP설치


설치되는 버전은 5.4.16 이다.


[root@Cent7_64B conf.d]# yum -y install php



설치 후 아파치를 재시작하면 적용된다.


[root@Cent7_64B conf.d]# systemctl restart httpd.service



phpinfo();  로 확인해 본다.







밑으로 쭉 내려서 모듈들이 설치되었는지 확인해 본다.


iconv, json, libxml, mbstring, mysql, openssl 등등



참고로 설치할 수 있는 php관련 모듈을 검색해 본다.

[root@Cent7_64B conf.d]# yum search php                                                                        

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

 * base: ftp.daumkakao.com

 * epel: mirror.premi.st

 * extras: ftp.daumkakao.com

 * updates: ftp.daumkakao.com

 * webtatic: sp.repo.webtatic.com

================================================================================= N/S matched: php ==================================================================================

geos-php.x86_64 : PHP modules for GEOS

graphviz-php.x86_64 : PHP extension for graphviz

nntpgrab-php.x86_64 : PHP module which allows PHP scripts to communicate with NNTPGrab

php.x86_64 : PHP scripting language for creating dynamic web sites

php-Assetic.noarch : Asset Management for PHP

php-EasyRdf.noarch : A PHP library designed to make it easy to consume and produce RDF

php-EasyRdf-doc.noarch : Documentation for php-EasyRdf

php-Faker.noarch : A PHP library that generates fake data

php-JsonSchema.noarch : PHP implementation of JSON schema

php-Metadata.noarch : A library for class/method/property metadata management in PHP

php-PHPMailer.noarch : PHP email transport class with a lot of features

php-PHPParser.noarch : A PHP parser written in PHP


엄청 많다..



필요한 것들이 설치가 안되어 있으므로 한꺼번에 설치한다.


[root@Cent7_64B conf.d]# yum -y install php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel



설치 후 아파치를 재시작한뒤 phpinfo를 확인해 보면 관련 모듈들이 설치되어 있을 것이다.




그동안 소스 설치로 많은 시간이 들었다면 이제는 yum으로 간편하게 설치하자.



끝.


'Linux' 카테고리의 다른 글

CentOS 7 apache virtualhost  (2) 2016.01.15
CentOS 7 iptables 설정  (1) 2016.01.15
CentOS 7 MySQL-5.7.10 설치 boost  (0) 2016.01.11
CentOS 7 network prefix  (0) 2015.12.04
리눅스 NFS설정  (0) 2015.09.25
블로그 이미지

엘로드넷

,