Last active
October 14, 2020 11:56
-
-
Save danielt69/d6066fde19f6cac15c6ef097af352485 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 | |
# Before you start this script, edit the following file: /etc/wsl.conf | |
# | |
# [automount] | |
# enabled = true | |
# options = "metadata" | |
# | |
FULL_NAME="" | |
USER_NAME="" | |
LINUX_USER_NAME="daniel" | |
read -p 'Type your full name inside double inverted commas: ' FULL_NAME | |
read -p 'Type your windows username: ' USER_NAME | |
read -p 'Type your linux username: ' LINUX_USER_NAME | |
cd ~ | |
sudo add-apt-repository -y ppa:ondrej/php | |
sudo apt-get -y update && sudo apt-get -y upgrade | |
sudo apt-get -y install build-essential lamp-server^ php-curl php-mbstring php-xml php-xdebug php-gd zip unzip sshpass dos2unix pv net-tools bridge-utils libssl-dev software-properties-common php7.4 wget git-core php-cli php-zip libapache2-mod-php php7.4-common php7.4-curl php7.4-mbstring php7.4-xml php7.4-xdebug php7.4-gd php7.4-mysql php7.4-xmlrpc php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-opcache php7.4-soap php7.4-zip php7.4-intl | |
sudo a2enmod php7.4 | |
echo "ServerName localhost" | sudo tee -a /etc/apache2/apache2.conf > /dev/null | |
echo "AcceptFilter http none" | sudo tee -a /etc/apache2/apache2.conf > /dev/null | |
sudo service apache2 restart | |
sudo usermod -d /var/lib/mysql/ mysql | |
sudo service mysql restart | |
# sudo mysql -uroot -ppassword -e "CREATE USER '$LINUX_USER_NAME'@'%' IDENTIFIED WITH mysql_native_password BY 'mySQL@123';" | |
# sudo mysql -uroot -ppassword -e "GRANT ALL ON *.* TO '$LINUX_USER_NAME'@'%';" | |
# install composer | |
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" | |
php -r "if (hash_file('sha384', 'composer-setup.php') === '795f976fe0ebd8b75f26a6dd68f78fd3453ce79f32ecb33e7fd087d39bfeb978342fb73ac986cd4f54edd0dc902601dc') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" | |
sudo php composer-setup.php --install-dir=/usr/bin --filename=composer | |
php -r "unlink('composer-setup.php');" | |
# instal nvm and nodejs | |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash | |
source ~/.bashrc | |
nvm install node | |
# install wp-cli | |
sudo curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar | |
sudo chmod +x wp-cli.phar | |
sudo sudo mv wp-cli.phar /usr/bin/wp | |
sudo wp cli update | |
# installing wp-completion.bash | |
wget https://raw.githubusercontent.com/wp-cli/wp-cli/v2.4.0/utils/wp-completion.bash | |
cat ~/wp-completion.bash >> ~/.bashrc | |
source ~/.bashrc | |
rm -rf ~/wp-completion.bash | |
# Creating a folder for WordPress files | |
mkdir -p /mnt/c/wsl/www/wp | |
cd /mnt/c/wsl/www/wp | |
sudo chsh -s /bin/bash www-data | |
sudo chown -hR www-data:www-data /var/www/ | |
# sudo -u www-data -i -- wp core download | |
sudo service mysql start | |
# sudo mysqld_safe --skip-grant-tables --skip-networking & | |
# sudo mysql_secure_installation | |
wp core download --locale=en_US | |
wp config create --dbname=wp --dbuser=wp --dbpass=password --dbhost=localhost --skip-check | |
wp config set WP_DEBUG true --raw | |
wp config set WP_DEBUG_LOG true --raw | |
# remove mariaDB : | |
# sudo apt -y purge mariadb-server mariadb-server-10.3 mariadb-server-core-10.3 | |
# mysql_secure_installation | |
# sudo mysqladmin -u root password "password" | |
# sudo mysql -u root -p"password" -e "UPDATE mysql.user SET Password=password('password') WHERE User='root'" | |
# # sudo mysql -u root -p"password" -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')" | |
# sudo mysql -u root -p"password" -e "DELETE FROM mysql.user WHERE User=''" | |
# sudo mysql -u root -p"password" -e "DROP DATABASE IF EXISTS test" | |
# sudo mysql -u root -p"password" -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\_%'" | |
sudo mysql -u root -p"password" -e "CREATE DATABASE wp" | |
# sudo mysql -u root -p"password" -e "CREATE USER 'wp'@'%' IDENTIFIED WITH mysql_native_password BY 'password';" | |
sudo mysql -u root -p"password" -e "CREATE USER 'wp'@'%' IDENTIFIED BY 'wp';" | |
# sudo mysql -u root -p"password" -e "GRANT ALL ON *.* TO 'daniel'@'%';" | |
sudo mysql -u root -p"password" -e "GRANT ALL PRIVILEGES ON *.* TO 'wp'@'%' WITH GRANT OPTION;" | |
sudo mysql -u root -p"password" -e "FLUSH PRIVILEGES" | |
sudo service mysql restart | |
# wp db create | |
# install Wordpress | |
wp core install --admin_user=admin --admin_password=password [email protected] --url=dev.local.com --title=wp --skip-email | |
sudo chown -hR www-data:www-data /mnt/c/wsl/www | |
# sudo -u www-data -i -- wp core config --dbname='wp' --dbuser='wp' --dbpass='wp' --dbhost='localhost' --dbprefix='wp_' | |
# sudo -u www-data -i -- wp core install --title='dev.local.com' --admin_user='admin' --admin_password='password' --url='http://dev.local.com' --admin_email='[email protected]'; | |
# admin password 5w2UD%pZLmHAR2oTA! | |
# ----------------------------------------------------- # | |
cd /etc/apache2/sites-available/ | |
sudo cp 000-default.conf dev.local.com.conf | |
sudo chmod 777 /etc/apache2/sites-available/dev.local.com.conf | |
sudo echo "<VirtualHost *:80> | |
ServerAdmin webmaster@localhost | |
ServerName dev.local.com | |
DocumentRoot /mnt/c/wsl/www/wp/ | |
ErrorLog ${APACHE_LOG_DIR}/error.log | |
CustomLog ${APACHE_LOG_DIR}/access.log combined | |
</VirtualHost>" > /etc/apache2/sites-available/dev.local.com.conf | |
sudo chmod 644 /etc/apache2/sites-available/dev.local.com.conf | |
sudo a2ensite dev.local.com.conf | |
sudo a2enmod rewrite | |
sudo service apache2 reload | |
# Alter the relevant details and save | |
# sudo vim /etc/hosts | |
sudo chmod 777 /etc/hosts | |
sudo echo "127.0.0.1 dev.local.com" >> /etc/hosts | |
sudo chmod 644 /etc/hosts | |
# Add 127.0.0.1 dev.local.com under 127.0.0.1 local.local.com | |
sudo service apache2 restart | |
# Add the same line to: C:\WINDOWS\System32\drivers\etc\hosts | |
//////////////////////////////////////////////////////////// | |
echo "All Done!" | |
echo "Navigate to http://dev.local.com to verify" | |
exit; | |
# //////////////////////////////////////////////////////////////////////// | |
# add https://stackoverflow.com/questions/46610256/chmod-wsl-bash-doesnt-work | |
# //////////////////////////////////////////////////////////////////////// | |
# # wsl settings: | |
# echo "" | |
# echo "" | |
# neofetch | |
# echo "" | |
# # http://bashrcgenerator.com/ | |
# export PS1="\[\033[38;5;197m\]\u\[$(tput sgr0)\]@\[$(tput sgr0)\]\[\033[38;5;14m\]\H\[$(tput sgr0)\] \t \d:\[$(tput sgr0)\]\[\033[38;5;202m\][\w]\[$(tput sgr0)\]: \[$(tput sgr0)\]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
download and run:
wget https://gist.githubusercontent.com/danielt69/d6066fde19f6cac15c6ef097af352485/raw/7728f48cc0ca0bfe0c287d57009921a2e5856f9f/wsl-lamp-wp5-setup.sh
chmod a+x wsl-lamp-wp5-setup.sh
sh wsl-lamp-wp5-setup.sh | & tee wsl-lamp-wp5-setup.log