• Get In Touch
February 15, 2017

How to Install DreamFactory Open Source on CentOS 7

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

DreamFactory is a free and open source REST API middleware platform that provides RESTful services for building applications. It automatically generates a customizable and secure REST API for backend data resources. It also allows you to securely proxy to any remote REST or SOAP service and run your own custom APIs with DreamFactory. DreamFactory can be deployed on various platform and some of its features are listed below.

  • Instant API creation
  • Deep SQL support
  • Combine databases
  • Server-side scripting
  • Rock solid security
  • Live API docs
  • Run anywhere.

Prerequisites

You’ll need a CentOS 7 server and root user to follow this guide if in case you are logged in as non root user then run sudo -i command to switch to root user.

Updating System

It is recommended to update your system and available packages before installing DreamFactory open source on your server. To update your system run underneath command.

yum -y update

Installing Apache Web Server

Once the system is updated, you can install the dependencies required. To install DreamFactory open source you will need to install the Apache web server along with MaraiDB and PHP with a few extensions.

Run the following command to install the Apache web server.

yum -y install httpd

Now you can start Apache and enable it to start at boot time, using the following commands.

systemctl start httpd.service systemctl enable httpd.service

You can check the status of Apache web server using the following command.

systemctl status httpd

You should see following output:

[root@Sajid ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2017-02-13 13:13:01 UTC; 24s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 10553 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─10553 /usr/sbin/httpd -DFOREGROUND
           ├─10554 /usr/sbin/httpd -DFOREGROUND
           ├─10555 /usr/sbin/httpd -DFOREGROUND
           ├─10556 /usr/sbin/httpd -DFOREGROUND
           ├─10557 /usr/sbin/httpd -DFOREGROUND
           └─10558 /usr/sbin/httpd -DFOREGROUND

Feb 13 13:13:01 ip-172-31-17-249 systemd[1]: Starting The Apache HTTP Server...
Feb 13 13:13:01 ip-172-31-17-249 systemd[1]: Started The Apache HTTP Server.

We will need to install MariaDB for database purposes for DreamFactory. MariaDB 5.5 is shipped in the default CentOS 7 repository, so just run this command to install MariaDB.

yum -y install mariadb-server

Now you’ll have to start the MariaDB service and enable it to start at the boot time like we have done before for apache server, to do so please run following command.

systemctl start mariadb.service systemctl enable mariadb.service

You can check status of mariaDB using this below given command and you should see following output.

systemctl status mariadb.service

[root@Sajid ~]# systemctl status mariadb.service
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2017-02-13 13:14:40 UTC; 20s ago
 Main PID: 10703 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─10703 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─10860 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr...

Feb 13 13:14:38 ip-172-31-17-249 mariadb-prepare-db-dir[10624]: The latest information about Ma....
Feb 13 13:14:38 ip-172-31-17-249 mariadb-prepare-db-dir[10624]: You can find additional informa...:
Feb 13 13:14:38 ip-172-31-17-249 mariadb-prepare-db-dir[10624]: http://dev.mysql.com
Feb 13 13:14:38 ip-172-31-17-249 mariadb-prepare-db-dir[10624]: Support MariaDB development by ...B
Feb 13 13:14:38 ip-172-31-17-249 mariadb-prepare-db-dir[10624]: Corporation Ab. You can contact....
Feb 13 13:14:38 ip-172-31-17-249 mariadb-prepare-db-dir[10624]: Alternatively consider joining ...:
Feb 13 13:14:38 ip-172-31-17-249 mariadb-prepare-db-dir[10624]: http://mariadb.com/kb/en/contri.../
Feb 13 13:14:38 ip-172-31-17-249 mysqld_safe[10703]: 170213 13:14:38 mysqld_safe Logging to '/...'.
Feb 13 13:14:38 ip-172-31-17-249 mysqld_safe[10703]: 170213 13:14:38 mysqld_safe Starting mysq...ql
Feb 13 13:14:40 ip-172-31-17-249 systemd[1]: Started MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full.

We recommend you to make sure that this installation is secure and to do so run following command.

mysql_secure_installation

You’ll be asked to provide root password so enter appropriate password and answer yes to all questions by pressing Y.

Enter current password for root (enter for none): Just press the Enter button
Set root password? [Y/n]: Y
New password: your-root-password
Re-enter new password: your-root-password
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

Now you’ll have to create a database for DreamFactory so please follow the instructions.

mysql -u root -p

You’ll be asked to enter password so simply enter a password and now execute the following queries to create a new database.

CREATE DATABASE dreamfactory;

The above query will create a database named dreamfactory. For the database you can use any name you prefer in the place of dreamfactory. Make sure that you use semicolon at the end of each query as a query always ends with a semicolon. Once the database is created you can create a new user and grant the required permissions to the user for the database.

CREATE USER 'df_user'@'localhost' IDENTIFIED BY 'StrongPassword';

The above query will create a user with username df_user. You can use any preferred username instead of df_user. Replace StrongPassword with a strong password.

Now provide the appropriate privileges to your database user over the database you have created. Run the following query to do so.

GRANT ALL PRIVILEGES ON dreamfactory.* TO 'df_user'@'localhost';

Now run the following query to immediately apply the changes on the database privileges.

FLUSH PRIVILEGES;

Now you can exit from MariaDB prompt using following command.

\q.

We will have to install PHP 7.1. To do so run following commands as shown below.

yum -y install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

Now use this command to install PHP 7.1 and required extensions.

yum install mod_php71w php71w-common php71w-cli php71w-gd php71w-mbstring php71w-mcrypt php71w-xml php71w-mysqlnd php71w-pecl-mongodb -y

Next you’ll have to restart your apache web server to load new components that we just configured and use following command to restart apache web server.

systemctl restart httpd.service

Installing Composer

You’ll have to install composer first to install DreamFactory software so let’s install latest release of composer and please execute below given commands to do so.

cd
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php -r "if (hash_file('SHA384', 'composer-setup.php') === '55d6ead61b29c7bdee5cccfb50076874187bd9f21f65d8991d46ec5cc90518f447387fb9f76ebae1fbbacf329e583e30') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php

php -r "unlink('composer-setup.php');"

We have installed composer successfully and now you’ll need to make it globally accessible so you’ll have to move files and you can do so by running underneath command, it will do the job for you.

mv composer.phar /usr/local/bin/composer

Installing DreamFactory

Once you have installed all the dependencies required then now you are ready to install DreamFactory. DreamFactory open source software is available in the github repository so install git and download latest stable release of DreamFactory, to do so run following commands.

yum -y install git
wget https://github.com/dreamfactorysoftware/dreamfactory/archive/2.4.2.tar.gz

We have downloaded DreamFactory and no we have extract it so run below given commands to extract it and install required dependencies.

tar -zxvf 2.4.2.tar.gz
cd dreamfactory-2.4.2

If in case you don’t have composer package installed on your system then you can install it using yum -y install composer

composer install --no-dev

The above command may take some moments so you’ll have to wait until it finished.

mv ~/dreamfactory-2.4.2 /opt

Next set proper ownership to the software using below given commands:

chown -R root:root /opt/dreamfactory-2.4.2

chown -R apache:apache /opt/dreamfactory-2.4.2/storage/ /opt/dreamfactory-2.4.2/bootstrap/cache/

chmod -R 2775 /opt/dreamfactory-2.4.2/storage/ /opt/dreamfactory-2.4.2/bootstrap/cache/

Next change your directory to /opt/dreamfactory-2.4.2 and create a .env file to store DreamFactory configuration and you can do so using these commands as shown.

cd /opt/dreamfactory-2.4.2
php artisan dreamfactory:setup

Next input database details as shown below:

 Which database would you like to use for system tables? [sqlite]:
  [0] sqlite
  [1] mysql
  [2] pgsql
  [3] sqlsrv
 > 1

 Enter your mysql Host:
 > localhost

 Enter your database name:
 > dreamfactory

 Enter your database username:
 > df_user

 Enter your database password:
 > yourpassword

 Re-enter your database password:
 > yourpassword

 Enter your Database Port [3306]:
 > 3306

Run same command again to set up admin details.

php artisan dreamfactory:setup

Enter your admin details as shown below:

Creating the first admin user...

 Enter your first name:
 > Sajid

 Enter your last name:
 > Qureshi

 Enter display name:
 > Sajid Qureshi

 Enter your email address?:
 > me@sajidbhaijaan.net

 Choose a password:
 > <your-admin-password>

 Re-enter password:
  > <your-admin-password>

Creating a Virtual Host

You’ll need to set up a virtual host for DreamFactory, you can do that using any text editor here we are using nano text editor if in case you don’t have nano editor then you can install it using yum -y install nano and run this command to create a virtual host configuration file.

nano /etc/httpd/conf.d/dreamfactory.conf

Add below given content to the file and replace the values of ServerAdmin, ServerName, ServerAlias, Errorlog, and CustomLog with your own ones.

<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /opt/dreamfactory-2.4.2/public/
ServerName dreamfactory.example.com
ServerAlias www.dreamfactory.example.com
<Directory /opt/dreamfactory-2.4.2/public/>
Options FollowSymLinks
AllowOverride All
AllowOverride None
Require all granted
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [L]
<LimitExcept GET HEAD PUT DELETE PATCH POST>
    Allow from all
</LimitExcept>
</Directory>
ErrorLog /var/log/httpd/dreamfactory.example.com-error_log
CustomLog /var/log/httpd/dreamfactory.example.com-access_log common
</VirtualHost>

Save the file and exit from the text editor and restart your apache web server using this command to apply changes that we have just made.

systemctl restart httpd.service

Finally you’ll have to modify firewall rules so if in case you don’t have firewalld services installed on your server then you can install it using yum -y install firewalld and you can start it using systemctl start firewalld

Next run these below given commands to modify the firewalld rules.

firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --reload

Next temporarily disable SELinux services and then restart your apache web server using these commands as shown.

setenforce 0
systemctl restart httpd

Web Access

Open up your favorite web browser and visit http://yourserverIP to access DreamFactory and log in using admin email address and password.

HP_NO_IMG/data/uploads/users/744ed2f1-2baa-42b2-b09d-ad15a2ae3934/957599826.png” alt=” ” />

By clicking on log in button you’ll see admin dashboard like this shown below and you can turn your database into a RESTful API platform using it.

HP_NO_IMG/data/uploads/users/744ed2f1-2baa-42b2-b09d-ad15a2ae3934/953115981.png” alt=” ” />

Conclusion

In this tutorial you have learned how to install and configure DreamFactory open source software on your CentOS 7 server. We hope now you have enough knowledge to work with DreamFactory.

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]