Ubuntu

Setup Local Repositories with ‘apt-mirror’ in Ubuntu and Debian Systems

Setup Local Repositories with &-8216;apt-mirror&-8217; in Ubuntu and Debian Systems &-8211; this Article or News was published on this date:2019-05-28 19:20:46 kindly share it with friends if you find it helpful

When today traffic and casual internet speeds is measured in teens of Giga over an eye blink even for ordinary Internet clients, what’s the purpose of setting a local repository cache on LAN’s you may ask?

Setup Local Repositories in UbuntuSetup Local Repositories in Ubuntu

Setup Local Repositories in Ubuntu

One of the reasons is to reduce Internet bandwidth and high speed on pulling packages from local cache. But, also, another major reason should be privacy. Let’s imagine that clients from your organization are Internet restricted, but their Linux boxes need to regular system updates on software and security or just need new software packages. To go further picture, a server that runs on a private network, contains and serves secret sensitive information only for a restricted network segment, and should never be exposed to public Internet.

This are just a few reasons why you should build a local repository mirror on your LAN, delegate an edge server for this job and configure internal clients to pull out software form its cache mirror.

Ubuntu provides apt-mirror package to synchronize local cache with official Ubuntu repositories, mirror that can be configured through a HTTP or FTP server to share its software packages with local system clients.

For a complete mirror cache your server needs at least 120G free space reserved for local repositories.

Requirements

  1. Min 120G free space
  2. Proftpd server installed and configured in anonymous mode.

Step 1: Configure Server

1. The first thing you may want to do is to identify the closest and fastest Ubuntu mirrors near you’re location by visiting Ubuntu Archive Mirror page and select your country.

Setup Local Repositories in UbuntuUbuntu Archive Mirror

Ubuntu Archive Mirror

If your country provides more mirrors you should identify mirror address and do some tests based on ping or traceroute results.

Setup Local Repositories in UbuntuSelect Mirror Location

Select Mirror Location

2. The next step is to install required software for setting up local mirror repository. Install apt-mirror and proftpd packages and configure proftpd as standalone system daemon.

$ sudo apt-get install apt-mirror proftpd-basic
Setup Local Repositories in UbuntuInstall apt-mirror Proftpd

Install apt-mirror Proftpd

Setup Local Repositories in UbuntuProFTPD Configuration

ProFTPD Configuration

3. Now it’s time to configure apt-mirror server. Open and edit /etc/apt/mirror.list file by adding your nearest locations (Step 1) – optional, if default mirrors are fast enough or you’re not in a hurry – and choose your system path where packages should be downloaded. By default apt-mirror uses /var/spool/apt-mirror location for local cache but on this tutorial we are going to use change system path and point set base_path directive to /opt/apt-mirror location.

$ sudo nano /etc/apt/mirror.list
Setup Local Repositories in UbuntuConfigure apt-mirror Server.

Configure apt-mirror Server.

Also you can uncomment or add other source list before clean directive – including Debian sources – depending on what Ubuntu versions your clients use. You can add sources from 12.04, if you like but be aware that adding more sources requires more free space.

For Debian source lists visit Debian Wiki or Debian Sources List Generator.

4. All you need to do now is, just create path directory and run apt-mirror command to synchronize official Ubuntu repositories with our local mirror.

$ sudo mkdir -p /opt/apt-mirror
$ sudo apt-mirror
Setup Local Repositories in UbuntuCreate apt-mirror Paths

Create apt-mirror Paths

As you can see apt-mirror proceeds with indexing and downloading archives presenting total number of downloaded packages and their size. As we can imagine 110-120 GB is large enough to take some time to download.

You can run ls command to view directory content.

Setup Local Repositories in UbuntuVerify apt-mirror Paths

Verify apt-mirror Paths

Once the initial download is completed, future downloads will be small.

5. While apt-mirror downloads packages, you can configure your Proftpd server. The first thing you need to do is, to create anonymous configuration file for proftpd by running the following command.

$ sudo nano /etc/proftpd/conf.d/anonymous.conf

Then add the following content to anonymous.conf file and restart proftd service.

Anonymous ~ftp>
   User                    ftp
   Group                nogroup
   UserAlias         anonymous ftp
   RequireValidShell        off
-   MaxClients                   10
   Directory *>
     Limit WRITE>
       DenyAll
     /Limit>
   /Directory>
 /Anonymous>
Setup Local Repositories in UbuntuConfigure ProFTPD

Configure ProFTPD

6. Next step is to link apt-mirror path to proftpd path by running a bind mount by issuing the command.

$ sudo mount --bind /opt/apt-mirror/mirror/archive.ubuntu.com/  /srv/ftp/
Setup Local Repositories in UbuntuMount apt-mirror to ProFTP Path

Mount apt-mirror to ProFTP Path

To verify it run mount command with no parameter or option.

$ mount
Setup Local Repositories in UbuntuVerify Paths

Verify Paths

7. Last step is to make sure that Proftpd server is automatically started after system reboot and mirror-cache directory is also automatically mounted on ftp server path. To automatically enable proftpd run the following command.

$ sudo update-rc.d proftpd enable

To automatically mount apt-mirror cache on proftpd open and edit /etc/rc.local file.

$ sudo nano /etc/rc.local

Add the following line before exit 0 directive. Also use 5 seconds delay before attempting to mount.

sleep 5
sudo mount --bind  /opt/apt-mirror/mirror/archive.ubuntu.com/ /srv/ftp/
Setup Local Repositories in UbuntuAuto Mount Apt Mirrors

Auto Mount Apt Mirrors

If you pull packages from Debian repositories run the following commands and make sure appropriate settings for above rc.local file are enabled.

$ sudo mkdir /srv/ftp/debian
$ sudo mount --bind /opt/apt-mirror/mirror/ftp.us.debian.org/debian/ /srv/ftp/debian/
Setup Local Repositories in UbuntuDebian Repository Setup

Debian Repository Setup

8. For a daily apt-mirror synchronization you can also create a system schedule job to run at 2 AM every day. Run crontab command, select your preferred editor then add the following line syntax.

$ sudo crontab –e
Setup Local Repositories in UbuntuDaily apt-mirror Synchronization

Daily apt-mirror Synchronization

On last line add the following line.

0  2  *  *  *  /usr/bin/apt-mirror >> /opt/apt-mirror/mirror/archive.ubuntu.com/ubuntu/apt-mirror.log
Setup Local Repositories in UbuntuAdd Cron Entry for Synchronization

Add Cron Entry for Synchronization

Now every day at 2 AM your system repository cache will synchronize with Ubuntu official mirrors and create a log file.

Step 2: Configure clients

9. To configure local Ubuntu clients, edit /etc/apt/source.list on client computers to point to the IP address or hostname of apt-mirror server – replace http protocol with ftp, then update system.

deb ftp://192.168.1.13/ubuntu trusty universe
deb ftp://192.168.1.13/ubuntu trusty main restricted
deb ftp://192.168.1.13/ubuntu trusty-updates main restricted
-- Ad so on….
Setup Local Repositories in UbuntuConfigure Clients

Configure Clients

10. To view repositories you can actually open a browser and point to your server IP address of domain name using FTP protocol.

Setup Local Repositories in UbuntuView Local Repositories

View Local Repositories

The same system applies also to Debian clients and servers, the only change needed are debian mirror and sources list.

Also if you install a fresh Ubuntu or Debian system, provide your local mirror manually whit ftp protocol when installer asks which repository to use.

The great thing about having your own local mirror repositories is that you’re always on current and your local clients don’t have to connect to Internet to install updates or software.

Setting Up High-Performance HHVM and Nginx/Apache with MariaDB on Debian/Ubuntu

