Skip to content

Instantly share code, notes, and snippets.

@pvguerra
Last active August 31, 2018 18:20
Show Gist options
  • Save pvguerra/0064e7298cba513aa9d973fc712b6181 to your computer and use it in GitHub Desktop.
Save pvguerra/0064e7298cba513aa9d973fc712b6181 to your computer and use it in GitHub Desktop.
Vagrant - macOS - CentOS7

Vagrant on Mac OS 10.13.3 High Sierra

Create and configure lightweight, reproducible, and portable development environments. Vagrant is an amazing tool for managing virtual machines via a simple to use command line interface.

Vagrant uses Virtualbox to manage the virtual dependencies. You can directly download virtualbox and install or use homebrew for it.

$ brew cask install virtualbox
$ brew cask install vagrant

Vagrant Box

Add the Vagrant box you want to use:

$ vagrant box add centos7box https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.1.0/

You can find more boxes at Vagrant Cloud.

Now create a test directory and cd into the test directory. Then we'll initialize the vagrant machine.

$ vagrant init centos7box

Configuring Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "centos-7.0-x86_64"
  config.vm.hostname = "development.vm"
  config.vm.network "forwarded_port", guest: 80, host: 8080, auto_correct: true
  config.vm.network "forwarded_port", guest: 8000, host: 8000, auto_correct: true
  config.vm.network "forwarded_port", guest: 90, host: 9090, auto_correct: true
  config.vm.network "forwarded_port", guest: 9000, host: 9000, auto_correct: true
  config.vm.network "private_network", ip: "192.168.68.8"
  config.vm.network "public_network"
end

Now lets start the machine using the following command.

$ vagrant up

You can ssh into the machine now.

$ vagrant ssh

Halt the vagrant machine when need.

$ vagrant halt

Other useful commands are suspend, destroy etc.

Cent OS 7

Basic Configurations

$ yum -y install git nano unzip

Check the system locale specified on your server:

$ localectl status

You should see something like the following:

System Locale: LANG=de_DE.UTF-8
VC Keymap: de
X11 Layout: de

If you want to set up different system locale on your system, you can do that by using the localectl command. First, list the availables locales:

$ localectl list-locales

If you want to filter you can do that using the command below:

$ localectl list-locales | grep en

To set up a specific system locale:

$ localectl set-locale LANG=en_US.utf8

EPEL Repository

EPEL or Extra Package for Enterprise Linux is an additional package repository that provides useful software packages that are not included in the CentOS official repository. It can be installed on RPM based Linux distributions like CentOS and Fedora.

In this tutorial, we need the EPEL repository for the Nginx installation as Nginx packages do not exist in the official CentOS repository. Install the EPEL repository with the yum command below.

$ yum -y install epel-release

Update repolist:

$ yum -y repolist
$ yum -y update

Nginx

In this tutorial, we will run a Laravel under the LEMP Stack. Nginx is the web server part of the LEMP stack and can be installed from EPEL repository.

Install Nginx 1.10 from the EPEL repository with yum.

$ yum -y install nginx

When the installation is complete, start Nginx and add it to start at boot time.

$ systemctl start nginx
$ systemctl enable nginx

Nginx is running on port 80, check it with the netstat command below.

$ netstat -plntu | grep "nginx"

In case you get 'Command not found' as result, then install the net-tools package as shown below.

$ yum -y install net-tools

PHP-FPM 7.1

Laravel can be installed on a server with PHP version >= 5.6.4. In this tutorial, we will use the latest version PHP 7.1 that is supported by Laravel.

PHP 7.1 does not exist in the CentOS base repository, we need to install it from a third party repository named 'webtatic'.

Install the webtatic repository with this rpm command.

$ rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

Now we can install PHP-FPM with all of the extensions needed by Laravel with a single yum command.

$ yum -y install php71w php71w-curl php71w-common php71w-cli php71w-mysql php71w-mbstring php71w-fpm php71w-xml php71w-pdo php71w-zip

$ yum -y install php71w php71w-gd php71w-intl php71w-mbstring php71w-pdo php71w-process php71w-xml php71w-cli php71w-mcrypt php71w-fpm

PHP 7.1 has been installed on our CentOS 7 system.

Next, configure PHP by editing the configuration file php.ini with vim or nano.

$ nano /etc/php.ini

Uncomment the line below and change the value to 0.

cgi.fix_pathinfo=0

Save the file and exit the editor.

Now edit the PHP-FPM file www.conf.

$ nano /etc/php-fpm.d/www.conf

PHP-FPM will run under the user and group 'nginx', change the value of the two lines below to 'nginx'.

user = nginx

group = nginx

Instead of using the server port, PHP-FPM will run under a socket file. Change the 'listen' value to the path '/run/php-fpm/php-fpm.sock' as shown below.

listen = /run/php-fpm/php-fpm.sock

The socket file owner will be the 'nginx' user, and the permission mode is 660. Uncomment and change all values like this:

listen.owner = nginx

listen.group = nginx

listen.mode = 0660

For the environment variables, uncomment these lines and set the values as shown below.

env[HOSTNAME] = $HOSTNAME

env[PATH] = /usr/local/bin:/usr/bin:/bin

env[TMP] = /tmp

env[TMPDIR] = /tmp

env[TEMP] = /tmp

Save the file and exit nano, then start PHP-FPM and enable it to run at boot time.

$ systemctl start php-fpm
$ systemctl enable php-fpm

PHP-FPM is running under the socket file, check it with the command below.

$ netstat -pl | grep php-fpm.sock

The PHP and PHP-FPM 7.1 installation and configuration have been completed.

PostgreSQL

To install from the CentOS repositories, simply run:

$ sudo yum -y install postgresql-server postgresql-contrib

Initialize your Postgres database and start PostgreSQL:

$ postgresql-setup initdb
$ systemctl start postgresql
$ systemctl enable postgresql

PostgreSQL has been started and is running on port 5432, check it with the netstat command:

$ netstat -plntu | grep "postgres"

By default, PostgreSQL will create a Linux user named postgres to access the database software.

Change the postgres user’s Linux password:

$ passwd postgres

Issue the following commands to set a password for the postgres database user. Be sure to replace newpassword with a strong password and keep it in a secure place.

$ su - postgres
$ psql -d template1 -c "ALTER USER postgres WITH PASSWORD 'newpassword';"
$ exit

Note that this user is distinct from the postgres Linux user. The Linux user is used to access the database, and the PostgreSQL user is used to perform administrative tasks on the databases.

The password set in this step will be used to connect to the database via the network. Peer authentication will be used by default for local connections.

PHP Composer

PHP composer is a package manager for the PHP programming language. It has been created in 2011 and it's inspired by the Node.js 'npm' and Ruby's 'bundler' installer. Install composer with the curl command.

$ curl -vsS https://getcomposer.org/installer | php && yum install composer -y
$ mv composer.phar /usr/local/bin/composer
$ export COMPOSER_ALLOW_SUPERUSER=1
$ composer -v create-project laravel/laravel /usr/share/nginx/html/laravel

When the installation completed, try to use the 'composer' command and you will see the results as below.

$ composer

Configure Nginx Virtual Host for Laravel

In this step, we will create the nginx virtual host configuration for the Laravel project. We need to define the web root directory for this Laravel installation, I will use the '/var/www/laravel' directory as web root directory.

Create it with the mkdir command below:

$ mkdir -p /var/www/laravel

Next, go to the nginx directory and create a new virtual host configuration file laravel.conf in the conf.d directory.

$ nano /etc/nginx/conf.d/laravel.conf

Paste the configuration below into the file:

server {
        listen 80;
        listen [::]:80 ipv6only=on;
 
    # Log files for Debugging
        access_log /var/log/nginx/laravel-access.log;
        error_log /var/log/nginx/laravel-error.log;
 
    # Webroot Directory for Laravel project
        root /var/www/laravel/public;
        index index.php index.html index.htm;
 
        # Your Domain Name
        server_name laravel.hakase-labs.co;
 
        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }
 
    # PHP-FPM Configuration Nginx
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

Save the file and exit nano.

Test the nginx configuration and make sure there is no error, then restart the nginx service.

$ nginx -t
$ systemctl restart nginx
$ systemctl stop firewalld

The nginx virtual host configuration for Laravel has been completed.

Install Laravel

Now go to the laravel web root directory '/var/www/laravel'.

$ cd /var/www/laravel

Laravel provides two ways for the installation of the framework on the server. We can install Laravel with the laravel installer, and we can install it with PHP composer. In this tutorial, I will install Laravel by creating a new project with the composer command.

Run the command below to install Laravel:

$ composer create-project laravel/laravel .

When the installation is complete, change the owner of the Laravel web root directory to the 'nginx' user, and change the permission of the storage directory to 755 with the commands below.

$ chown -R nginx:root /var/www/laravel
$ chmod 755 /var/www/laravel/storage

Enable SELinux

First of all, let’s make sure that SELinux is running in enforcing mode globally.

$ setenforce 1

Default SELinux policy labels nginx and its associated files and ports with domain (type) httpd_t. So what we are going to do next is allow nginx to run in permissive mode. In this mode nginx (and php-fpm) will run without restrictions, but, Linux will log all SELinux related errors. Run:

