31 C
Texas
angeloma
Senior Writer and partner

How to install Yii PHP Framework on Debian 9 and Ubuntu 18.04?

Every day we find new and better web applications. This is because more and more are being developed for the web with languages like Python, Ruby or PHP. The latter has several powerful frameworks such as Yii. Today, I will show you how to install Yii PHP on Debian 9 and Ubuntu 18.04.

In order to be pragmatic and flexible, Yii PHP was born. It is a framework for object-oriented PHP development that uses the architectural pattern MVC. What makes it ideal for developing many web applications such as forums, information sites or virtual shopping.

With Yii PHP you will have no licensing problems because it is open source (BSD Licence) which makes it ideal for community, educational or long-range projects.

So, let’s install Yii PHP Framework on Debian 9 and Ubuntu 18.04.

Install Apache web server

- Advertisement -

If you are going to start developing in PHP is necessary, install a web server. There are several options like Apache web server or Ngnix. Both valid and very good. However, for this tutorial, I will use the Apache web server.

Open a Terminal and run this command:

:~$ sudo apt install apache2

Then, enable and start the service.

:~$ sudo systemctl enable apache2
:~ sudo systemctl start apache2

Next, open a web browser and go to HTTP://localhost. If you see this, everything is OK.

Apache default page
Apache default page

Install Yii PHP Framework

Installing Yii PHP is simply because I will do it via Composer which is a dependency manager for PHP that really does wonders. So, the first step is to install Composer.

Open a terminal and run:

:~$ curl -sS https://getcomposer.org/installer | php

1.- Installing Composer
1.- Installing Composer

Now, make composer available to all users from the terminal in the form of a command.

:~$ sudo mv composer.phar /usr/local/bin/composer

2.- Installing Composer
2.- Installing Composer

Now, install Yii PHP Framework using Composer.

:~$ composer create-project --prefer-dist yiisoft/yii2-app-basic example

Note: You can change example for the name you want.

3.- Install Yii PHP Framework
3.- Install Yii PHP Framework

4.- Installing Yii PHP Framework
4.- Installing Yii PHP Framework

Now, move the created folder. In my case is example.

:~$ sudo mv example /var/www/html/

5.- Moving the created folder to apache document root
5.- Moving the created folder to apache document root

Next, move to the directory.

:~$ cd /var/www/html/example

To avoid dependency problems with Composer, it is necessary to edit a file inside the example folder.

:~$ sudo nano composer.json

And add the following:

"replace": {
    "bower-asset/jquery": ">=1.11.0",
    "bower-asset/inputmask": ">=3.2.0",
    "bower-asset/punycode": ">=1.3.0",
    "bower-asset/yii2-pjax": ">=2.0.0"
},

Like this:

6.- Editing the composer file on the project folder
6.- Editing the composer file on the project folder

Now, let’s make a Virtualhost for Yii PHP.

Copy the Apache default site configuration file. Then, edit it.

:~$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/yii.conf
:~$ sudo nano /etc/apache2/sites-available/yii.conf

And add the following:

 RewriteEngine on
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . index.php
 RewriteRule ^index.php/ - [L,R=404]

One more thing, for all Yii applications the document root is /var/www/html/PROJECT_FOLDER/web. In my case, the VirtualHost file for Yii will be something like this.

7.- Creating a VirtualHost for Yii PHP
7.- Creating a VirtualHost for Yii PHP

Then, it is necessary to assign the corresponding permissions to the folder. It is also necessary to change the owner of the folder to avoid permission problems.

:~$ sudo chown -R www-data:www-data /var/www/html/example/
:~$ sudo chmod -R 777 /var/www/html/example/*

8.- Settings the appropriate permissions to project folder
8.- Settings the appropriate permissions to the project folder

Next, enable the VirtualHost, the rewrite module and finally, restart Apache.

:~$ sudo a2ensite yii.conf
:~$ sudo a2enmod rewrite
:~$ sudo systemctl restart apache2

8.- Making the last configurations to Yii
9.- Making the last configurations to Yii

Now start the Yii service. By default, Yii uses port 8080 but you can specify another port if it is busy or unavailable.

:~$ php yii serve --port=8888

10.- Starting Yii PHP
10.- Starting Yii PHP

Now, open your web browser and go to HTTP://localhost:8888.

11.- Yii default page
11.- Yii default page

That message indicates that everything went right.

Conclusion

Yii e sun framework PHP for the development of simple and complex applications standing out for its high performance. It is open source and very well supported at the community level.

Please share this article through your social networks.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article