Showing posts with label Notes on MySQL. Show all posts
Showing posts with label Notes on MySQL. Show all posts

Saturday, July 25, 2020

Installing Apache Webserver with PHP scripting, and MySQL and PostgreSQL PHP connection driver under Ubuntu 18.04 LTS (Bionic Beaver)

Clement L. Rasul 1.  Download and install the Apache webserver software

# apt-get install apache2

If there are errors displayed during the installation, issue the update command before repeating the installation command.

# apt-get update --fix-missing
# apt-get install apache2


2.  Download and install the PHP scripting language

# apt-get install php

If there are errors displayed during the installation, issue the update command before repeating the installation command.

# apt-get update --fix-missing
# apt-get install php libapache2-mod-php

3.  Download and install the MySQL database server PHP connection driver.

# apt-get install php-mysql

If there are errors displayed during the installation, issue the update command before repeating the installation command.

# apt-get update --fix-missing
# apt-get install php-mysql


4.  Download and install the PostgreSQL database server PHP connection driver as follows:

# apt-get install php-pgsql

If there are errors displayed during the installation, issue the update command before repeating the installation command.

# apt-get update --fix-missing
# apt-get install php-pgsql



5.  By default, the Apache webserver should be running after installation.  You should restart the Apache webserver in order to load the PHP, MySQL and PostgreSQL support.  Issue the command:

# systemctl restart apache2.service


6. To check if the Apache process is running, issue the command

# ps ax | grep apache2

This should produce a display similar to this if it is running:

23263 ?        Ss     0:00 /usr/sbin/apache2 -k start
23265 ?        S      0:00 /usr/sbin/apache2 -k start
23266 ?        S      0:00 /usr/sbin/apache2 -k start
23267 ?        S      0:00 /usr/sbin/apache2 -k start
23268 ?        S      0:00 /usr/sbin/apache2 -k start
23269 ?        S      0:00 /usr/sbin/apache2 -k start
25621 pts/0    S+     0:00 grep --color=auto apache2

If the apache2 process is not running, the display should just produce this entry:

6433 pts/0    S+     0:00 grep --color=auto apache2

7.  To test if the Apache webserver is running using an Internet browser, type the address where the webserver is running.  On the local machine, the address is 127.0.0.1 (also known as the loopback address).  This should display a page similar to this.


This is the default page of the Apache web server.


8.  To change the default page of the Apache webserver, remove the "index.html" file in the subdirectory "/var/www/html" and create a sample HTML file called "index.html" as follows:

# cd /var/www/html
# rm index.html
# vi index.html


< html >
< head >
< title > My First HTML Page < /title >
< /head >
< body >
Hello World!< /body >
< /html >

My assumption here is, you are familiar with using the vi text editor in Linux.  You may use your own preferred text editor to create the HTML file.  After refreshing your browser, the display should look like this.




9.  To test if the Apache webserver has PHP scripting support, create the following "test.php" file and place it in the subdirectory "/var/www/html".

# cd /var/www/html
# vi test.php

< ?php 
phpinfo();
? >

Type in the address bar of the browser "http://127.0.0.1/test.php", the browser should display a page similar to this.




10.  To know if the MySQL database PHP connection driver is installed, you should see and entry in the PHP test page similar to this:




11.  Likewise, to know if the PostgreSQL database PHP connection driver is installed, you should see an entry in the PHP test page similar to this:



12.  Should there be a need to uninstall the Apache webserver, shut down the running apache2 process first before uninstalling.

# systemctl stop apache2.service
# apt-get remove apache2



Thursday, April 16, 2009

Installing MySQL on Ubuntu

As always, various distributions of Linux have different ways of naming their software packages. In the case of Ubuntu 8.10 Linux, the software packages for MySQL database system are: "mysql-client" and "mysql-server". To install MySQL on Ubuntu, issue the following commands:

#apt-get install mysql-client
#apt-get install mysql-server

Friday, December 19, 2008

Solution to MySQL auto_increment Limitations

By default, MySQL's auto_increment column has a maximum number of 2,147,483,647. In practice, this number may even be less since the next NULL insert to the table will use the next value of the highest insert number. Consequently, once you have reached the maximum number, the next null insert will cause an error because of the occurrence of a duplicate key.

The solution to MySQL's auto_increment limitations is to create a primary key as an UNSIGNED BIGINT(20) type. As an example for the table "mytest", issue the following MySQL command:

>CREATE TABLE mytest(p_id BIGINT(20) UNSIGNED PRIMARY KEY AUTO_INCREMENT, name CHAR(10) );

The UNSIGNED BIGINT(20) type has a maximum number of 18,446,744,073,709,551,616. A SIGNED BIGINT(20) type has a maximum number of 9,223,372,036,854,775,807. Since you will be using this as a non-duplicating primary key in your table, most likely you will be using the UNSIGNED BIGINT(20) type since there is no need for storing negative values.

Thursday, December 18, 2008

Recovering Lost MySQL Password

The following are the steps on how to recover lost passwords in MySQL.

Steps:

1. Kill the MySQL daemon.

(the command on a RedHat-based system)
# /etc/rc.d/init.d/mysqld stop

2. Run the command:

# safe_mysqld --skip-grant-tables&
(on Fedora Core 5, the command is "mysqld_safe" instead of "safe_mysqld")

3. Go to the CLI.

#mysql
> use mysql
> update user set password=password('test123') where user='root' and host='localhost';
>\quit

4. Stop the MySQL

#mysqladmin -u root -p shutdown

5. Rerun MySQL

# /etc/rc.d/init.d/mysqld start

You can now access your database using the new password 'test123' as follows:

#mysql -u root -ptest123