Setting Up High-Performance HHVM and Nginx/Apache with MariaDB on Debian/Ubuntu &-8211; this Article or News was published on this date:2019-05-28 18:15:52 kindly share it with friends if you find it helpful

HHVM stands for HipHop Virtual Machine, is an open source virtual machine created for running Hack (it’s a programming language for HHVM) and PHP written applications. HHVM uses a last minute compilation path to achieve remarkable performance while keeping the flexibility that PHP programmers are addicted to. Till date, HHVM has achieved over a 9x increase in http request throughput and more than 5x cut in memory utilization (when running on low system memory) for Facebook compared with the PHP engine + APC (Alternative PHP Cache).

HHVM can also be used along with a FastCGI-based web-server like Nginx or Apache.

Install HHVM, Nginx and Apache with MariaDBInstall HHVM, Nginx and Apache with MariaDB

Install HHVM, Nginx and Apache with MariaDB

In this tutorial we shall look at steps for setting up Nginx/Apache web server, MariaDB database server and HHVM. For this setup, we will use Ubuntu 15.04 (64-bit) as HHVM runs on 64-bit system only, although Debian and Linux Mint distributions are also supported.

Step 1: Installing Nginx and Apache Web Server

1. First do a system upgrade to update repository list with the help of following commands.

- apt-get update && apt-get upgrade
Install HHVM, Nginx and Apache with MariaDBSystem Upgrade

System Upgrade

2. As I said HHVM can be used with both Nginx and Apache web server. So, it’s your choice which web server you will going to use, but here we will show you both web servers installation and how to use them with HHVM.

Installing Nginx

In this step, we will install Nginx/Apache web server from the packages repository using following command.

- apt-get install nginx
Install HHVM, Nginx and Apache with MariaDBInstall Nginx Web Server

Install Nginx Web Server

Installing Apache

- apt-get install apache2
Install HHVM, Nginx and Apache with MariaDBInstall Apache Web Server

Install Apache Web Server

At this point, you should be able to navigate to following URL and you will able to see Nginx or Apache default page.

http://localhost
OR
http://IP-Address
Nginx Default Page
Install HHVM, Nginx and Apache with MariaDBNginx Welcome Page

Nginx Welcome Page

Apache Default Page
Install HHVM, Nginx and Apache with MariaDBApache Default Page

Apache Default Page

Step 2: Install and Configure MariaDB

3. In this step, we will install MariaDB, as it providers better performance as compared to MySQL.

- apt-get install mariadb-client mariadb-server
Install HHVM, Nginx and Apache with MariaDBInstall MariaDB Database

Install MariaDB Database

4. After MariaDB successful installation, you can start MariaDB and set root password to secure the database:

- systemctl start mysql
- mysql_secure_installation

Answer the following questions by typing y or n and press enter. Make sure you read the instructions carefully before answering the questions.

Enter current password for root (enter for none) = press enter
Set 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 privileges tables now[y/n] = y 

5. After setting root password for MariaDB, you can connect to MariaDB prompt with the new root password.

- mysql -u root -p

Step 3: Installation of HHVM

6. At this stage we shall install and configure HHVM. You need to add the HHVM repository to your sources.list file and then you have to update your repository list using following series of commands.

- wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | apt-key add -
- echo deb http://dl.hhvm.com/ubuntu DISTRIBUTION_VERSION main | sudo tee /etc/apt/sources.list.d/hhvm.list
- apt-get update

Important: Don’t forget to replace DISTRIBUTION_VERSION with your Ubuntu distribution version (i.e. lucid, precise, or trusty.) and also on Debian replace with jessie or wheezy. On Linux Mint installation instructions are same, but petra is the only currently supported distribution.

After adding HHVM repository, you can easily install it as shown.

- apt-get install -y hhvm

Installing HHVM will start it up now, but it not configured to auto start at next system boot. To set auto start at next boot use the following command.

- update-rc.d hhvm defaults

Step 4: Configuring Nginx/Apache to Talk to HHVM

7. Now, nginx/apache and HHVM are installed and running as independent, so we need to configure both web servers to talk to each other. The crucial part is that we have to tell nginx/apache to forward all PHP files to HHVM to execute.

If you are using Nginx, follow this instructions as explained..

By default, the nginx configuration lives under /etc/nginx/sites-available/default and these config looks in /usr/share/nginx/html for files to execute, but it don’t know what to do with PHP.

To make Nginx to talk with HHVM, we need to run the following include script that will configure nginx correctly by placing a hhvm.conf at the beginning of the nginx config as mentioned above.

This script makes the nginx to talk to any file that ends with .hh or .php and send it to HHVM via fastcgi.

- /usr/share/hhvm/install_fastcgi.sh
Install HHVM, Nginx and Apache with MariaDBConfigure Nginx for HHVM

Configure Nginx for HHVM

Important: If you are using Apache, there isn’t any configuration is needed now.

8. Next, you need to use /usr/bin/hhvm to provide /usr/bin/php (php) by running this command below.

- /usr/bin/update-alternatives --install /usr/bin/php php /usr/bin/hhvm 60

After all the above steps are done, you can now start HHVM and test it.

- systemctl start hhvm

Step 5: Testing HHVM with Nginx/Apache

9. To verify that hhvm working, you need to create a hello.php file under nginx/apache document root directory.

- nano /usr/share/nginx/html/hello.php       [For Nginx]
OR
- nano /var/www/html/hello.php               [For Nginx and Apache]

Add the following snippet to this file.

?php
if (defined('HHVM_VERSION')) {
echo 'HHVM is working';
 phpinfo();
}
else {
echo 'HHVM is not working';
}
?>

and then navigate to the following URL and verify to see “hello world“.

http://localhost/info.php
OR
http://IP-Address/info.php
Install HHVM, Nginx and Apache with MariaDBHHVM Page

HHVM Page

If “HHVM” page appears, then it means you’re all set!

Conclusion

These steps are very easy to follow and hope your find this tutorial useful and if you get any error during installation of any packages, post a comment and we shall find solutions together. And any additional ideas are welcome.

How to Install Security Updates Automatically on Debian and Ubuntu

How to Install Security Updates Automatically on Debian and Ubuntu &-8211; this Article or News was published on this date:2019-05-28 17:10:22 kindly share it with friends if you find it helpful

It has been said before -and I couldn’t agree more- that some of the best system administrators are those who seem (note the use of the word seem here) to be lazy all the time.

While that may sound somewhat paradoxical, I bet it must be true in most cases – not because they are not doing the job they are supposed to be doing, but rather because they have automated most of it.

One of the critical needs of a Linux system is to be kept up to date with the latest security patches available for the corresponding distribution.

In this article we will explain how to set up your Debian and Ubuntu system to auto install (or update) essential security packages or patches automatically when needed.

Other Linux distributions such as CentOS/RHEL configured to install security updates automatically.

Needless to say, you will need superuser privileges in order to perform the tasks outlined in this article.

Configure Automatic Security Updates On Debian/Ubuntu

To begin, install the following packages:

- aptitude update -y && aptitude install unattended-upgrades apt-listchanges -y

where apt-listchanges will report what has been changed during an upgrade.

Next, open /etc/apt/apt.conf.d/50unattended-upgrades with your preferred text editor and add this line inside the Unattended-Upgrade::Origins-Pattern block:

Unattended-Upgrade::Mail "root";

Finally, use the following command to create and populated the required configuration file (/etc/apt/apt.conf.d/20auto-upgrades) to activate the unattended updates:

- dpkg-reconfigure -plow unattended-upgrades

Choose Yes when prompted to install unattended upgrades:

Configure Unattended Security Updates on DebianConfigure Unattended Security Updates on Debian

Configure Unattended Security Updates on Debian

then check that the following two lines have been added to /etc/apt/apt.conf.d/20auto-upgrades:

APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";

And add this line to make reports verbose:

APT::Periodic::Verbose "2";

Last, inspect /etc/apt/listchanges.conf to make sure notifications will be sent to root.

Configure Unattended Security Updates on DebianNotify Security Updates on Debian

Notify Security Updates on Debian

In this post we have explained how to make sure your system is updated regularly with the latest security patches. Additionally, you learned how to set up notifications in order to keep yourself informed when patches are applied.

Do you have any questions about this article? Feel free to drop us a note using the comment form below. We look forward to hearing from you.

How to Delete Old Unused Kernels in Debian and Ubuntu

How to Delete Old Unused Kernels in Debian and Ubuntu &-8211; this Article or News was published on this date:2019-05-28 16:44:53 kindly share it with friends if you find it helpful

In our last article, we’ve explained how to delete old unused kernels in CentOS/RHEL/Fedora. In this article, we will explain how to delete old unused kernels in Debian and Ubuntu systems, but before moving further, you may want to install the latest version in order to take advantage of: security fixes, new kernel functions, updated drivers and so much more.

To upgrade your kernel to latest version in Ubuntu and Debian, follow this guide:

  1. How to Upgrade Kernel to Latest Version in Ubuntu

Important: It is advisable to keep at least one or two old kernels to fall back to in case there is a problem with an update.

To find out the current version of Linux kernel running on your system, use the following command.

$ uname -sr

Linux 4.12.0-041200-generic

To list all installed kernels on your system, issue this command.

$ dpkg -l | grep linux-image | awk '{print$2}'

linux-image-4.12.0-041200-generic
linux-image-4.8.0-22-generic
linux-image-extra-4.8.0-22-generic
linux-image-generic

Remove Old Unused Kernels on Debian and Ubuntu

Run the commands below to remove a particular linux-image along with its configuration files, then update grub2 configuration, and lastly reboot the system.

$ sudo apt remove --purge linux-image-4.4.0-21-generic
$ sudo update-grub2
$ sudo reboot
Removing Old Kernel in Ubuntu
[sudo] password for sfnews: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  linux-generic linux-headers-4.8.0-59 linux-headers-4.8.0-59-generic linux-headers-generic linux-image-4.8.0-59-generic linux-image-extra-4.8.0-59-generic linux-image-generic
Suggested packages:
  fdutils linux-doc-4.8.0 | linux-source-4.8.0 linux-tools
Recommended packages:
  thermald
The following packages will be REMOVED:
  linux-image-4.8.0-22-generic* linux-image-extra-4.8.0-22-generic*
The following NEW packages will be installed:
  linux-headers-4.8.0-59 linux-headers-4.8.0-59-generic linux-image-4.8.0-59-generic linux-image-extra-4.8.0-59-generic
The following packages will be upgraded:
  linux-generic linux-headers-generic linux-image-generic
