Home / SIDU


    How to install databases

    2013-01-01 00:00
    890477   0   2

    This msg is too old (originally written on 01 Jan 2013). Now its 22 May 2022 and PHP already ver 8, MySQL already ver 8. Let's re-write the wiki as following:

    Install ubuntu 22.04 LAMP via vagrant, PHP 8 MySQL 8 PostgreSQL 13 etc

    A - Install Git Bash for windows

    If you are already on Linux or Mac, this is optional.

    I m a bit confused of the name of this tool, called "Git Bash", on "gitforwindows.org", it says "Git for windows", when actually installed, it is called "MINGW64".

    This tool for windows is similar to linux terminal. Use Shift + Ctrl + C | V for copy and paste.

    B - Download the following if not yet

    B1 - Virtual Box: www.virtualbox.org

    B2 - Vagrant: vagrantup.com

    C - Make a project

    eg Let's call our new project as "sun", you can make this folder at any place.

    $ mkdir ~/sun
    $ cd ~/sun

    D - Install ubuntu 22.04

    search a linux box via app.vagrantup.com/boxes/search

    $ vagrant init alvistack/ubuntu-22.04

    Then you might need to init the box as per your need, the following is only an example, please update to your need:

    $ vim Vagrantfile

    Vagrant.configure("2") do |config|
    config.vm.box = "alvistack/ubuntu-22.04"
    config.vm.network "forwarded_port", guest: 80, host: 80
    config.vm.network "private_network", ip: "192.168.1.1"
    # next 2 lines need run after apache2 installed -- vagrant reload --provision
    # config.vm.synced_folder ".", "/vagrant", disabled: true
    # config.vm.synced_folder ".", "/var/www"
    end

    Then make the vagrant box

    $ vagrant up

    Once installed, SSH into the box

    $ vagrant ssh

    Check if Ubuntu 22.04 installed:

    $ lsb_release -a

    Check if you need upgrade ubuntu:

    $ sudo apt update
    $ sudo apt upgrade

    E - Install Apache2

    $ sudo apt install apache2

    And check after installed:

    $ apache2 -v

    Also you might need do the following:

    $ sudo ufw app list
    $ sudo ufw allow in "Apache Full"
    $ sudo ufw status
    $ sudo a2enmod rewrite
    ## php.net/manual/en/timezones.php
    $ sudo timedatectl set-timezone Australia/Sydney
    $ sudo service apache2 restart

    And check if the localhost working by open your browser and input this:

    http://localhost

    F - install PHP

    $ sudo apt install php libapache2-mod-php php-mysql
    $ sudo apt install sqlite3 php-curl php-xml php-mbstring php-zip
    $ sudo apt-get install php-sqlite3

    OR other versions eg php 7.2

    # sudo add-apt-repository ppa:ondrej/php --yes &> /dev/null
    # sudo apt update

    $ sudo apt install php7.2 libapache2-mod-php7.2 php7.2-mysql
    $ sudo apt install sqlite3 php7.2-curl php7.2-xml php7.2-mbstring php7.2-zip
    $ sudo apt-get install php7.2-sqlite3

    Your project might also need the following:

    $ sudo apt-get install php7.2-gd php7.2-soap php7.2-intl

    Check PHP version

    $ php -v

    G1 - install mariaDB

    $ sudo apt install mariadb-server

    Login into MariaDB

    $ sudo mysql

    Check date

    $ select now();

    Update root password

    $ SELECT * FROM mysql.user WHERE user = 'root';

    $ ALTER USER 'root'@'localhost' IDENTIFIED BY 'new-pass4root';
    $ FLUSH PRIVILEGES;

    G2 - Install MySQL 8

    # in case need to un-install mysql
    # sudo apt-get remove --purge mysql*

    $ sudo apt install mysql-server
    $ sudo mysql

    # do not install next line -- save time skip next line
    # sudo mysql_secure_installation

    # sudo vim /etc/mysql/my.cnf -- mysql.cnf no need to change
    [mysqld]
    default-time-zone = "+10:00"
    $ sudo service mysql restart
    $ sudo mysql –e "SELECT NOW();"

    $ SELECT host,user,plugin,authentication_string,Grant_priv FROM mysql.user;

    $ CREATE USER 'sun'@'localhost' IDENTIFIED BY 'password';
    # GRANT ALL PRIVILEGES ON *.* TO 'sun'@'locahost' WITH GRANT OPTION; -- this does not work
    $ GRANT ALL ON *.* TO 'sun'@'localhost' WITH GRANT OPTION;
    $ ALTER USER 'sun'@'localhost' IDENTIFIED WITH mysql_native_password BY 'pwd';

    $ CREATE DATABASE sun;
    $ GRANT CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT, REFERENCES on sun.* TO 'sun'@'localhost';
    $ FLUSH PRIVILEGES;

    H - install PostgreSQL

    $ sudo apt install postgresql postgresql-contrib
    $ sudo apt install php-pgsql
    $ sudo -i -u postgres psql ## login via cmd
    $ \password postgres ## input new password twice
    $ \q ## quit


    =============
    The following is the old wiki for installing PHP5 MySQL5 etc


    You need to check official websites as howto. Here is a quick guide for ubuntu users as howto install Apache2+PHP5, MySQL, PostgreSQL, SQLite, CUBRID, MSSQL

    A. Install apache2+php5: windows xampp; ubuntu:
    sudo apt-get install apache2 php5 libapache2-mod-php5 php5-gd

    B1. Install MySQL database and php driver: [optional]
    sudo apt-get install mysql-server mysql-client php5-mysql

    B2. Install PostgreSQL database and php driver: [optional]
    sudo apt-get install postgresql php5-pgsql
    Setup password for user postgres via terminal
    sudo -u postgres psql ## login via cmd
    \password postgres ## input new password twice
    \q ## exit psql

    B3. Install php driver for SQLite: [optional]
    sudo apt-get install php5-sqlite

    B4. Install CUBRID database and php driver: [optional]
    sudo add-apt-repository ppa:cubrid/cubrid
    sudo apt-get update
    sudo apt-get install cubrid php5-cubrid cubrid-demodb
    You need to start db each time on use:
    cubrid server start demodb

    B5. Install Microsoft SQL Server (MSSQL): [optional]
    sudo apt-get install freetds-common freetds-bin unixodbc php5-sybase

    C. Restart apache server: ubuntu
    sudo service apache2 restart
    Back « SIDU Support and Help Desk
    Next » Optional sidu_fk table

    Comments

    Leave a commentEdit comment

    Category