How to generate .phar in netbeans - php

I have a problem of building the php appliction.
Target 'build' does not exist in this project
in netbeans php project.
Just send what are all the prosedures to build a phar along with composer in netbeans IDE using ubuntu os

Netbeans has plugins, you can install NBPhar, which will help you to create .phar file.
You can create .phar file by following below steps :
Create a new PHP file named create-phar.php in your myapp root with the following code:
<?php
$srcRoot = "~/myapp/src";
$buildRoot = "~/myapp/build";
$phar = new Phar($buildRoot . "/myapp.phar",
FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, "myapp.phar");
$phar["index.php"] = file_get_contents($srcRoot . "/index.php");
$phar["common.php"] = file_get_contents($srcRoot . "/common.php");
$phar->setStub($phar->createDefaultStub("index.php"));
copy($srcRoot . "/config.ini", $buildRoot . "/config.ini");
Then open a terminal window, navigate to the myapp directory and run it:
$ php create-phar.php
Refer this article Packaging Your Apps with Phar for detailed explanation.

Related

Run WP-CLI using PHP

I've installed WP-CLI on the Mac and my next step is to execute WP-CLI commands using PHP script.
I've tried to implement it the following way but I do not see anything happening. Can someone please look at my code and tell me that what I'm doing wrong?
define( 'WP_CLI_ROOT', '/usr/local/bin/wp' );
include WP_CLI_ROOT . '';
$output = shell_exec("wp --info");
echo "<pre>".$output."</pre>";
Do I need to configure and setup wp-cli with my PHP files?
Also, when I type wp --info on my terminal the following information comes up. Nothing is appearing beside the Package Dir & global config. do I also need to make adjustments to wp-cli?
MAC-00343:htdocs mike$ wp --info
PHP binary: /usr/bin/php
PHP version: 5.6.30
php.ini used:
WP-CLI root dir: phar://wp-cli.phar
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: /Users/mike/Docker/xamp/www/wordpress_wwws/htdocs
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 1.3.0
Any help or suggestions will be much appreciated.
Thanks
The problem is your wp cli aren't in the path environment variable, you should add your wp cli root to the path environment as following, hopefully this is helpful. For reference all wp cli command, visit the url - https://wpcommands.com
<?php
$saved = getenv("path"); // get the value of PATH environment variable and save current value
$newld = "/usr/local/bin"; // extra paths to add - in this case, it should be your wp cli root
if ($saved)
{
$newld .= ":$saved";
}
// append old paths if any
putenv("path=$newld"); // set new value
// exec wp cli command
$output = shell_exec("wp --info");
echo "<pre>".$output."</pre>";
?>
Here is what wp --info returns on my terminal.
the only main difference I see is the php.isi used: field.
Sorry I cant help more, but I dont know what DOCKER is, and I am using MAMP, not XAMP
phar path is just the current directory I'm working in

Nette phar boot file

I'm trying to create a single-file version of PHP framework Nette 2.4. I create a phar file using this code:
<?php
$phar = new Phar('nette.phar');
$phar->buildFromDirectory(__DIR__ . '/../vendor/nette');
$phar->setStub("<?php
require 'phar://' . __FILE__ . '/loader.php';
__HALT_COMPILER();");
$phar->compressFiles(Phar::GZ);
Everything is fine, the file is created. If I try to use this compacted version:
// bootstrap.php
<?php
require __DIR__ . '/nette.phar';
...
Error occurs:
Warning: require(phar://C:\wamp64\www\app\nette.phar/loader.php): failed to open stream: phar error: "loader.php" is not a file in phar "C:/wamp64/www/app/nette.phar" in C:\wamp64\www\app\nette.phar on line 2
So, single-file version is loaded, but there is no boot file loader.php. Does anyone know where is the mistake? Thanks for all the suggestions!
You can't create .phar from Nette downloaded via Composer. It doesn't have some necessary files (e.g. your Loader.php).
If you want to create .phar download official .zip from https://nette.org/en/download and create .phar from folder ./Nette.
__
BTW you don't need to create .phar yourself, you can find it in the .zip file in folder Nette-minified

Set buildpack failed for php application developed using wamp server

My application folder name is "social_network". It is in wamp\www path. I am trying to deploy app folder("social_network") to heroku using git commands.I followed all the instructions of heroku's instructions pages. I included composer.json file in the app folder, installed composer, kept Procfile. I even gave the commands of "heroku buildpacks:set".But still the push is being failed with an error message "set buildpack failed".The code in Procfile is:
"web: vendor/bin/heroku-php-apache2." Is this the process type to be given for the app in wamp server? What folder should I try to deploy- wamp or social_network?I doubt if there will be any more changes to make inorder to deploy as it is developed using wamp server.How can I deploy successfully?
The mistake that I had done was having the files of composer.json and Procfile along with my php files under social_network folder while the repository was created in www folder(I had my .git folder in www folder). So, heroku was not able to recognize my app as a php app and the push failed.
As I had a great difficulty to deploy my php application that was developed through wamp server, I would like to explain all the steps involved in deploying the php app which needs a database to heroku.
It is better to have all the application files directly under www folder.
The following documentation can be referred:
Getting started with heroku for php:
Have a heroku account, install php, and install composer and run it. The composer will download required packages in a folder called vendor which should be in your app directory.
Download heroku CLI and login to heroku using the command:
heroku login
Include composer.json file so that heroku recognizes that the application is a php app. It should contain the following code:
{
"require": {
"php": "^5.5.12"
}
}
The above code will instruct Heroku to use the latest version of PHP 5. The version can be anything which your app uses.
Have a Procfile to declare what command should be executed to start the app. It should have the following code:
web: vendor/bin/heroku-php-apache2
Now in cmd, make sure that the path of your www folder:
c:\wamp\www>
If there are any changes made to composer.json file, update the composer.lock file by:
c:\wamp\www> update composer
Next, create a new repository in the www folder by:
c:\wamp\www>git init
Then add your files to the repository.
c:\wamp\www>git add .
Then commit:
c:\wamp\www>git commit
Then create an app in heroku
c:\wamp\www>heroku create
Then comes the part of creating database and establishing connection:
The following documentation can be referred:
ClearDb Database documentation for php by heroku
Create a database:
C:\wamp\www>heroku addons:create cleardb:ignite
Set the url of the database to the app created in heroku:
C:\wamp\www> heroku config:set DATABASE_URL='the url that was created by the above command'
To know the CLEARDB_DATABASE_URL:
C:\wamp\www>heroku config
which gives the url:
CLEARDB_DATABASE_URL= mysql://user:password#host/heroku_db?reconnect=true
Example of the CLEARDB_DATABASE_URL:
mysql://b8xxxxxx:edxxxx# us-cdbr-iron-east-04.cleardb.net/heroku_xx‌​xxxx?reconnect=true .
To dump the existing sql file to the sql database in heroku, make sure that the PATH had been set for mysql and then give the following commands:
To get a mysql prompt with connection to the database.
C:\wamp\www>mysql -u b8xxxxxx -h us-cdbr-iron-east-04.cleardb.net -p heroku_xxxxxx
To dump the existing file to heroku database:
C:\wamp\www>mysql --host=us-cdbr-iron-east-04.cleardb.net --user=b8xxxxxx --password=edxxxxxx --reconnect heroku_xxxxxx< yoursqlfile.sql
Now use the database created and connect to it in your code:
<?php
$url = parse_url(getenv("CLEARDB_DATABASE_URL"));
$server = $url["host"];
$username = $url["user"];
$password = $url["pass"];
$db = substr($url["path"], 1);
$con = mysqli_connect("$server", "$username", "$password", "$db");
?>
Then push to the app created in heroku:
c:\wamp\www>git push heroku master
Open the app:
c:\wamp\www>heroku open
That's it! Now the website is hosted onto heroku successfully!

PharData extractTo method failed to extract .tar.gz on linux environment

I would like to extract .tar.gz file into the particular folder. I have used cURL to download the .tar.gz file from MailChimp batch operation. I have used below code to extract tar file.
$phar = new \PharData('upload/test.tar.gz');
$phar->extractTo('upload/',null, true);
It is working on windows environment. But on Linux(Ubuntu), I got below error when to run above code.
Uncaught exception 'PharException' with message 'Extraction from phar "upload/test.tar" failed: Cannot extract ".", internal error'
I have already set default apache user and group permission for upload folder.
sudo chown -R www-data:www-data upload/
PHP Version: 5.6.24
I have attach sample .tar.gz file: http://www.simbanic.com/_projects/test/05c902076e.tar.gz
I had the same problem with MailChimp batch response archive.
Stupid solution, but it works...
$p = new PharData($tarGzArchive, RecursiveDirectoryIterator::SKIP_DOTS);
$p->convertToData(Phar::ZIP);
$zip = new ZipArchive;
$res = $zip->open($createdZipArchive);
if ($res === TRUE) {
$zip->extractTo($destinationPath);
$zip->close();
}

Doctrine Cli on Windows

I am having some trouble configuring doctrine orm on windows 8, php 5.4. I have installed Doctrine using Composer.
I have followed the docs to the letter but when I run any commands, php vendor/bin/doctrine orm:schema-tool:create for example, my command line just outputs
SRC_DIR="`pwd`"
cd "`dirname "$0"`"
cd "../doctrine/orm/bin"
BIN_TARGET="`pwd`/doctrine"
cd "$SRC_DIR"
"$BIN_TARGET" "$#"
I have also tried php vendor/bin/doctrine.php .... but it just prints out the above.
I have followed Doctrine's guide to the letter. Has anyone seen this before and if so, can you suggest anything?
i found a solution
there are also a bin folder in vendor/doctrine/orm/bin/ you can use this one like this
php vendor/doctrine/orm/bin/doctrine orm:schema-tool:create
make sure you have root folder and a cli-config.php file is present in root folder.
below is location where i found a solution
https://groups.google.com/forum/#!msg/doctrine-user/_ph183Kh-5o/_P_coljB-dcJ
this is working fine for me .
I had the same problem. The following solution worked for me:
"vendor/bin/doctrine.bat" orm:schema-tool:create
So, basically you:
use the ".bat" file provided by Doctrine and
enclose the call to that ".bat" file in quotes.
My Environment
Windows 7 Professional (x64)
PHP 5.5.12
Doctrine ORM 2.4.4
Do not write "php..." (it will write the file content)
Just "vendor\bin\doctrine orm:schema-tool:create" do the job (from the project root eg. c:\php\theProject).
Next, you will need a "cli-config.php" in the project root...
For Window version use backward slash "\"
vendor\bin\doctrine orm:schema-tool:create
not forward slash "/"
vendor/bin/doctrine orm:schema-tool:create
You can either install something like git bash or simply use the PHP version of the script:
php vendor\bin\doctrine.php orm:info
Obviously, the php binary directory should be in your PATH environment variable, otherwise, it's something like:
C:\path\to\php.exe vendor\bin\doctrine.php orm:info
Copy doctrine.bat (located at vendor/bin/doctrine.bat) to your project root directory
Create a bootstrap.php file in any path inside your project root directory with the following content:
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
$paths = array("../model");
$isDevMode = false;
$dbParams = array(
'driver' => 'pdo_mysql',
'host' => 'localhost',
'user' => 'root',
'password' => '',
'dbname' => 'angular_php',
);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($dbParams, $config);
Create a cli-config.php file in your project root directory with the following content:
<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;
// replace with file to your own project bootstrap
require_once 'path/to/file/bootstrap.php';
return ConsoleRunner::createHelperSet($entityManager);
Execute from a command line window (CMD):
c:\path\to\project\root\directory>doctrine --help
It's done!
I found it wasnt returning anything from the doctrine.php.bat. Turns out it was a PHP error in my cli-config.php file
Using Cygwin on Windows with doctrine installed via composer, was having the same problem
resolved by:
vendor/bin/doctrine.bat orm:convert-mapping
if you are still having issues you can run the cli script using php to get the console tools running:
for example
php cli-config.php orm:schema-tool:create
All the answers on this question are either outdated or outright incorrect. In my case, I observed, after installing the the library, the "\vendor\doctrine\orm\" folder was completely empty. The docs ask you to run vendor/bin/doctrine, which in turn attempts to call "vendor\doctrine\orm\bin\doctrine[.php]" (The php file extension is optional). After discovering this, I downloaded the library from the git repository and replaced the composer-installed version.
php vendor/doctrine/orm/bin/doctrine
then works fine.
Also, beware of the common misconception that the cli-config.php file must exist in the root of your project. It's fine to leave it in your config folder

Categories