Tuesday 4 January 2022

 

Setup your own WAMP stack – Part III

In the previous two parts we have done with apache & php

Now we will be installing MySQL in our system

1. Download from https://dev.mysql.com/downloads community download page --> Windows downloads -- Without installer (zip file, unzip it in C:\mysql). I got it from Oracle.

2.Unzip the mysql-noinstall-5.x.xx-win32.zip to e.g. C:\ rename it to mysql

3. Uninstall any previous MySQL Windows service

Code:

mysqld.exe --remove

4. Copy one of the MySQL\*.ini files (usually my-large.ini) to MySQL\my.ini

5. Edit my.ini and change any parameters for your site.

5a. Sometimes it is possible that my.ini is not present. In that case search C:\Windows\my.ini or c:\Windows\my.cnf or c:\my.ini or c:\my.cnf. The system searches the my.ini file in these locations.  If nowhere it is found we have to create our own my.ini file in the directory c:\mysql, where we place all our mysql sub folders.

5b. Edit my.ini file (it is also a text file), it must contain the basedir and datadir to specify the location of mysql subfoldars and data location.

In my case it is:

#Path to installation directory. All paths are usually resolved relative to this.

#basedir="C:/Program Files/MySQL/MySQL Server 5.1/"

basedir="C:/mysql/"

 

#Path to the database root

#datadir="C:/Documents and Settings/All Users/Application Data/MySQL/MySQL Server 5.1/Data/"

datadir="C:/apache24/mydata/data/"

6. You can install mysqld.exe as a Windows service with

(see also : http://dev.mysql.com/doc/refman/5.6/en/windows-start-service.html )

Code:

To install the mysql service write in command line:

C:\mysql\bin>mysqld.exe –installß

Now do:

C:\mysql\bin>mysqld –initializeß

This may take some time. Please keep patience. After that the system database variable like root and temporary password and other will be initialized.

Secure the initial MySQL accounts MySQL access controls. Be aware that default both root and the anonymous account are set up with no password, so anyone can connect to the MySQL server as root.

In the data directory as mentioned in the my.ini file we will get a file with .err extension which will contain the temporary password for the root user of mysql.

We have to change this password in the following way:

C:\mysql\bin>mysql -l localhost -u root -p ß

Enter password: ***********

We will get the below message:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 22

Server version: 8.0.20 MySQL Community Server - GPL

 

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql>

Note: Common Error: C:\Apache24>mysql

If we type the above without username & password, we will get the following error:

ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)

We have to enter the temporary password we got from the said err file.

Now change the password for the user root@localhost in the following way:

mysql> ALTER USER 'root'@localhost IDENTIFIED WITH mysql_native_password BY 'abcdef';

Query OK, 0 rows affected (0.18 sec)

 

Optional:

7. Download phpmyadmin which is a good interface over your browser to manage mysql.

You can download phpMyAdmin from the page https://www.phpmyadmin.net/ from any web browser.

8a. unzip it to C:\Apache2\htdocs\ and rename it to phpMyAdmin

8b. You must put the folder phpMyAdmin inside the htdocs folder of Apache.

9. Now you should have access over http://localhost/phpmyadmin/

[Note: To make Apache able to run phpMyAdmin, the phpMyAdmin folder should be located inside document root folder of Apache. So, in this case it should be htdocs folder of apache root directory.]

Setup Apache-PHP-MySQL (All in short)

Finally, it is done.

From cli(Command Line Interface) I did.

1. apache 2.4 was previously installed from apache lounge

2. then after setting up httpd.conf file in c:\apache24\conf folder & setting the httpd-ssl.conf file in c:\apache24\conf\extra folder

a. I installed service by httpd --install

b. from windows services.msc ( to be ran from windows+R) windows apache can be started/restarted/stopped

c. from cli restart apache with c:\apache24\bin>httpd -k restart

d. all documents in browser are referenced from htdocs folder in c:\apache24 (as I set c:\apache24 as my root directory)

 

3.downloaded zip for php7, unpacked it, kept it in c:\php7 folder copied php.ini.production/php.ini.development to php.ini, done necessary modifications;

a. in c:\apache24\conf\httpd.conf file, made the necessary modifications for inclusion of php, include module fcgid if it is not there.

b. modify c:\apache24\conf\httpd.conf for securing ssl/tls

 

4. download mysql as zip from oracle

a. unpacked it in c:\mysqlxx.xx, renamed the folder as c:\mysql

b. install the service in services.msc window(seen on windows+r=>services.msc) from cli, by typing: mysqld --install(cant remember one or two hiphen), before that set the path for for mysql in env variables

c. there was no my.ini file in the system, created one in c:\mysql, specified the basedir and datadir there, specified some more options. saved it

d. created the folders as specified in my.in

e. from cli type:mysqld --initialize

f. it will take some time

g. after that check the data folder as mentioned in the datadir in my.ini(in my case c:\apache24\mydata\data), there must be an .err file. for me it was LAPTOP-419.....err. there will be the temporary password for root user

h. now start the mysql service from services.msc

i. now in cli type: mysql -h localhost -u root -p

j. it will ask for password

k. put that one from step g.

l. mysql prompt will come, change the password with alter user statement.

m. after that create new user, database, tables ,insert few data into table

n. now do the script php connect with data base with statement mysqli_connect(host, user, password, dbname, port)

o. it is successful

5. the last problem i faced that ' server authentication method unknown to the client' solved it this way:

 

C:\mysql>mysql -h localhost -u root -p

Enter password: ***************************************

The display Output:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 14

Server version: 8.0.20 MySQL Community Server - GPL

 

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> ALTER USER 'root'@localhost IDENTIFIED WITH mysql_native_password BY 'abcdef';

Query OK, 0 rows affected (0.18 sec)

 

Changing the password for another mysql user::

mysql> ALTER USER 'subhra'@localhost IDENTIFIED WITH mysql_native_password BY 'xyzmnopq';

Query OK, 0 rows affected (0.19 sec)

To exit mysql write \q at the mysql prompt.

mysql> \q

Bye

Now we can test our first web page on any browser. For this we have to create a web page test.html and put the following code in this html file. We can use Notepad++ as the editor.

<html>

          <head>

                   <title>This is a test Page</title>

          </head>

          <body>

                   <div>

                             <h1>Hello World!</h1>

                             <h2>Meet the New Idea</h2>

                   </div>

          </body>

</html>

Now open any web browser(like google chrome, Firefox, Internet Explorer etc.) and in the address bar write http://localhost/test1.html and press <-- [enter]

We will see the below test page on our browser:



Now we can make our desired web pages with html and php scripts with the help of mySql database. We can test our web pages in our local browsers and after completion we could upload out scripts to our desired domain server.