Installable PHP application architecture [closed]

5

I'm trying to improve my PHP applications. In this goal I would like to create an installer for a web application, a website for example.

I already know linux packages like rpm and deb, that's not what I'm talking about, because some servers do not have access to bash or commands like exec , shell_exec , and < strong> eval .

My intention is to create a auto-installable application as a wordpress for example - a package to download and in a click install. Anyone have any suggestions?

    
asked by anonymous 24.12.2013 / 17:40

4 answers

14

What you could do is learn from the examples you cited. What Wordpress does, like other PHP applications (phpMyAdmin, Joomla, Drupal ...), is to put in a .ZIP (or .tar.gz) all the files that would be in the root of the site. Basically, you go into the WWW (public_html) folder of your project and zip.

But here you want the project to auto-install ... The wordpress approach is the cool one. You create a install.php or a route, which basically if/else , in the following stream:

  • Is the database configuration file ok?
  • Can I connect to the bank?
  • Is there whathever table in my bank?

Well, if you were able to connect legal but a key database table does not exist, you run your SQL commands that create your database.

    
25.12.2013 / 01:09
8

Good response from @FReNeTiC. I would, however, like to add a few pointers on how to do a auto-install .

Main configuration file

Like Wordpress, you will need a basic file configuration that works independently of the database. Usually the file will contain the database access information, directory notes, and main language.

Sometimes it is possible that the file is automatically created through an installation screen. You make a screen with the necessary data, the user completes the form and you save the file in the correct place.

But, unfortunately, this is not always possible, because in some hosting you can not write to the file system and / or do not want to give written permission to the scripts. In this case, do as Wordpress: show the configuration file on the screen and ask the user to create a file on the server with the content displayed.

Database Migrations

How much of the database. There are some frameworks for bank migrations, such as:

  • Ruckusing Migrations : follows the philosophy of RoR (Ruby on Rails). Changes to the database are made via PHP code. Supports MySQL and PostgreSQL.
  • Doctrine Migrations : changes are specified in XML. The Doctrine project supports MySQL, PostgreSQL, SQL Server, Oracle and others, but I do not know if migrations work well on all of them.
  • Phinx: Simple PHP Database Migrations : provides another API for migrations via PHP code. See more documentation here . Supports MySQL, PostgreSQL and SQLite.

Whether you choose any of these, some other, or even create another "nail" solution, it's important to define a method so that your database can always be upgraded to the most current version when your system runs.

Considerations

Creating a self-installing system is something that can be achieved without many problems.

On the other hand, managing updates in the system life cycle can be tricky. In addition, an installation with excellent usability, intuitive and friendly as Wordpress is something that requires effort.

Remember that WP is an already very traditional system that has been evolving over the years. They know the main problems that occur in different environments and have know-how to do several environmental checks in advance, in order to anticipate possible problems. So do not expect such a good result right away.

    
26.12.2013 / 18:14
3

I note that your main goal is to have a better quality of software, especially a high degree of reuse in your code. Of course, practicality in deploy.

To improve your PHP applications , I suggest you use and study some frameworks. So you will know some architectures, good OO strategies, reuse etc. See this research on the PHP frameworks most promising for 2014 (in English). Some of these frameworks may give you this auto-install (or at least a base) functionality.

Deploy tools can help with delivery. Many of these frameworks use what's in your version control (such as git ) to package and deliver your code in a fantastic way - installing the application, doing migration, updating code etc. And whatever you want the user to do, it's not that high level is a hand on the wheel to package the application and "install" somewhere. I know that the TYPO3 Flow does this with SURF , the Symfony also .

At the same time, you could take a spin on link , a dependency manager for PHP. This tutorial gives a good overview. And there are good examples of packages at link . In any case, the responses from @utluiz and @FReNeTiC are great. I would only do this with a framework - the use accelerates productivity, quality and brings experience. Of course, everything has a counterpoint: in a scale environment, sometimes a framework may not have the best performance for a given solution.

    
17.01.2014 / 03:42
3

From a conceptual point of view, you can reduce your problem to two points: one executable file , and another file containing the files, for example, a file zip.

I'll assume you're going to use PHP. I would recommend doing everything in one file, even images, JS and CSS are in this file, to avoid

  • Create a single executable file , which, for portability reasons, should contain all Javascripts and CSSs in the interface. It can be a PHP script, Perl, Shell, and the like.
  • The executable file should be pre-validated , such as checking if the server supports the application and checking that the compressed file containing the application is not corrupted
  • Your application should be in the compressed file . The executable file should unzip your application. Then you will have to opt for two alternatives.
  • Your only executable file should ask for instructions to install the application and yourself. Eg useful when it comes to a full backup
  • Your only executable file should go to your application screen, which will be installed on the new platform
  • After installation is complete, you should remove the initial executable file, and preferably the compressed file with the application
  • If you need to do something related to updating after the application has been installed, you will need to integrate something into the application that does this. Both Joomla and Wordpress have systems that work exactly by doing this.

    Regardless of the application, the auto-update part needs to have some kind of minimal integration with the client application.

    References

    Item 3.1 is used by Akeeba Backup, one of the most famous extensions to the Joomla CMS link .

    In addition, I have worked with something similar to this. It is important that you do it in a way that is as simple as possible for the user, and give messages that make him understand that it is the fault of the server that he is in or of something he turns on (as a corrupted file).

    Pro-tip

    That kind of question you asked is only worth it if it is done on a large scale and is economically interesting. If you are not sure of this from the start, do it in the simplest way you can imagine and require the least amount of knowledge in the application you are going to use, otherwise you will have a white elephant. The way I explained is relatively easy to do , does not require elevated permissions to system functions (soon to be used on any hosting), and has option for do not force you to know much about the application you are going to use .

        
    04.02.2014 / 08:38