$ semanage permissive -a httpd_t

Install Java Runtime Environment (Java JRE)

In CentOS, the JRE package is java-$(version)-openjdk. The openjdk-headless package contains a minimal implementation of the JDK for executing Java applications on the command line. In this example, you’ll install the minimal version of OpenJDK 8.

$ yum -y install java-1.8.0-openjdk-headless

After the installation finishes, verify its completion using.

$ yum list installed | grep "java"

The output should be:

java-1.8.0-openjdk-headless.x86_64   1:1.8.0.131-3.b12.el7_3           @updates
javapackages-tools.noarch            3.4.1-11.el7                      @base
python-javapackages.noarch           3.4.1-11.el7                      @base
tzdata-java.noarch                   2017b-1.el7                       @updates

Install the Java Development Kit (Java JDK)

$ yum -y install java-1.8.0-openjdk-devel

After the installation finishes, verify its completion using.

$ yum list installed | grep "openjdk-devel"

The output should be:

java-1.8.0-openjdk-devel.x86_64      1:1.8.0.131-3.b12.el7_3           @updates

DCM4CHEE Binaries

Create a folder to alocate the files:

$ mkdir ~/dcm4chee && cd ~/dcm4chee

Download binaries for dcm4chee:

$ wget https://ufpr.dl.sourceforge.net/project/dcm4che/dcm4chee/2.18.1/dcm4chee-2.18.1-psql.zip

Download the binary distribution of JBoss 4.2.3.GA from here and extract it into a different directory:

$ mkdir ../jboss && cd ../jboss
$ wget https://sourceforge.net/projects/jboss/files/JBoss/JBoss-4.2.3.GA/jboss-4.2.3.GA.zip

Unzip files:

$ unzip dcm4che-2.18.3-psql.zip
$ unzip jboss-4.2.3.GA.zip

Copy files from JBoss to dcm4chee.

Go to the dcm4chee-2.18.3-psql/bin directory and execute the install_jboss.sh script, with the path of your JBoss as installation directory as a parameter. In my case:

$ sh install_jboss.sh ../../../jboss/jboss-4.2.3.GA/

Create the DCM4CHEE Database

Edit the pg_hba.conf file in order to set the right permissions:

$ su - postgres
$ nano /data/pg_hba.conf
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                trust
#host    replication     postgres        127.0.0.1/32            trust
#host    replication     postgres        ::1/128                 trust

Now, create the database. If you are in dcm4chee-psql-2.18.1 directory, follow these commands:

$ export PGUSER=postgres
$ createdb pacsdb
$ psql pacsdb -f sql/create.psql

This will create all the database structure. Now we have to setup the database access from dcm4chee. In your dcm4chee installation, use a text editor to edit server/default/deploy/pacs-postgres-ds.xml and set the database password.

This file controls the dcm4chee connections to the main archive application database.

$ nano server/default/deploy/pacs-postgres-ds.xml

Probably will be necessary update the port 8080 where DCM4CHEE is normally running. In my case I choose the port 8081.

$ nano server/default/deploy/jboss-web.deployer/server.xml

Connect to the Web Interface at http://localhost:8081/dcm4chee-web3/ of the archive using any Web Browser. You should get the User Login Screen. Login in using default Administrator account ‘admin’, with password ‘admin’.

IPTables

The first step is to stop and mask the firewalld service:

$ systemctl stop firewalld
$ systemctl mask firewalld

Then, install the "iptables-services" package (if it is not already installed):

$ yum -y install iptables-services

Enable the service to start at boot-time:

$ systemctl enable iptables
$ systemctl enable ip6tables

Change "$IP_WAN" by your IP and "$IP_HOST" by host LAN IP:

$ iptables -t nat -A PREROUTING -p tcp -d $IP_WAN --dport 8080 -j DNAT --to $IP_HOST:8081

DICOM Toolkit and Library

Download and unzip binaries:

$ cd ~/dcm4chee
$ wget https://ufpr.dl.sourceforge.net/project/dcm4che/dcm4che2/2.0.29/dcm4che-2.0.29-bin.zip
$ unzip dcm4che-2.0.29-bin.zip
$ brew cask install java
$ ./dcmsnd DCM4CHEE@localhost:11112 /path/dicom/

Python / Django

PIP

$ easy_install pip

Now, go to the Django project directory:

$ pip install -r requirements.txt
@brunohcastro
Copy link

Usar TCP como protocolo do PHP-FPM para evitar abuso de disco.
mudar de:
listen = /run/php-fpm/php-fpm.sock
para:
listen = 0.0.0.0:9000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment