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
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.
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
Now, make composer available to all users from the terminal in the form of a command.
:~$ sudo mv composer.phar /usr/local/bin/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.
Now, move the created folder. In my case is example.
:~$ sudo mv example /var/www/html/
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:
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.
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/*
Next, enable the VirtualHost, the rewrite module and finally, restart Apache.
:~$ sudo a2ensite yii.conf :~$ sudo a2enmod rewrite :~$ sudo systemctl restart apache2
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
Now, open your web browser and go to HTTP://localhost:8888
.
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.