How to install LAMP stack in OpenBSD

To install LAMP stack in OpenBSD

LAMP stands for Linux, Apache, MySQL & PHP. In this article we will learn how to install LAMP stack in OpenBSD.

To install Apache

Run the following command to install the apache web server.

# pkg_add apache-httpd 
quirks-2.241 signed on 2016-07-26T16:56:10Z
apache-httpd-2.4.23:db-4.6.21p3v0: ok
apache-httpd-2.4.23:apr-1.5.2: ok
apache-httpd-2.4.23:apr-util-1.5.4p1: ok
apache-httpd-2.4.23:apache-httpd-common-2.4.23: ok
apache-httpd-2.4.23: ok
The following new rcscripts were installed: /etc/rc.d/apache2
See rcctl(8) for details.


Start the apache web server by running the following command.

# /etc/rc.d/apache2 start                                                       
apache2(ok)


After starting the services, open the browser and enter your IP address to check its functionality.

To install MySQL

Next install the php-mysql package by running the following command.

# pkg_add php-mysql                                                             
quirks-2.241 signed on 2016-07-26T16:56:10Z
Ambiguous: choose package for php-mysql
a       0: 
        1: php-mysql-5.5.37p0
        2: php-mysql-5.6.23p0
Your choice: 2
php-mysql-5.6.23p0:mariadb-client-10.0.25v1: ok
php-mysql-5.6.23p0:femail-1.0p1: ok
php-mysql-5.6.23p0:femail-chroot-1.0p2: ok
php-mysql-5.6.23p0:php-5.6.23p0: ok
php-mysql-5.6.23p0: ok
The following new rcscripts were installed: /etc/rc.d/php56_fpm
See rcctl(8) for details.


Enable the php modules and create a soft link for it.

#ln -sf /var/www/conf/modules.sample/php-5.6.conf /var/www/conf/modules/php.conf 
You can enable this module by creating a symbolic link from
/etc/php-5.3.sample/mysql.ini  to /etc/php-5.3/mysql.ini.
  ln -sf /etc/php-5.6.sample/mysql.ini /etc/php-5.6/mysql.ini


To install mysql-server, utilize the following command.

# pkg_add mariadb-server 
quirks-2.241 signed on 2016-07-26T16:56:10Z
mariadb-server-10.0.25p0v1:p5-Net-Daemon-0.48p0: ok
mariadb-server-10.0.25p0v1:p5-PlRPC-0.2020: ok
..
..
..
mariadb-server-10.0.25p0v1:p5-DBI-1.633: ok
mariadb-server-10.0.25p0v1:p5-DBD-mysql-4.033: ok
mariadb-server-10.0.25p0v1: ok
The following new rcscripts were installed: /etc/rc.d/mysqld
See rcctl(8) for details.


Next run the mysql_install_db command as shown below.

# mysql_install_db 
Installing MariaDB/MySQL system tables in ' /var/mysql'  ...
160920  3:02:41 [Note] /usr/local/libexec/mysqld (mysqld 10.0.25-MariaDB) starting as process 26829 ...
160920  3:02:41 [Note] InnoDB: Using mutexes to ref count buffer pool pages
160920  3:02:41 [Note] InnoDB: The InnoDB memory heap is disabled
160920  3:02:41 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
.
.
.
http://dev.mysql.com
Support MariaDB development by buying support/new features from MariaDB
Corporation Ab. You can contact us about this at sales@mariadb.com.
Alternatively consider joining our community based development effort:
http://mariadb.com/kb/en/contributing-to-the-mariadb-project/


Start the mysql services by running the following command.

# /etc/rc.d/mysqld start 
mysqld(ok)


Then set password for the root user in mysql by using the following command.

# mysql_secure_installation                                                
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
..
..
..
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!
..
..
All done!  If you' ve completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!


Login to mysql server and create the Database.

# mysql -u root -p 
Enter password: 
Welcome to the MariaDB monitor.  Commands end with   or g.
Your MariaDB connection id is 11
Server version: 10.0.25-MariaDB OpenBSD port: mariadb-server-10.0.25p0v1
.
.
MariaDB [(none)]>  exit
Bye


To install phpmyadmin

Run the following command to install phpmyadmin.

# pkg_add phpMyAdmin 
quirks-2.241 signed on 2016-07-26T16:56:10Z
phpMyAdmin-4.5.5.1p0:t1lib-5.1.2p0: ok
phpMyAdmin-4.5.5.1p0:php-gd-5.6.23p0: ok
phpMyAdmin-4.5.5.1p0:php-mysqli-5.6.23p0: ok
phpMyAdmin-4.5.5.1p0:libmcrypt-2.5.8p2: ok
phpMyAdmin-4.5.5.1p0:php-mcrypt-5.6.23p0: ok
phpMyAdmin-4.5.5.1p0: ok
enable the php-gd module module 
#ln -sf /etc/php-5.3.sample/gd.ini /etc/php-5.3/gd.ini 
enable the php-mcrypt module
#ln -sf /etc/php-5.3.sample/mcrypt.ini /etc/php-5.3/mcrypt.ini 
point the phpMyAdmin directory  to the DocumentRoot of your web-server
# ln -s  /var/www/phpMyAdmin /var/www/htdocs/phpMyAdmin 
Restart the apache web server
# /etc/rc.d/apache2 restart                                                      
apache2(ok)
apache2(ok)


To verify php installation
Create a phpinfo.php file inside /var/www/htdocs/ directory.

#nano /var/www/htdocs/phpinfo.php 

Add the following lines to the file.

< ?php
phpinfo() 
?> 

Save the file and exit.


Open the browser and point to the URL https://< IP_address> /phpinfo.php

Login to the phpMyAdmin using the respective credentials.


To start all three services at boot

Open and edit the rc.conf.local file to start all the services at the boot point.

#nano /etc/rc.conf.local 
mysqld_flags=" " 
httpd_flags=" " 
pkg_scripts=" mysqld httpd php56_fpm" 
Tag : LAMP
FAQ
Q
How to destroy a session variable in a LAMP ?
A
To destroy Session_unregister() Unregister a global variable from the current session
Q
State how can you take a backup of the whole database in MySQL?
A
You can use the command line utility to take a backup of all the mysql table or a specific mysql table easily with the following:





mysqldump –-user [user_name] –-password=[password] [database_name] > [dump_file_name]
Q
How can I install two software at the same time in LAMP stack?
A
Yes, you can choose several applications but it gets installed one by one.
Q
How Can you increase the execution time of a php script in LAMP stack?
A
Yes, we can use the max_execution_time variable to set the desired time you needed for executing a php script.
Q
What is SQL Injection and how do you deal with that LAMP stack?
A
SQL injection is a technique utilized by hackers to get access into your database by using malicious SQL statements. Using this, anyone can gain complete access to your database without any authorization or permission.