Skip to content

Instantly share code, notes, and snippets.

@abola
Last active June 23, 2016 07:20
Show Gist options
  • Save abola/c49039dc4f1de71c5196 to your computer and use it in GitHub Desktop.
Save abola/c49039dc4f1de71c5196 to your computer and use it in GitHub Desktop.
WordPress-install-centos6.7.sh
#!/bin/sh
###
# This script will install wordpress on a pure CentOS 6.7 minimal
#
# Step 1. create a file and copy code from this Gist
# 2. check every configuration right
# 3. Do it!
# ex: /bin/sh /path/to/wp-install.sh
###
# @author Abola Lee<[email protected]>
###
# Default mysql root password
MYSQL_ROOT_PASSWORD="12345678"
# wordpress download source
WORDPRESS_SRC="https://tw.wordpress.org/wordpress-4.4.2-zh_TW.tar.gz";
# wordpress database connection info
WP_DB_NAME="wordpress"
WP_DB_USER="root"
WP_DB_PASS="12345678"
WP_DB_HOST="localhost"
WP_TITLE="Webcome"
WP_ADMIN_ACC="root"
WP_ADMIN_PW="12345678"
WP_ADMIN_EMAIL="[email protected]"
# Your wordpress host/ip
# !important DO NOT use localhost here
WP_HOST="192.168.56.103"
# ============= start install ==============
# Disable SElinux
mv /etc/selinux/config /etc/selinux/config.ori
echo "SELINUX=disabled" > /etc/selinux/config
echo "SELINUXTYPE=targeted" >> /etc/selinux/config
# allow 80 from iptables
# http://serverfault.com/questions/525801/iptables-appends-rule-default-after-a-input-j-reject-reject-with-icmp-host
iptables -N allow_services
iptables -I INPUT 5 -j allow_services
iptables -A allow_services -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
service iptables save
service iptables restart
# Install NTP service
yum -y install ntpdate
echo "# 每日校時" >> /var/spool/cron/root
echo "10 5 * * * /usr/sbin/ntpdate tock.stdtime.gov.tw" >> /var/spool/cron/root
echo "" >> /var/spool/cron/root
# Basic Tool package install
yum -y install wget
# Install httpd server
yum -y install httpd httpd-devel
# start httpd server
service httpd start
# set service on
chkconfig httpd on
# Install MySQL server
yum -y install mysql mysql-server mysql-devel mysql-libs
# start mysql server and set default root password
service mysqld start
/usr/bin/mysqladmin -u root password $MYSQL_ROOT_PASSWORD
# set service on
chkconfig mysqld on
# no password login, only for root account
echo "[mysql]" >> ~root/.my.cnf
echo "user=root" >> ~root/.my.cnf
echo "password=\"$MYSQL_ROOT_PASSWORD\"" >> ~root/.my.cnf
chmod 600 ~root/.my.cnf
# Install PHP
yum -y install php php-*
# Download and install wordpress
cd /var/www/html
curl $WORDPRESS_SRC | tar zxv
chown -R apache:apache wordpress/
echo 'create database '"$WP_DB_NAME"';' | mysql -u root
# setp 1. make wp-config.php
echo -e "<?php\n" > /var/www/html/wordpress/wp-config.php
# add salt from wordpress.org
curl https://api.wordpress.org/secret-key/1.1/salt/ >> /var/www/html/wordpress/wp-config.php
echo -e \
"define('DB_NAME','$WP_DB_NAME');\n"\
"define('DB_USER','$WP_DB_USER');\n"\
"define('DB_PASSWORD','$WP_DB_PASS');\n"\
"define('DB_HOST','$WP_DB_HOST');\n"\
"define('DB_CHARSET','utf8');\n"\
"define('DB_COLLATE','utf8_unicode_ci');\n"\
"\$table_prefix='wp_';\n"\
"define('WP_DEBUG', false);\n"\
"if("'!'"defined('ABSPATH'))define('ABSPATH', dirname(__FILE__) . '/');\n"\
"require_once(ABSPATH.'wp-settings.php');\n" >> /var/www/html/wordpress/wp-config.php
# step 2. add administrator and make page
curl -X POST \
-H "Cache-Control: no-cache" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'weblog_title='"$WP_TITLE"'&user_name='"$WP_ADMIN_ACC"'&admin_password='"$WP_ADMIN_PW"'&pass1-text='"$WP_ADMIN_PW"'&admin_password2='"$WP_ADMIN_PW"'&admin_email='"$WP_ADMIN_EMAIL"'&Submit=安裝 WordPress&=' \
"http://$WP_HOST/wordpress/wp-admin/install.php?step=2" >/dev/null 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment