skip to Main Content

I am trying to setup a local server in Ubuntu om Windows with WSL2. I am not a Linux expert by any measure and don’t know exactly what I am doing. Sorry for the long post but I have tried to give as much information as I can.

I have visited a number of sites for instructions (where it all just seems to work) and came up with the following:
Start Ubuntu on Windows 10
Follow the prompts to create the user ‘andrew’ with password ‘andrew’ then execute the following commands

sudo apt update && sudo apt upgrade
sudo apt-get install apache2 php7.4 libapache2-mod-php7.4 mysql-server php7.4-mysql
sudo apt-get install php-curl php-gd php-intl php-json php-mbstring php-xml
sudo service apache2 stop
sudo service mysql stop
sudo systemctl disable apache2
sudo systemctl disable mysql
sudo apt-get install adminer
echo "Alias /adminer.php /usr/share/adminer/adminer.php" | sudo tee /etc/apache2/conf-available/adminer.conf
sudo a2enconf adminer.conf
sudo service apache2 restart

ps shows apache is runnung as user www-data

sudo usermod -d /var/lib/mysql/ mysql
sudo service mysql start

ps shows mysql running as user mysql

sudo mysql
    CREATE USER 'andrew'@'localhost' IDENTIFIED BY 'andrew';
    GRANT ALL PRIVILEGES ON * . * TO 'andrew'@'localhost';
    FLUSH PRIVILEGES;
sudo vi /var/www/html/phpinfo.php
    <?php phpinfo();?>

Localhost/phpinfo/php displays correctly

sudo nano /etc/php/7.4/apache2/php.ini
    display_errors = On
    display_startup_errors = On
    error_reporting = E_ALL
   22  sudo a2enmod rewrite
   23  sudo service apache2 restart

localhost/adminer.php shows the adminer login page but I get "Access denied" when I try to log in as root or as andrew, with or without passwords.

I created a test script (stole it from here "Permission denied" error from Adminer with root@localhost I did not try the solution as I am not running SELinux)

<?php
$db = mysqli_connect('127.0.0.1','andrew','andrew')
  or die(mysqli_error());
var_dump($db);

Which does not throw any errors and displays db info which looks OK.
If I do the same with root and the password andrew (which I use for sudo) then I see two errors (do I need a different password for root?)

Warning: mysqli_connect(): (HY000/1698): Access denied for user
‘root’@’localhost’ in /var/www/html/sqltest.php on line 2

Warning: mysqli_error() expects exactly 1 parameter, 0 given in
/var/www/html/sqltest.php on line 3

If I

sudo mysql

and

SELECT User,Host FROM mysql.user;
+------------------+-----------+
| User             | Host      |
+------------------+-----------+
| andrew           | localhost |
| debian-sys-maint | localhost |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+

I can also

sudo mysqladmin status -u root -p
sudo mysqladmin status -u andrew -p
sudo mysql -u root -p
sudo mysql -u andrew -p

All using password andrew (so my sudo password does seem to work for root), but only as sudo, not as plain andrew

I don’t know where to go from here. How do I login to adminer?

2

Answers


  1. Chosen as BEST ANSWER

    I've been through the process again after resetting my Ubuntu instance in WSL2 and the adminer installation definitely works after a complete restart. There is something (I don't know what) that need restarting or reloading, besides the apache2 and mysql services.


  2. I am not knowing much about PHP and Windows with WSL2 but I think it is the same thing with Django. It seems like while trying to access your resources you get blocked due to the security reasons of ubuntu. so tries to grant access to your resources by the following command.

    $ chmod 664 ~/to/yourproject/directory/yoursqlname.sql
    $ sudo chown :www-data ~/to/yourproject/directory/yoursqlname.sql
    $ sudo chown :www-data ~/to/yourproject/directory/
    $ sudo chown :www-data ~/to/yourproject/directory/wsgifolder
    

    the below command will allow you to access your resource if you are not able to access them after running the above command. In short, the below command will help you access adminer

    $ sudo find -type d -exec chmod +x {} +
    

    then run the following command

     $ sudo systemctl restart apache2
     $ sudo systemctl reload apache2
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search