Home / Linux / How to Install Yii PHP Framework on CentOS 8

How to Install Yii PHP Framework on CentOS 8

How to Install Yii PHP Framework on CentOS 8

Yii is an open-source, high-performance, versatile, environment friendly and safe PHP framework for quickly constructing fashionable Web functions. It is a generic and full-stack net programming framework for writing code in an object-oriented trend and offers many confirmed and ready-to-use options. It comes with quite a lot of affordable defaults and built-in instruments that assist you write strong and safe code.

Yii Features

Here are a few of Yii’s key options:

  • A pure OOP-based framework.
  • A component-based structure.
  • Implements the MVC (Model-View-Controller) architectural sample.
  • Supports question builders and ActiveRecord for each relational and NoSQL databases.
  • Multi-tier caching help.
  • RESTful API growth help.
  • It’s extraordinarily extensible permitting customers to customise or substitute any piece of code proper from the core. Besides, customers can use or develop redistributable extensions.

Yii 2.zero is the present technology of the framework (on the time of writing) which requires PHP 5.four.zero or above however runs finest with the most recent model of PHP 7. It helps a few of the newest Web applied sciences and protocols, together with Composer, PSR, namespaces, traits, and others.

Being a generic Web growth framework at the side of its important options, Yii can be utilized to develop almost any sorts of Web functions from consumer/admin portals, boards, content material administration programs (CMS), to e-commerce initiatives, RESTful Web providers, and far more at giant scale.


  1. A operating occasion of the CentOS 8 server.
  2. A LAMP or LEMP stack with PHP 5.four.zero or above.
  3. A Composer – an application-level package deal supervisor for the PHP.

In this text, we’ll present you ways to set up the Yii PHP framework on a CentOS 8 server to begin creating PHP functions utilizing Yii.

Installing Yii Using Composer

There are a number of methods to set up Yii, however the really helpful manner to set up Yii is utilizing Composer package deal supervisor, because it permits you to replace Yii with a single command and likewise permits you to set up new extensions.

If you don’t have already got Composer put in on your CentOS 8 server, you may set up it by operating the next instructions.

# curl -sS https://getcomposer.org/installer | php
# mv composer.phar /usr/native/bin/composer
# chmod +x /usr/native/bin/composer
Install Composer in CentOS 8Install Composer in CentOS 8

Install Composer in CentOS 8

With Composer put in, you may set up the most recent secure model of Yii utility template beneath an Apache or Nginx Web-accessible listing referred to as testapp. You can choose a special listing identify if you would like.

# cd /var/www/html/      [Apache Root Directory]
# cd /usr/share/nginx/html/   [Nginx Root Directory]
# composer create-project --prefer-dist yiisoft/yii2-app-basic testapp
Install Yii PHP Framwork in CentOS 8Install Yii PHP Framwork in CentOS 8

Install Yii PHP Framework in CentOS 8

After set up is full, both configure your net server (see subsequent part) or use the built-in PHP net server by executing the next command within the testapp mission root listing.

# cd testapp
# php yii serve

Note: By default, the HTTP-server will pay attention to port 8080. However, if that port is already in use, you should utilize the totally different port by including --port the argument as proven.

# php yii serve --port=8888
Verify Yii InstallationVerify Yii Installation

Verify Yii Installation

Now, open your browser and kind the next URL to entry the put in Yii utility.

Yii ApplicationYii Application

Yii Application

Configuring Web Servers for Yii

On a manufacturing server, you may want to configure your webserver to serve the Yii net utility through the URL http://www.example.com/index.php as an alternative of http://www.example.com/basic/testapp/index.php. In that case, you could level your net server doc root to the testapp/net listing.

Recommended Nginx Configuration

Create a configuration file referred to as /and many others/nginx/conf.d/testapp.conf.

# vi /and many others/nginx/conf.d/testapp.conf

Next, copy and paste the next configuration in it. Remember to substitute tecmintapp.lan along with your area identify and /usr/share/nginx/html/testapp/net with the trail the place your app information are situated.

server png

Save the file and restart the Nginx to impact the latest modifications.

# systemctl restart nginx

Recommended Apache Configuration

Use the next configuration in Apache’s httpd.conf file or inside a digital host configuration.

# Set doc root to be "testapp/web"
DocRoot "/var/www/html/testapp/web"

<Directory "/var/www/html/testapp/web">
    # use mod_rewrite for fairly URL help
    RewriteEngine on
    # if $showScriptName is fake in UrlManager, don't enable accessing URLs with script identify
    RewriteRule ^index.php/ - [L,R=404]
    # If a listing or a file exists, use the request immediately
    RewriteCond % !-f
    RewriteCond % !-d
    # Otherwise ahead the request to index.php
    RewriteRule . index.php

    # ...different settings...

Save the file and restart the Apache to impact the latest modifications.

# systemctl restart httpd

Testing Yii Web Application Via a Browser

Before testing our Yii net utility be certain to replace the safety context of the /net/belongings/ listing to make it writable to the online course of, by operating the next command.

# chcon -R -t httpd_sys_content_rw_t '/usr/share/nginx/html/testapp/net/belongings/' [for Nginx]
# chcon -R -t httpd_sys_content_rw_t '/var/www/html/testapp/net/belongings/'         [for Apache] 

Next, replace your firewalld guidelines to enable HTTP and HTTPS requests by way of the firewall to the Nginx server.

# firewall-cmd --zone=public --add-service=http --permanent
# firewall-cmd --zone=public --add-service=https --permanent
# firewall-cmd --reload

Finally, take a look at in case your net utility working nice and is being served by Nginx or Apache. Open an internet browser and level it to the next handle:


The default Yii utility net web page ought to show as proven within the following screenshot.

Yii Web App PageYii Web App Page

Yii Web App Page

Congratulations! You have efficiently put in the most recent technology of the Yii PHP framework and configured it to work with Nginx or Apache on CentOS 8.

For extra data and the way to begin utilizing Yii for constructing your net utility, see the Yii definitive information.

About Agent

Check Also

SpaceX Successfully Launches 60 More Starlink Satellites as it Continues Towards 2020 Service Debut

SpaceX Successfully Launches 60 More Starlink Satellites as it Continues Towards 2020 Service Debut SpaceX …

Leave a Reply

Your email address will not be published. Required fields are marked *