3 upgraded, 4 newly installed, 2 to remove and 182 not upgraded.
Need to get 72.0 MB of archives.
After this operation, 81.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main amd64 linux-headers-4.8.0-59 all 4.8.0-59.64 [10.2 MB]
Get:2 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main amd64 linux-headers-4.8.0-59-generic amd64 4.8.0-59.64 [811 kB]                                                               
Get:3 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main amd64 linux-generic amd64 4.8.0.59.72 [1,782 B]                                                                               
Get:4 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main amd64 linux-headers-generic amd64 4.8.0.59.72 [2,320 B]                                                                       
Get:5 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main amd64 linux-image-4.8.0-59-generic amd64 4.8.0-59.64 [23.6 MB]                                                                
Get:6 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main amd64 linux-image-extra-4.8.0-59-generic amd64 4.8.0-59.64 [37.4 MB]                                                          
Get:7 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main amd64 linux-image-generic amd64 4.8.0.59.72 [2,348 B]                                                                         
Fetched 72.0 MB in 7min 12s (167 kB/s)                                                                                                                                                       
Selecting previously unselected package linux-headers-4.8.0-59.
(Reading database ... 104895 files and directories currently installed.)
Preparing to unpack .../0-linux-headers-4.8.0-59_4.8.0-59.64_all.deb ...
Unpacking linux-headers-4.8.0-59 (4.8.0-59.64) ...
Selecting previously unselected package linux-headers-4.8.0-59-generic.
Preparing to unpack .../1-linux-headers-4.8.0-59-generic_4.8.0-59.64_amd64.deb ...
Unpacking linux-headers-4.8.0-59-generic (4.8.0-59.64) ...
Preparing to unpack .../2-linux-generic_4.8.0.59.72_amd64.deb ...
Unpacking linux-generic (4.8.0.59.72) over (4.8.0.22.31) ...
Preparing to unpack .../3-linux-headers-generic_4.8.0.59.72_amd64.deb ...
Unpacking linux-headers-generic (4.8.0.59.72) over (4.8.0.22.31) ...
Selecting previously unselected package linux-image-4.8.0-59-generic.
Preparing to unpack .../4-linux-image-4.8.0-59-generic_4.8.0-59.64_amd64.deb ...
Done.
Removing linux-image-4.8.0-22-generic (4.8.0-22.24) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.8.0-22-generic /boot/vmlinuz-4.8.0-22-generic
update-initramfs: Deleting /boot/initrd.img-4.8.0-22-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.8.0-22-generic /boot/vmlinuz-4.8.0-22-generic
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.12.0-041200-generic
Found initrd image: /boot/initrd.img-4.12.0-041200-generic
Found linux image: /boot/vmlinuz-4.8.0-59-generic
done
...

Although this method works just fine, it is more reliable and efficient to use a handy script called “byobu” that combines all the commands above into a single program with useful options such as specifying number of kernels to keep on the system.

Install byobu script package which provides a program called purge-old-kernels used for removing old kernels and header packages from the system.

$ sudo apt install byobu

Then remove old kernels like so (the command below allows 2 kernels to be kept on the system).

$ sudo purge-old-kernels --keep 2

You may also like to read these following related articles on Linux kernel.

  1. How to Load and Unload Kernel Modules in Linux
  2. How to Change Kernel Runtime Parameters in a Persistent and Non-Persistent Way

In this article, we have described how to remove old unused kernel images on Ubuntu and Debian systems. You can share any thoughts via the feedback from below.

How to Install ionCube Loader in Debian and Ubuntu

How to Install ionCube Loader in Debian and Ubuntu &-8211; this Article or News was published on this date:2019-05-28 16:19:06 kindly share it with friends if you find it helpful

ionCube loader is a PHP extension (module) that enables PHP to load files protected and encoded using ionCube Encoder software, which is mostly used in commercial software applications to protect their source code and prevent it from being visible and detectable.

Read Also: How to Install ionCube Loader in CentOS 7

In this article, we will explain how to install and configure ionCube Loader with PHP in Debian and Ubuntu distributions.

Prerequisites:

A Ubuntu or Debian server running with a web server (Apache or Nginx) along with a PHP installed. If you don’t have a web server and PHP on your system, you can install them using apt package manager as shown.

Step 1: Install Apache or Nginx Web Server with PHP

1. If you already have a running web server Apache or Nginx with PHP installed on your system, you can jump to the Step 2, otherwise use the following apt command to install them.

-------------------- Install Apache with PHP --------------------
$ sudo apt install apache2 php7.0 php7.0-fpm php7.0-cli 

-------------------- Install Nginx with PHP -------------------- 
$ sudo apt install nginx php7.0 php7.0-fpm php7.0-cli

2. Once you’ve installed Apache or Nginx with PHP on your system, you can start the web server and active it to auto start at system boot using following commands.

-------------------- Start Apache Web Server --------------------
$ sudo systemctl start apache2
$ sudo systemctl enable apache2

-------------------- Start Nginx + PHP-FPM Server --------------------
$ sudo systemctl start nginx
$ sudo systemctl enable nginx
$ sudo systemctl start php7.0-fpm
$ sudo systemctl enable php7.0-fpm

Step 2: Download IonCube Loader

3. Go to the inocube’s website and download the installation files, but before that you need to check whether your Linux distribution is running on 64-bit or 32-bit architecture using the following command.

$ uname -r

Linux TecMint 4.4.0-21-generic -37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

The above output clearly shows that the system is running on 64-bit architecture.

As per your Linux distribution architecture, download ioncube loader files to /tmp directory using following wget command.

-------------------- For 64-bit System --------------------
$ cd /tmp
$ wget https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz

-------------------- For 32-bit System --------------------
$ cd /tmp
$ wget https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86.tar.gz

4. Then uncompress the downloaded file using the tar command and switch into the unzipped folder. Then run the ls command to list the various ioncube loader files for different PHP versions.

$ tar -xvf ioncube_loaders_lin_x86*
$ cd ioncube/
$ ls -l
Ioncube Loader FilesIoncube Loader Files

Ioncube Loader Files

Step 3: Install ionCube Loader for PHP

5. In the above screenshot, you will see various ioncube loader files for different PHP versions, you need to select the right ioncube loader for your installed PHP version on your server. To know the currently installed php version on your server, run the command.

$ php -v
Ioncube Loader FilesCheck PHP Version in Ubuntu

Check PHP Version in Ubuntu

The above screenshot clearly tells that the system is using PHP 7.0.25 version, in your case it should be different version.

6. Next, find the location of the extension directory for PHP version 7.0.25, it is where the ioncube loader file will be installed.

$ php -i | grep extension_dir

extension_dir => /usr/lib/php/20151012 => /usr/lib/php/20151012

7. Next we need to copy ioncube loader for our PHP 7.0.25 version to the extension directory (/usr/lib/php/20151012).

$ sudo cp /tmp/ioncube/ioncube_loader_lin_7.0.so /usr/lib/php/20151012

Note: Make sure to replace the PHP version and extension directory in the above command according to your system configuration.

Step 4: Configure ionCube Loader for PHP

8. Now we need to configure ioncube loader to work with PHP, in the php.ini file. Debian and Ubuntu use different php.ini files for PHP CLI and PHP-FPM as shown.

$ sudo vi /etc/php/7.0/cli/php.ini 		-for PHP CLI 
$ sudo vi /etc/php/7.0/fpm/php.ini		-for PHP-FPM & Nginx
$ sudo vi /etc/php/7.0/apache2/php.ini	        -for Apache2	

Then add below line as the first line in the respective php.ini files.

zend_extension = /usr/lib/php/20151012/ioncube_loader_lin_7.0.so

Note: Make sure to replace the extension directory location and PHP version in the above command according to your system configuration.

9. Then save and exit the file. Now we need to restart the Apache or Nginx web server for the ioncube loaders to come into effect.

-------------------- Start Apache Web Server --------------------
$ sudo systemctl restart apache2

-------------------- Start Nginx + PHP-FPM Server --------------------
$ sudo systemctl restart nginx
$ sudo systemctl restart php-fpm

Step 5: Test ionCube Loader

10. Now it’s time to verify that the ionCube loader is properly installed and configured on your server by checking PHP version one more time. You should be able to see a message indicating that PHP is installed and configured with the ioncube loader extension (status should be enabled), as shown in the output below.

$ php -v

PHP 7.0.25-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with the ionCube PHP Loader (enabled) + Intrusion Protection from ioncube24.com (unconfigured) v10.2.0, Copyright (c) 2002-2018, by ionCube Ltd.
    with Zend OPcache v7.0.25-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies

That’s It! In order to secure PHP files, you need to have IonCube loader installed and configured with your installed PHP version, as shown above. We hope that everything worked fine without any issues, otherwise, use the feedback form below to send us your queries.