Skip to content

For those that would like to run MEDUSA locally on CentOS 7.x with SELinux enforcing

Douglas Needham edited this page Feb 11, 2021 · 14 revisions

For those that would like to run MEDUSA locally on CentOS 7.x with SELinux enforcing

DOCUMENT IN PROGRESS

Step-by-step guide

  1. Install PHP 7.4 (https://computingforgeeks.com/how-to-install-php-7-4-on-centos-7/)

    1. Install the EPEL and REMI repositories

      yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
      yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
      
    2. Enable the PHP 7.4 repository

      yum -y install yum-utils
      yum-config-manager --enable remi-php74
      
    3. Install PHP 7.4 and related PHP components

      yum update
      yum install -y php php-cli php-devel php-fpm php-pear composer
      
  2. Install the following packages with yum (nominal versions in parenthesis).

    • git (1.8.3)
    • indent (2.2.11)
    • ImageMagick (6.9.10)
    • ImageMagick-devel (6.9.10)
    • sassc (3.4.5)
    yum install -y git indent ImageMagick ImageMagick-devel sassc
    
  3. Install nginx (https://www.nginx.com/resources/wiki/start/topics/tutorials/install/)

    1. Create the repo file (/etc/yum.repos.d/nginx.repo) with the following:

      cat > /etc/yum.repos.d/nginx.repo <<'EOD'
      [nginx]
      name=nginx repo
      baseurl=https://nginx.org/packages/centos/$releasever/$basearch/
      gpgcheck=0
      enabled=1
      EOD
      
    2. Install nginx

      yum install nginx
      
    3. Enable and start the nginx server

      systemctl enable --now nginx
      
  4. Install node.js 14.x (from https://github.com/nodesource/distributions)

    curl -sL https://rpm.nodesource.com/setup_14.x | bash -
    yum install -y nodejs
    
  5. Install Mongodb 4.4 (https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-centos-7)

    1. Create the repo file (/etc/yum.repos.d/mongodb-org.repo) with the following:

      cat > /etc/yum.repos.d/mongodb-org.repo <<'EOD'
      [mongodb-org-4.4]
      name=MongoDB Repository
      baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/
      gpgcheck=1
      enabled=1
      gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
      EOD
      
    2. Install mongodb

      yum install -y mongodb-org
      
    3. Enable and start the mongodb server

      systemctl enable --now mongod
      
  6. Install Redis 6.0 (https://computingforgeeks.com/how-to-install-latest-redis-on-centos-7/)

    yum --enablerepo=remi install redis
    systemctl enable --now redis
    
  7. Enable PHP-FPM.

    systemctl enable --now php-fpm
    
  8. Install required PHP modules. Accept the default option for any prompts. Make sure you do this in either the same terminal window where you executed source ~/.bash_profile or a new terminal window created after you added the php path to the front of the search path, so pecl will find the correct php.ini file.

    pecl install mongodb 
    pecl install imagick 
    pecl install redis
    

    After the all the modules have been installed, verify that you have the following lines in files in /etc/php.d with a numeric prefix greater than that for json (e.g. 20-json.ini but 40-redis.ini) (https://ystatit.medium.com/cannot-find-redio-so-on-centos7-with-php7-bfffdece5ead)

    cat > /etc/php.d/40-imagick.ini <<EOD
    ; Enable imagick extension module
    extension="imagick.so"
    EOD
    
    cat > /etc/php.d/40-redis.ini <<EOD
    ; Enable redis extension module
    extension="redis.so"
    EOD
    
    cat > /etc/php.d/40-mongodb.ini <<EOD
    ; Enable mongodb extension module
    extension="mongodb.so"
    EOD
    
  9. Configure php-fpm. Edit /etc/opt/remi/php74/php-fpm.d/www.conf and change the listen line to

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

    and make sure these three lines are also included:

    listen.owner = nginx
    listen.group = nginx
    listen.mode = 0660
    

Now, as a regular user...

  1. Clone the MEDUSA repo in the directory of your choice (~/sites is good choice)

    git clone https://github.com/TRMN/medusa.git

  2. Copy .env.example to .env

    cd ~/sites/medusa
    cp .env.example .env
    
  3. Create the required framework directories under the application directory

    mkdir -p storage/framework/cache storage/framework/sessions storage/framework/views
    
  4. Edit the .env file and configure the database

  5. Install the required PHP dependencies.

    cd ~/sites/medusa
    composer install
    
  6. Generate the application key

    php artisan key:generate
    
  7. Install the required node dependencies to generate css from scss files and to minify javascript.

    cd ~sites/medusa
    npm install
    npm audit fix
    

Again as root...

  1. Copy server_configurations/nginx/medusa.dev from your clone to /etc/nginx/conf.d/medusa.dev.conf. Edit /etc/nginx/conf.d/medusa.dev.conf and adjust the paths (which use /path/to as a hint) as needed.

  2. Check to see that your chosen port is open with the firewall.

    firewall-cmd --list-all
    

    If the port is not open, use a command such as:

    firewall-cmd --permanent --add-port=8080/tcp
    firewall-cmd --reload
    

    If in doubt of what ports are a part of a service, you can consult the files under /usr/lib/firewalld/services, or use a command such as

    grep 8080 /usr/lib/firewalld/services/*
    

    to see if there is any pre-existing service which makes sense to use instead of the direct port number. (In this case, none do.)

  3. Set the SELinux file context for the source directory if not cloned into /var/www/html. Here, ~/sites is taken to mean /home/medusa/sites.

    semanage fcontext -a -e /var/www/html '/home/medusa/sites(/.*)?'
    

    Regardless of directory, the following will also doubtless be needed, with the path adjusted accordingly:

    semanage fcontext -a -t httpd_sys_rw_content_t '/home/medusa/sites/medusa/storage/(.*)?'
    

    Once this is done, restore the file contexts with the command:

    restorecon -Rv /home/medusa/sites/medusa
    
  4. Edit /etc/hosts and add medusa.local (I’ve had better luck using the .local extension instead of .dev)

    127.0.0.1 localhost medusa.local

  1. Expand the archive of the database you’ve been given and cd into the trmn directory created to load the database into your local mongodb server.

    $ cd trmn/
    $ mongorestore --db=trmn --drop .
    
  2. Verify that everything is working by going to http://medusa.local:8080/ in your browser. Use your current medusa login.

  3. Finally, give yourself ALL_PERMS, USER_MASQ and CONFIG in your local sandbox. Replace “RMN-XXXX-YY” with your RMN number.

    $ php artisan user:addperm RMN-XXXX-YY ALL_PERMS
    $ php artisan user:addperm RMN-XXXX-YY USER_MASQ
    $ php artisan user:addperm RMN-XXXX-YY CONFIG