Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Install WordPress on ubuntu, PHP71 , apache, mysql, configure WordPress, wp-cli, phpUnit, WP Coding standards, letsencrypt
#set your servername and email here
mkdir /wpinstall
cd /wpinstall
#generate password for mysql
SQLPASSWORD=$(date +%s|sha256sum|base64|head -c 32)
echo $SQLPASSWORD >> password.txt
debconf-set-selections <<< "mysql-server mysql-server/root_password password $SQLPASSWORD"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $SQLPASSWORD"
# install lamp server
apt update
apt upgrade -y
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
apt -y install apache2 mysql-server php7.4 libapache2-mod-php php7.4-mysql php7.4-gd php7.4-xml php7.4-xdebug php7.4-mbstring php7.4-curl php-libsodium php7.4-imagick php7.4-zip subversion
# set php as default
SRC="index.html index.cgi index.php index.xhtml index.htm"; DST="index.php"; sed -i "s/$SRC/$DST/g" $CONFIG_FILE
# update the upload file size
SRC="upload_max_filesize = 2M"; DST="upload_max_filesize = 64M"; sed -i "s/$SRC/$DST/g" /etc/php/7.2/apache2/php.ini
# enable rewrite
a2enmod rewrite
SRC="AllowOverride None"; DST="AllowOverride All"; sed -i "s/$SRC/$DST/g" /etc/apache2/apache2.conf
# disable directory index
SRC="Options Indexes FollowSymLinks"; DST="Options -Indexes +FollowSymLinks"; sed -i "s/$SRC/$DST/g" /etc/apache2/apache2.conf
systemctl restart apache2
# download and copy wordpress to web folder
cd /wpinstall
tar xzvf latest.tar.gz
rsync -avP /wpinstall/wordpress/ /var/www/html/
touch /var/www/html/.htaccess
chown -R www-data:www-data /var/www/html/.htaccess
mkdir /var/www/html/wp-content/uploads
# remove apache default page
rm /var/www/html/index.html
# configure wordpress
cd /var/www/html
yes | cp wp-config-sample.php $CONFIG_FILE
#generate password
PASSWORD=$(date +%s|sha256sum|base64|head -c 32)+
SRC="'WP_DEBUG', false"; DST="'WP_DEBUG', true"; sed -i "s/$SRC/$DST/g" $CONFIG_FILE
SRC="'DB_NAME', 'database_name_here'"; DST="'DB_NAME', 'wordpress'"; sed -i "s/$SRC/$DST/g" $CONFIG_FILE
SRC="'DB_USER', 'username_here'"; DST="'DB_USER', 'wordpressuser'"; sed -i "s/$SRC/$DST/g" $CONFIG_FILE
SRC="'DB_PASSWORD', 'password_here'"; DST="'DB_PASSWORD', '$PASSWORD'"; sed -i "s/$SRC/$DST/g" $CONFIG_FILE
SRC="'WP_DEBUG'"; DST="define( 'SCRIPT_DEBUG', true );"; grep -q "$DST" $CONFIG_FILE || sed -i "/$SRC/a$DST" $CONFIG_FILE
#update authentication keys and salts.
SALT=$(curl -L
SRC="define(\s*'AUTH_KEY'"; DST=$(echo $SALT|cat|grep -o define\(\'AUTH_KEY\'.\\{70\\}); sed -i "/$SRC/c$DST" $CONFIG_FILE
SRC="define(\s*'SECURE_AUTH_KEY'"; DST=$(echo $SALT|cat|grep -o define\(\'SECURE_AUTH_KEY\'.\\{70\\}); sed -i "/$SRC/c$DST" $CONFIG_FILE
SRC="define(\s*'LOGGED_IN_KEY'"; DST=$(echo $SALT|cat|grep -o define\(\'LOGGED_IN_KEY\'.\\{70\\}); sed -i "/$SRC/c$DST" $CONFIG_FILE
SRC="define(\s*'NONCE_KEY'"; DST=$(echo $SALT|cat|grep -o define\(\'NONCE_KEY\'.\\{70\\}); sed -i "/$SRC/c$DST" $CONFIG_FILE
SRC="define(\s*'AUTH_SALT'"; DST=$(echo $SALT|cat|grep -o define\(\'AUTH_SALT\'.\\{70\\}); sed -i "/$SRC/c$DST" $CONFIG_FILE
SRC="define(\s*'SECURE_AUTH_SALT'"; DST=$(echo $SALT|cat|grep -o define\(\'SECURE_AUTH_SALT\'.\\{70\\}); sed -i "/$SRC/c$DST" $CONFIG_FILE
SRC="define(\s*'LOGGED_IN_SALT'"; DST=$(echo $SALT|cat|grep -o define\(\'LOGGED_IN_SALT\'.\\{70\\}); sed -i "/$SRC/c$DST" $CONFIG_FILE
SRC="define(\s*'NONCE_SALT'"; DST=$(echo $SALT|cat|grep -o define\(\'NONCE_SALT\'.\\{70\\}); sed -i "/$SRC/c$DST" $CONFIG_FILE
# create wordpress database
mysql -uroot -p$SQLPASSWORD -e "CREATE DATABASE wordpress;"
mysql -uroot -p$SQLPASSWORD -e "CREATE USER wordpressuser@localhost IDENTIFIED BY '$PASSWORD';"
mysql -uroot -p$SQLPASSWORD -e "GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY '$PASSWORD';"
chown -R www-data:www-data /var/www/html/*
# install wp-cli
chmod +x wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp --force
# install phpUnit
cd /wpinstall
chmod +x phpunit-6.5.8.phar
mv phpunit-6.5.8.phar /usr/local/bin/phpunit --force
# install PHP_CodeSniffer
chmod +x phpcs.phar
mv phpcs.phar /usr/local/bin/phpcs --force
chmod +x phpcbf.phar
mv phpcbf.phar /usr/local/bin/phpcbf --force
# configure WordPress Coding Standards
git clone -b master wpcs
phpcs --config-set installed_paths /wpinstall/wpcs
#install letsencrypt
echo "ServerName $SERVERNAME" >> /etc/apache2/apache2.conf
systemctl restart apache2
add-apt-repository ppa:certbot/certbot -y
apt-get update
apt-get -y install python-certbot-apache
certbot --apache -d $SERVERNAME --email=$EMAIL --agree-tos --non-interactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment