Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP program create installable package

Tags:

linux

php

ubuntu

I have the following PHP script, and I'd like to create a package that people can install easy, something similar to this:

sudo dpkg -i packagename.deb

Any ideas on how can I do this?

/home/script.sh

#!/bin/bash
echo "Starting NAME service"
sudo -u root php -f /home/script.php &

/home/script.php

<?php

// The worker will execute every X seconds:
$seconds = 2;

// We work out the micro seconds ready to be used by the 'usleep' function.
$micro = $seconds * 1000000;

while(true){
 // This is the code you want to loop during the service...
 $myFile = "/home/filephp.txt";
 $fh = fopen($myFile, 'a') or die("Can't open file");
 $stringData = "File updated at: " . time(). "\n";
 fwrite($fh, $stringData);
 fclose($fh);

 // Now before we 'cycle' again, we'll sleep for a bit...
 usleep($micro);
}

/etc/systemd/system/name.service

[Unit]
Description=Crawler cache Service
After=network.target

[Service]
User=root
Restart=always
Type=forking
ExecStart=/home/script.sh

[Install]
WantedBy=multi-user.target
like image 402
Marcos Aguayo Avatar asked Dec 09 '25 08:12

Marcos Aguayo


1 Answers

Solved creating the following folder tree:

> package_name/
>> DEBIAN/
>>> control
>> usr/
>>> share/
>>>> package_name/
>>>>> script.sh
>>>>> script.php
>> etc/
>>> systemd/
>>>> system/
>>>>> name.service

In the "control" file you have to set some parameters, like the version number or dependencies.

Package: package_name
Version: 0.0.1
Section: base
Priority: optional
Architecture: all
Depends: php, php-curl
Maintainer: Marcos Aguayo <[email protected]>
Description: Package description

After that you only have to type the following command:

sudo dpkg-deb --build package_name/

When you have the .deb package, if you want to install it you can use this command:

sudo dpkg -i package_name.deb # --> Install .deb
systemctl start package_name  # --> Start the service
like image 60
Marcos Aguayo Avatar answered Dec 10 '25 22:12

Marcos Aguayo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!