Created
June 26, 2017 09:19
-
-
Save g3rhard/b767a2e09abc74d9a07235ac5cc66d0f to your computer and use it in GitHub Desktop.
This file contains 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 | |
# Deploy on Ubuntu 16.04 WordPress CMS | |
# https://www.digitalocean.com/community/tutorials/wordpress-lamp-ubuntu-16-04-ru | |
# https://kaiten.support/how-to-automate-wordpress-and-wp-config-php-creation/ | |
#Задаем пароль для пользователя root для MySQL | |
SQL_PASSWORD="SQL_PASS" | |
DB_NAME="WP_DB_NAME" | |
DB_USER="WP_DB_USER" | |
DB_PASSWORD="WP_DB_PASS" | |
#Wordpress root directory | |
WP_ROOT="/var/www/html" | |
#Задаем имя sudo-пользователя для установки прав на папку Wordpress | |
SUDO_USER="SUDO_USER" | |
IP=$(ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}') | |
# Настраививаем автоматический ввод пароля для админа mysql. | |
# http://stackoverflow.com/a/7740571 | |
echo "mysql-server mysql-server/root_password password $SQL_PASSWORD" | debconf-set-selections | |
echo "mysql-server mysql-server/root_password_again password $SQL_PASSWORD" | debconf-set-selections | |
# Устанавливаем лампу (linux, apache, mysql, php) | |
tasksel install lamp-server | |
# проверяем установлены ли пакеты | |
apt install -y software-properties-common python-software-properties | |
#Добавляем плагины PHP для корректной работы WordPress | |
apt install -y php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc | |
a2enmod rewrite | |
systemctl restart apache2 | |
#создаем БД и пользователя для WordPress | |
mysql -u root -p$COOKIES_PASSWORD -e "CREATE DATABASE $DB_NAME DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;" | |
mysql -u root -p$COOKIES_PASSWORD -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASSWORD';" | |
mysql -u root -p$COOKIES_PASSWORD -e "FLUSH PRIVILEGES;" | |
#Установка WordPress | |
cd /tmp | |
wget https://wordpress.org/latest.tar.gz | |
tar xzvf latest.tar.gz | |
touch /tmp/wordpress/.htaccess | |
chmod 660 /tmp/wordpress/.htaccess | |
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php | |
mkdir /tmp/wordpress/wp-content/upgrade | |
cp -a /tmp/wordpress/. $WP_ROOT | |
cat <<EOF >> /etc/apache2/apache2.conf | |
<Directory $WP_ROOT/> | |
AllowOverride All | |
</Directory> | |
EOF | |
chown -R $SUDO_USER:www-data /var/www/html | |
find $WP_ROOT -type d -exec chmod g+s {} \; | |
chmod g+w $WP_ROOT/wp-content | |
chmod -R g+w $WP_ROOT/wp-content/themes | |
chmod -R g+w $WP_ROOT/wp-content/plugins | |
rm $WP_ROOT/wp-config.php | |
#готовим конфиг файл wp-config.php | |
WPSalts=$(wget https://api.wordpress.org/secret-key/1.1/salt/ -q -O -) | |
#generate a random string; lower and upper case letters + numbers; maximun 9 characters | |
TablePrefx=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 9 | head -n 1)_ | |
#Add the following PHP code inside wp-config | |
cat <<EOF > $WP_ROOT/wp-config.php | |
<?php | |
/***Managed by Kaiten Support - Leonardo Gandini***/ | |
define('DB_NAME', '$DB_NAME'); | |
define('DB_USER', '$DB_USER'); | |
define('DB_PASSWORD', '$DB_PASSWORD'); | |
define('DB_HOST', 'localhost'); | |
define('DB_CHARSET', 'utf8'); | |
define('DB_COLLATE', ''); | |
/*WP Tweaks*/ | |
#define( 'WP_SITEURL', '' ); | |
#define( 'WP_HOME', '' ); | |
#define( 'ALTERNATE_WP_CRON', true ); | |
#define('DISABLE_WP_CRON', 'true'); | |
#define('WP_CRON_LOCK_TIMEOUT', 900); | |
#define('AUTOSAVE_INTERVAL', 300); | |
#define( 'WP_MEMORY_LIMIT', '256M' ); | |
#define( 'FS_CHMOD_DIR', ( 0755 & ~ umask() ) ); | |
#define( 'FS_CHMOD_FILE', ( 0644 & ~ umask() ) ); | |
#define( 'WP_ALLOW_REPAIR', true ); | |
#define( 'FORCE_SSL_ADMIN', true ); | |
#define( 'AUTOMATIC_UPDATER_DISABLED', true ); | |
#define( 'WP_AUTO_UPDATE_CORE', false ); | |
$WPSalts | |
\$table_prefix = '$TablePrefx'; | |
define('WP_DEBUG', false); | |
if ( !defined('ABSPATH') ) | |
define('ABSPATH', dirname(__FILE__) . '/'); | |
require_once(ABSPATH . 'wp-settings.php'); | |
EOF | |
systemctl restart apache2 | |
echo "Your Wordpress ready on http://$IP/index.php !" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment