Last active
December 18, 2015 03:49
-
-
Save pacojp/5721025 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# | |
# # sample usage | |
# curl -o /tmp/install_wordpress.sh https://gist.github.com/pacojp/5721025/raw | |
# /bin/bash /tmp/install_wordpress.sh ${HOSTNAME} | |
# | |
WORDPRESS_VERSION=3.5.1 | |
# Make sure only root can run our script | |
if [ "$(id -u)" != "0" ]; then | |
echo "This script must be run as root" 1>&2 | |
exit 1 | |
fi | |
if [ $# -ne 1 ]; then | |
echo "ホスト名を引数で指定して下さい ./install_wordpress.sh <HOSTNAME>" 1>&2 | |
exit 1 | |
fi | |
HOSTNAME=$1 | |
HOSTNAME_UL=`echo "$1" | sed 's/\./_/g'` | |
yum install -y php54-fpm php54-devel php54-cli php54-xml php54-mbstring php54-gd | |
if [ -f "/etc/my.cnf" ]; | |
then | |
echo "my.cnf already exists. skip installing mysql." | |
else | |
curl -o /tmp/install_mysql_server.sh https://gist.github.com/pacojp/5707825/raw | |
/bin/bash /tmp/install_mysql_server.sh | |
/etc/init.d/mysql start | |
fi | |
# mv httpd script & erace old files | |
mv /etc/init.d/httpd /etc/init.d/httpd_old | |
if [ -d "/var/www/" ]; then | |
mv /var/www /var/www_old | |
fi | |
mkdir -p /var/www | |
useradd nginx | |
chown nginx:root /var/www | |
if [ -d "/etc/nginx/" ]; then | |
echo "eginx already installed"; | |
else | |
curl -o /tmp/install_nginx.sh https://gist.github.com/pacojp/5704628/raw | |
/bin/bash /tmp/install_nginx.sh | |
curl -o /etc/nginx/nginx.conf https://gist.github.com/pacojp/5722674/raw | |
mkdir -p /var/log/nginx/${HOSTNAME} | |
chown nginx /var/log/nginx/${HOSTNAME} | |
mkdir -p /etc/nginx/conf.d | |
curl -o /etc/nginx/conf.d/${HOSTNAME}.conf https://gist.github.com/pacojp/5722706/raw | |
sed -i "s/example\.com/${HOSTNAME}/g" /etc/nginx/conf.d/${HOSTNAME}.conf | |
mkdir -p /var/www/${HOSTNAME}/public_html | |
mkdir -p /var/www/${HOSTNAME}/logs | |
chown -R nginx:root /var/www/* | |
echo 'hello world' > /var/www/${HOSTNAME}/public_html/index.html | |
echo '<?php phpinfo() ?>' > /var/www/${HOSTNAME}/public_html/phpinfo.php | |
sed -i "s/= apache/= nginx/g" /etc/php-fpm.d/www.conf | |
sed -i "s/listen = 127.0.0.1:9000/listen = \/var\/run\/php-fpm.sock/g" /etc/php-fpm.d/www.conf | |
sed -i "s/pm = dynamic/pm = static/g" /etc/php-fpm.d/www.conf | |
sed -i "s/m.max_children = 50/m.max_children = 5/g" /etc/php-fpm.d/www.conf | |
cd /var/www/${HOSTNAME}/ | |
#wget http://wordpress.org/latest.tar.gz | |
#tar -xzvf latest.tar.gz | |
wget http://ja.wordpress.org/wordpress-${WORDPRESS_VERSION}-ja.tar.gz | |
tar -xzvf wordpress-${WORDPRESS_VERSION}-ja.tar.gz | |
mv /var/www/${HOSTNAME}/wordpress/* /var/www/${HOSTNAME}/public_html/ | |
rm -rf /var/www/${HOSTNAME}/wordpress | |
mv /var/www/${HOSTNAME}/public_html/wp-config-sample.php /var/www/${HOSTNAME}/public_html/wp-config.php | |
# customize wp-config.php | |
sed -i "s/database_name_here/${HOSTNAME_UL}/g" /var/www/${HOSTNAME}/public_html/wp-config.php | |
sed -i "s/username_here/wp_user/g" /var/www/${HOSTNAME}/public_html/wp-config.php | |
sed -i "s/password_here//g" /var/www/${HOSTNAME}/public_html/wp-config.php | |
for a in $(seq 1 10); | |
do | |
sed -i "0,/put your unique phrase here/s/put your unique phrase here/`cat /dev/urandom | tr -dc '[:alnum:]' | head -c 60`/" /var/www/${HOSTNAME}/public_html/wp-config.php; | |
done; | |
sed -i "s/'WPLANG', ''/'WPLANG', 'ja'/g" /var/www/${HOSTNAME}/public_html/wp-config.php | |
sed -i "s/require_once(ABSPATH . 'wp-settings.php');//g" /var/www/${HOSTNAME}/public_html/wp-config.php | |
cat <<EOF >> /var/www/${HOSTNAME}/public_html/wp-config.php | |
define('WP_SITEURL', 'http://${HOSTNAME}'); | |
define('FORCE_SSL_ADMIN', true); | |
define('FORCE_SSL_LOGIN', true); | |
if (\$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') | |
\$_SERVER['HTTPS']='on'; | |
require_once(ABSPATH . 'wp-settings.php'); | |
EOF | |
cat <<EOF | mysql -u root | |
CREATE DATABASE \`${HOSTNAME_UL}\`; | |
GRANT ALL PRIVILEGES ON \`${HOSTNAME_UL}\`.* TO "wp_user"@"localhost"; | |
FLUSH PRIVILEGES; | |
EOF | |
cat <<EOF | |
installing almost done!! | |
you should do few steps below. | |
1. change mysql user password | |
echo "SET PASSWORD FOR wp_user@\"localhost\"=PASSWORD('newpasswordhere');" | mysql -u root | |
2. edit /var/www/${HOSTNAME}/public_html/wp-config.php (rewrite password phrase). | |
define('DB_PASSWORD', 'newpasswordhere'); | |
3. make robots.txt likie below (/var/www/${HOSTNAME}/public_html/robots.txt). | |
================================================= | |
User-Agent: * | |
Disallow: /wp-admin/ | |
Disallow: /wp-includes/ | |
Disallow: /wp-content/ | |
Disallow: /wp-content/plugins | |
Disallow: /wp-content/cache | |
Disallow: /wp-content/themes | |
Disallow: /*? | |
Disallow: /*.php$ | |
Disallow: /*.css$ | |
Disallow: /*.js$ | |
User-agent: Googlebot-Image | |
Disallow: / | |
Sitemap: http://${HOSTNAME}/sitemap.xml | |
================================================= | |
4. start servers | |
/etc/init.d/php-fpm start | |
/etc/init.d/nginx start | |
5. access http://${HOSTNAME}/wp-admin/install.php | |
EOF | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment