Skip to main content

Deploying PHP applications as PHAR archives

             
               Deploying PHP applications as PHAR archives

Today I discovered a very powerful addition to the PHP world. Phar is an archive extension for PHP that allows an entire PHP application to be packaged into a single file. It's basically PHP's answer to Java's .jar archive format. Don't get excited yet, it gets better...
There are a few things that make this particularly handy. For one, it is being integrated into the next major PHP release (5.3) which means that any standard PHP installation running the latest version will support .phar files right out of the box.
The other advantage is of course in deployment. Using a .phar file you can deploy an entire PHP application by working with just one file, rather than a bunch of files and directories. This is where .phar really shines. Imagine deploying a popular web app like WordPress by simply copying a single .phar file to your web server's root, rather than figuring out how to zip it up, upload it, and somehow unzip it remotely. Piece of cake!
The development side is equally as simple, being able to access files within the .phar file as easily as if it were another directory in the file system. The .phar file itself can be included in a script using any of PHP's standard import constructs (include, include_once, require, require_once). This also means external libraries can be more easily integrated, having just a single file to include in order to utilize a given library. A .phar archive can also be accessed as a stream using the same functions used to read/write other types of streams.
Certainly there are disadvantages as well, and this is not a one-size-fits-all solution. Using .phar files does result in a performance hit, meaning traffic-intensive sites and heavyweight applications are probably not the best place to use this tool. It also may not be ideal for a web app that is fairly modular, or other situations where source files might be added or removed on a regular basis. It does have its uses though, and for me it will be a welcome addition to the PHP core.
Reference:
#site_crafting

Comments

Popular posts from this blog

What is Bitnami ?

                                            What is Bitnami ? Bitnami makes it easy to run your favorite server apps anywhere Bitnami is a library of popular server applications and development environments that can be installed with one click, either in your laptop, in a virtual machine or hosted in the cloud. We take care of compiling and configuring the applications and all of their dependencies (third-party libraries, language runtimes, databases) so they work out-of-the-box. The resulting packaged software (a 'stack') is then made available as native installers, virtual machines and cloud images. These Bitnami application packages provide a consistent, secure and optimized end-user experience when deploying any app, on any platform. Bitnami Cloud Hosting Bitnami Cloud Hosting is a server management solution that makes it incredibly simple to launch and...

Using Sublime Text or gedit when logging as User

For me I used xhost + and it solved the problem. You can use it when you are working in a  remote instance and you wanna use gedit. By default, and for security reasons, the only user that interacts with X-server is the logged-in user. Meaning, You can not initiate a connection to x-server as a different user or in your case as root, unless you have overridden the default setting to allow different users/hosts to connect to x-server. So the error message you are getting is related to x-server since any other user can't connect to it. In order to get around it, you have various fixes you can apply. What I normally do when ever I need to run an X-app as root is as follows. From normal user terminal, I run  xhost +  to grant access to all user temporarily Then I log in as root from a different terminal and execute the X-app ie  gedit tester.php To make it permanent (which I don't suggest), edit  /etc/profile  and add the following line: expor...