Last active
May 11, 2016 09:54
-
-
Save mamemomonga/b413a0dbf95dabfdaf1cdafb67d581ce to your computer and use it in GitHub Desktop.
phpビルド補助ツール
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# http://blog.mamemomonga.com/2016/05/lamp-php-debian8.html | |
use utf8; | |
use feature 'say'; | |
use strict; | |
use warnings; | |
binmode(STDOUT,':utf8'); | |
binmode(STDIN, ':utf8'); | |
binmode(STDERR,':utf8'); | |
package InvokePHP; | |
# aptitude install liblwp-protocol-https-perl | |
use LWP::Simple; | |
sub new { | |
my ($class,$self)=(shift,{@_}); | |
bless($self,$class); | |
return $self; | |
} | |
sub usage { | |
my $self=shift; | |
say "USAGE: $0 [ configure | ini | download ]"; | |
exit 255; | |
} | |
sub download { | |
my $self=shift; | |
my $phpver=$self->check_latest_php("7.0"); | |
say qq{wget -O php-$phpver.tar.xz http://jp2.php.net/get/php-$phpver.tar.xz/from/this/mirror} | |
} | |
sub configure { | |
my @opt=( | |
# [Apache 1.X] | |
# 'with-apxs', | |
# [Apache 2.X] | |
'with-apxs2=/usr/bin/apxs', | |
# 64bit | |
'with-libdir=lib64', | |
# php.d | |
'with-config-file-scan-dir=/usr/local/etc/php.d', | |
# [データベース] | |
'with-mysqli=mysqlnd', | |
'with-pdo-mysql', | |
'enable-mysqlnd', | |
# 'enable-embedded-mysqli', | |
# 'with-pgsql', | |
# 'with-pdo-pgsql', | |
# [マルチバイト] | |
'enable-mbstring', | |
'enable-mbregex', | |
# [アーカイブ] | |
'with-zlib', | |
'with-bz2', | |
'enable-zip', | |
# [いろいろ] | |
'with-openssl', | |
'with-pcre-regex', | |
'with-mcrypt', | |
# [画像処理関連] | |
'enable-exif', | |
'with-jpeg-dir', | |
'with-png-dir', | |
'with-xpm-dir', | |
'with-gd', | |
'enable-gd-jis-conv', | |
'enable-gd-native-ttf', | |
'enable-exif', | |
'with-freetype-dir=/usr/lib', | |
# [ネットワーク] | |
'enable-sockets', | |
'enable-ftp', | |
'with-curl', | |
'with-openssl', | |
# Zend OPcache | |
'enable-opcache', | |
); | |
# OCP - Opcache Control Panel | |
# https://gist.github.com/ck-on/4959032 | |
# intl対応(ICU4.2以上?が必要) | |
if(-d '/usr/local/icu48') { | |
push @opt,'enable-intl'; | |
push @opt,'with-icu-dir=/usr/local/icu48' | |
} | |
say join(' ',('./configure',map {"--$_"} @opt)); | |
} | |
sub ini { | |
my $self=shift; | |
say << '__END_OF_LINES__'; | |
#!/bin/sh | |
set -xe | |
mkdir -p /usr/local/etc/php.d | |
cat > /usr/local/etc/php.d/01_global.ini << 'EOS' | |
[PHP] | |
expose_php = off | |
short_open_tag = off | |
memory_limit = 256M | |
file_uploads = On | |
max_file_uploads = 20 | |
post_max_size = 20M | |
upload_max_filesize = 10M | |
display_errors = On | |
display_startup_errors = On | |
html_errors = On | |
log_errors = On | |
report_memleaks = On | |
error_reporting = E_ALL | |
error_log = /var/log/php/error.log | |
[Date] | |
date.timezone = Asia/Tokyo | |
EOS | |
cat > /usr/local/etc/php.d/02_opcache.ini << 'EOS' | |
[PHP] | |
zend_extension=opcache.so | |
[opcache] | |
opcache.memory_consumption=128 | |
opcache.interned_strings_buffer=8 | |
opcache.max_accelerated_files=4000 | |
opcache.revalidate_freq=60 | |
opcache.fast_shutdown=1 | |
opcache.enable_cli=0 | |
EOS | |
cat > /usr/local/etc/php.d/03_memcache.ini << 'EOS' | |
;[PHP] | |
;extension=memcache.so | |
;[Session] | |
;session.save_handler = memcache | |
;session.save_path = "tcp://localhost:11211" | |
EOS | |
__END_OF_LINES__ | |
} | |
sub check_latest_php { | |
my ($self,$release)=@_; | |
my $atom=get("http://www.php.net/releases/feed.php"); | |
while( $atom=~m#<link rel="enclosure" title="([^"]+)" href="([^"]+)">#mg ) { | |
my($title,$href)=($1,$2); | |
if($title=~/^PHP (\Q$release.\E(?:\d{1,2})) \Q(tar.gz)\E/) { return $1 } | |
} | |
} | |
package Main; | |
my $cmd=$ARGV[0] || ''; | |
my $iphp=InvokePHP->new(); | |
if($iphp->can($cmd)) { | |
$iphp->$cmd; | |
} else { | |
$iphp->usage; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment