Installing PHP Framework CodeIgniter On Linux.CodeIgniter is a fairly popular PHP framework focused primarily on building web applications quickly. The key features of CodeIgniter are its impressive speed. And an unusually low barrier to entry for newbies and novice developers. This framework is especially appreciated by fans of creating “from scratch” their sites and even CMS (content management systems), since CodeIgniter is really quite easy to learn and use. Often, web hosting clients are interested in the possibility of pre-installing this framework on the hosting. This article will cover both the installation of CodeIgniter itself and the basics of laying the “foundation” for building web applications (sites) based on it.
Content:
How does it work?
CodeIgniter distribution kit
Installing CodeIgniter
Providing additional security
Conclusion
Table of Contents
How does it work?
The CodeIgniter framework is built on the MVC (Model View Controller) architecture. Which assumes a high degree of separation of the logic of work and data display. In other words, there are several functional layers in the model, that is, PHP code, data, and display are clearly separated.
The core of the framework can be installed separately in the system – this is the functional layer. To which the control layer (controllers) is connected. The latter can (and should, unlike the core of the framework) be supplemented, modified in accordance with the ideas of the developers who create the web application, that is, it is the backend. Another layer is displays or “Views”. Nothing more than rendering and styling on pages in a web browser – frontend. This concept allows parallel development by several project participants much more efficiently. Without thinking about implementing the interaction between the layers (controllers and views). Since they are provided by the very architecture of CodeIgniter.
CodeIgniter distribution kit
The purpose of the main components of the CodeIgniter distribution reveals the principle of building web applications themselves based on it:
- The system is a directory containing, in fact, the core of the framework itself. Which can be taken out separately. The place where third-party executable files and system libraries are stored (for example, in the / opt file system on a separate partition) with the appropriate safe permissions for ordinary users;
- application – a directory containing a functional layer of the web application (site) itself. And in which the developers add and implement its logic of work. This is the backend of the project;
- root and index.php file – This is the root directory of the web application and its index file. Auxiliary subdirectories with web application resources are usually added here – skins (views), icons, images, etc., i.e. frontend.
The application directory stores child controllers (developer-defined) inherited from the parent controller (CI_Controller). Which is implemented in the core of CodeIgniter from the system directory. Thus, building web applications on the CodeIgniter framework is nothing more than expanding and spreading the capabilities of the framework based on object-oriented programming paradigms. The extension itself is made in the application directory. You can also add new or third-party libraries here. By connecting them to the kernel through child controllers. At the same time, without affecting or modifying the code of the very core of the CodeIgniter framework in the system directory.
Installing CodeIgniter
So, first, you need to download the CodeIgniter distribution from the official website page:
$ wget https://github.com/bcit-ci/CodeIgniter/archive/3.1.10.zip
Now you can immediately unpack all the contents of the downloaded archive into the directory with the virtual hosts of the webserver, in this case, it is the htdocs / directory in the user’s home directory:
$ unzip 3.1.10.zip -d ~ / htdocs
As a result, the full path to the framework will be as follows:
/home/john/htdocs/CodeIgniter-3.1.10
In this case, all actions, as you can see, take place for the john user account. At this stage, you should pay attention to the fact that the CodeIgniter-3.1.10 directory also contains the framework (the system directory). And the actual framework of the web application itself (application directory and index.php file) that uses this framework. Nobody forbids “carrying” the framework with you. However, it is more expedient (after all, this is a framework) and safer to move it, as noted above, to a separate place. Next, in the index file of the web application /index.php, you need to specify the location of the framework using an absolute path. By setting the appropriate variable in this file, for example:
$ system_path = ‘/opt/codeigniter-3.1.10/system’;
Now you need to actually install the CodeIgniter framework by taking it out separately. This will make it available to all users on the system:
$ sudo mv ~ / htdocs / CodeIgniter-3.1.10 / system /opt/codeigniter-3.1.10/
In doing so, you must, of course, make sure that the /opt/codeigniter-3.1.10appropriate access rights are set for the directory and its contents so that other users can use it without compromising security. You can also rename the directory with the CodeIgniter-3.1.10 test virtual host for convenience:
$ mv ~ / htdocs / CodeIgniter-3.1.10 ~ / htdocs / codeigniter-test
You also need to make sure the web application frontend in ~ / htdocs / codeigniter-test uses the appropriate application subdirectory. There is a separate variable for this in the index.php file:
$ application_folder = ‘application’;
Now you need to configure the webserver virtual host for the directory ~/htdocs/codeigniter-test and go to the corresponding address in your web browser:
This completes the installation and basic configuration of the CodeIgniter framework. With this installation option, that is, when web application developers do not need to “carry around” the CodeIgniter framework. The server administrator needs to provide information about the location of CodeIgniter on the system. Users simply plug in the framework already installed on the server for their applications using the application index file, as described above. Naturally, the place for installing CodeIgniter, in this case, should meet the optimal security requirements of the administered server.
Providing additional security
In general, to protect a web application from direct access to its files on the server (you never know what a hole may appear on the hosting), you can also move the application directory. Somewhere outside of the virtual host root of the web application itself. In this case, the directory is Codeigniter-test. You can also change the location of the Views directory. Which is set by the $ view_folder variable in the index.php file of the web application. By default, this directory has a location /application/views/.
How to ensure security and how to work with the CodeIgniter framework, in general, can be read in more detail on the pages of the official manual in the form of HTML help. Shipped directly with the CodeIgniter distribution in the user_guide subdirectory and accessible via the index.html file.
Conclusion
In conclusion, it should be noted that installing CodeIgniter on the server is just an additional step towards meeting users and/or clients of the system to simplify the use of the framework. Advanced users and developers, as you can see from this article, can independently use it regardless of the existing server configuration.
For professional services or consultation from GCC Marketing Dubai please Contact Us or call us directly on 00971567300683