Instalasi Apache, mariaDB dan PHP di OpenBSD

Berikut adalah langkah dalam instalasi apache :

# pkg_add  apache-httpd
# rcctl enable apache2
# rcctl start apache2

Untuk document root defaulnya ada di /var/www/htdocs

Berikut adalah langkah instalasi mariadb

# pkg_add mariadb-server mariadb-client
# rcctl enable mysqld
# rcctl start mysqld
# /usr/local/mariadb-install-db
# rcctl start mysqld
# rcctl restart mysqld
# mysql_secure_installation
Enter current password for root (enter for none) : enter
Switch to unix_socket authentication [Y/n] n
Change the root password ? [Y/n]Y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n]y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

mysql -u root -p

MariaDB [(none)]> ALTER USER root@localhost IDENTIFIED VIA mysql_native_password;
Query OK, 0 rows affected (0.021 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> SET PASSWORD = PASSWORD('passwordbaru');
Query OK, 0 rows affected (0.017 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.000 sec)

Membuat user :

MariaDB [(none)]> CREATE USER 'admin'@'localhost' IDENTIFIED BY 'passworduser';
Query OK, 0 rows affected (0.017 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.001 sec)

Membuat Database :

MariaDB [(none)]> Create database  kampus;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]>

Memberikan hak akses pada user :

MariaDB [(none)]> GRANT ALL PRIVILEGES ON kampus.* TO 'admin'@'localhost';
Query OK, 0 rows affected (0.015 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.001 sec)

Melihat hak akses user :

MariaDB [(none)]> SHOW GRANTS FOR 'admin'@'localhost';

Instalasi PHP

# pkg_add php
# rcctl enable php83_fpm
# rcctl start  php83_fpm
# pkg_add php-apache
# pkg_add php-mysqli
# ls -sf /var/www/conf/modules.sample/php-8.3.conf  /var/www/conf/modules/php.conf
# ln -sf /etc/php-8.3.sample/mysql.ini  /etc/php-8.3
# rcctl restart apache2 php83_fpm
# nano  /var/www/htdocs/info.php
<?
php phpinfo();
?>

Kemudian lakukan tes url http://localhost/info.php

Utuk testing koneksi ke database gunakan script ini :

<?php
# Fill our vars and run on cli
# $ php -f db-connect-test.php

$dbname = 'name';
$dbuser = 'user';
$dbpass = 'pass';
$dbhost = 'host';

$link = mysqli_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
mysqli_select_db($link, $dbname) or die("Could not open the db '$dbname'");

$test_query = "SHOW TABLES FROM $dbname";
$result = mysqli_query($link, $test_query);

$tblCnt = 0;
while($tbl = mysqli_fetch_array($result)) {
  $tblCnt++;
  #echo $tbl[0]."<br />\n";
}

if (!$tblCnt) {
  echo "There are no tables<br />\n";
} else {
  echo "There are $tblCnt tables<br />\n";
} 
?>

Leave a ReplyCancel reply