-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WSL Installation Upgrades and Documentation (#1958)
* WSL Installation Upgrades and Documentation - bin/homestead - Registered WslApplyFolderMapping command - scripts\features\mariadb.sh - stop the mysql service before uninstall and remove the installation tracking file. - scripts\features\mysql.sh - Create feature installation script for mysql. - scripts\features\postgresql.sh - removed `systemctl disable postgresq` from the end to make sure it works after the feature install - src\WslApplyFeatures.php - Changed the command name from wsl:apply-features to wsl:features. - src\WslApplyFolderMapping.php - Added new command to do folder mapping - src\WslCreateDatabaseCommand.php - Changed the command name from wsl:create-databases to wsl:databases. - src\WslCreateSiteCommand.php - Changed the command name from wsl:create-sites to wsl:sites. - Remove nginx/sites-enabled/* as well while removing existing nginx sites. - Add cron job for laravel schedule:run if mentioned in yaml file. - wsl.md - Documentation for Installing Homestead on Windows subsystem for Linux * Style CI Fix * Fixed a typo * Added validations for WSL_USER_NAME and WSL_USER_GROUP --------- Co-authored-by: Karmendra Suthar <karmendra.suthar@omniware.in>
- Loading branch information
Showing
10 changed files
with
510 additions
and
16 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ -f ~/.homestead-features/wsl_user_name ]; then | ||
WSL_USER_NAME="$(cat ~/.homestead-features/wsl_user_name)" | ||
WSL_USER_GROUP="$(cat ~/.homestead-features/wsl_user_group)" | ||
else | ||
WSL_USER_NAME=vagrant | ||
WSL_USER_GROUP=vagrant | ||
fi | ||
|
||
export DEBIAN_FRONTEND=noninteractive | ||
|
||
if [ -f /home/$WSL_USER_NAME/.homestead-features/mysql ]; then | ||
echo "Mysql already installed." | ||
exit 0 | ||
fi | ||
|
||
touch /home/$WSL_USER_NAME/.homestead-features/mysql | ||
chown -Rf $WSL_USER_NAME:$WSL_USER_GROUP /home/$WSL_USER_NAME/.homestead-features | ||
|
||
# Stop MariDB service | ||
service mariadb stop | ||
# Remove old PPA | ||
rm -f /etc/apt/sources.list.d/mariadb.list* | ||
# Remove MariaDB | ||
apt-get -o Dpkg::Options::="--force-confnew" remove -y --purge mariadb-server mariadb-client mysql-common | ||
apt-get autoremove -y | ||
apt-get autoclean | ||
|
||
rm -rf /var/lib/mysql/* | ||
rm -rf /var/log/mysql | ||
rm -rf /etc/mysql | ||
rm -r /home/$WSL_USER_NAME/.homestead-features/mariadb | ||
|
||
# Install MySQL | ||
echo "mysql-server mysql-server/root_password password secret" | debconf-set-selections | ||
echo "mysql-server mysql-server/root_password_again password secret" | debconf-set-selections | ||
apt-get install -y mysql-server | ||
|
||
# Configure MySQL 8 Remote Access and Native Pluggable Authentication | ||
mkdir -p /etc/mysql/conf.d | ||
cat > /etc/mysql/conf.d/mysqld.cnf << EOF | ||
[mysqld] | ||
bind-address = 0.0.0.0 | ||
disable_log_bin | ||
default_authentication_plugin = mysql_native_password | ||
EOF | ||
|
||
# Configure MySQL Password Lifetime | ||
echo "default_password_lifetime = 0" >> /etc/mysql/mysql.conf.d/mysqld.cnf | ||
|
||
# Configure MySQL Remote Access | ||
sed -i '/^bind-address/s/bind-address.*=.*/bind-address = 0.0.0.0/' /etc/mysql/mysql.conf.d/mysqld.cnf | ||
service mysql restart | ||
|
||
export MYSQL_PWD=secret | ||
|
||
mysql --user="root" -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'secret';" | ||
mysql --user="root" -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;" | ||
mysql --user="root" -e "CREATE USER 'homestead'@'0.0.0.0' IDENTIFIED BY 'secret';" | ||
mysql --user="root" -e "CREATE USER 'homestead'@'%' IDENTIFIED BY 'secret';" | ||
mysql --user="root" -e "GRANT ALL PRIVILEGES ON *.* TO 'homestead'@'0.0.0.0' WITH GRANT OPTION;" | ||
mysql --user="root" -e "GRANT ALL PRIVILEGES ON *.* TO 'homestead'@'%' WITH GRANT OPTION;" | ||
mysql --user="root" -e "FLUSH PRIVILEGES;" | ||
mysql --user="root" -e "CREATE DATABASE homestead character set UTF8mb4 collate utf8mb4_bin;" | ||
|
||
sudo tee /home/${WSL_USER_NAME}/.my.cnf <<EOL | ||
[mysqld] | ||
character-set-server=utf8mb4 | ||
collation-server=utf8mb4_bin | ||
EOL | ||
|
||
service mysql restart | ||
|
||
unset MYSQL_PWD |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Laravel\Homestead; | ||
|
||
use Laravel\Homestead\Settings\JsonSettings; | ||
use Laravel\Homestead\Settings\YamlSettings; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class WslApplyFolderMapping extends Command | ||
{ | ||
/** | ||
* Configure the command options. | ||
* | ||
* @return void | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('wsl:folders') | ||
->setDescription('Configure folder mapping in WSL from Homestead configuration') | ||
->addOption('json', null, InputOption::VALUE_NONE, 'Determines if the Homestead settings file will be in json format.'); | ||
} | ||
|
||
/** | ||
* Execute the command. | ||
* | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int | ||
*/ | ||
public function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
// Grab the current settings or create an example configuration | ||
$format = $input->getOption('json') ? 'json' : 'yaml'; | ||
$settings = $this->parseSettingsFromFile($format, []); | ||
|
||
foreach ($settings['folders'] as $key => $folder) { | ||
$folder_map = $folder['map']; | ||
$folder_to = $folder['to']; | ||
$parent_directory = dirname($folder_to); | ||
$folder_map_cmd = "rm -r {$folder_to} ; mkdir -p {$parent_directory} && ln -s {$folder_map} {$folder_to}"; | ||
$out = shell_exec($folder_map_cmd); | ||
print_r($out); | ||
$output->writeln('Created symbolic link '.$folder_to.' to '.$folder_map.'.'); | ||
} | ||
|
||
$output->writeln('WSL folders have been mapped!'); | ||
|
||
return 0; | ||
} | ||
|
||
/** | ||
* @param string $format | ||
* @param array $options | ||
* @return mixed | ||
*/ | ||
protected function parseSettingsFromFile(string $format, array $options) | ||
{ | ||
$SettingsClass = ($format === 'json') ? JsonSettings::class : YamlSettings::class; | ||
$filename = __DIR__."/../Homestead.{$format}"; | ||
|
||
return $SettingsClass::fromFile($filename)->toArray(); | ||
} | ||
} |
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
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
Oops, something went wrong.