You can install Yii in two ways, using [Composer](http://getcomposer.org/) or downloading an archive file.
You can install Yii in two ways, using [Composer](http://getcomposer.org/) or by downloading an archive file.
The former is the preferred way as it allows you to install new [extensions](structure-extensions.md)
The former is the preferred way, as it allows you to install new [extensions](structure-extensions.md) or update Yii by simply running a single command.
or update Yii by running a single command.
> Note: Unlike with Yii 1, standard installations of Yii 2 results in both the framework and an application skeleton being downloaded and installed.
Installing via Composer <a name="installing-via-composer"></a>
Installing via Composer <a name="installing-via-composer"></a>
-----------------------
-----------------------
If you do not already have Composer installed, you may get it by following the instructions at
If you do not already have Composer installed, you may do so by following the instructions at
[getcomposer.org](https://getcomposer.org/download/), or simply
[getcomposer.org](https://getcomposer.org/download/). On Linux and Mac OS X, you'll run the following commands:
* on Linux or Mac, run the following commands:
```
```
curl -s http://getcomposer.org/installer | php
curl -s http://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
mv composer.phar /usr/local/bin/composer
```
```
* on Windows, download and run [Composer-Setup.exe](https://getcomposer.org/Composer-Setup.exe).
On Windows, you'll download and run [Composer-Setup.exe](https://getcomposer.org/Composer-Setup.exe).
Please refer to the [Composer Documentation](https://getcomposer.org/doc/) if you encounter any
Please refer to the [Composer Documentation](https://getcomposer.org/doc/) if you encounter any
problems or want to learn more about the Composer usage.
problems or want to learn more about Composer usage.
With Composer installed, you can install Yii by running the following command under a Webaccessible folder:
With Composer installed, you can install Yii by running the following command under a Web-accessible folder:
Verifying the Installation <a name="verifying-installation"></a>
----------------------
----------------------
After installation, you can use your browser to access the installed Yii application with the following URL,
After installation, you can use your browser to access the installed Yii application with the following URL:
assuming you have installed Yii in a directory named `basic` that is under the document root of your Web server
and the server name is `hostname`,
```
```
http://hostname/basic/web/index.php
http://hostname/basic/web/index.php
```
```
(This URL assumes you have installed Yii in a directory named `basic`, directly under the Web server document root directory,
and that the server name is `hostname`.)
![Successful Installation of Yii](images/start-app-installed.png)
![Successful Installation of Yii](images/start-app-installed.png)
You should see the above "Congratulations!" page in your browser. If not, please check if your PHP installation satisfies
You should see the above "Congratulations!" page in your browser. If not, please check if your PHP installation satisfies
Yii's requirements by using one of the following approaches:
Yii's requirements. You can check if the minimum requirements are met using one of the following approaches:
* Use a browser to access the URL `http://hostname/basic/requirements.php`
* Use a browser to access the URL `http://hostname/basic/requirements.php`
* Run the following commands:
* Run the following commands:
...
@@ -86,8 +86,7 @@ Yii's requirements by using one of the following approaches:
...
@@ -86,8 +86,7 @@ Yii's requirements by using one of the following approaches:
php requirements.php
php requirements.php
```
```
You should configure your PHP installation so that it meets the minimum requirement of Yii.
You should configure your PHP installation so that it meets the minimum requirements of Yii. Most importantly, you should have PHP 5.4 or above. You should also install
In general, you should have PHP 5.4 or above. And you should install
the [PDO PHP Extension](http://www.php.net/manual/en/pdo.installation.php) and a corresponding database driver
the [PDO PHP Extension](http://www.php.net/manual/en/pdo.installation.php) and a corresponding database driver
(such as `pdo_mysql` for MySQL databases), if your application needs a database.
(such as `pdo_mysql` for MySQL databases), if your application needs a database.
...
@@ -95,32 +94,32 @@ the [PDO PHP Extension](http://www.php.net/manual/en/pdo.installation.php) and a
...
@@ -95,32 +94,32 @@ the [PDO PHP Extension](http://www.php.net/manual/en/pdo.installation.php) and a
Configuring Web Servers <a name="configuring-web-servers"></a>
Configuring Web Servers <a name="configuring-web-servers"></a>
-----------------------
-----------------------
> Info: You may skip this sub-section for now if you are just test driving Yii with no intention
> Info: You may skip this subsection for now if you are just test driving Yii with no intention
of deploying it to a production server.
of deploying it to a production server.
The application installed according to the above instructions should work out of box with either
The application installed according to the above instructions should work out of box with either
an [Apache HTTP server](http://httpd.apache.org/) or an [Nginx HTTP server](http://nginx.org/), on
an [Apache HTTP server](http://httpd.apache.org/) or an [Nginx HTTP server](http://nginx.org/), on
either Windows or Linux.
Windows, Mac OS X, or Linux.
On a production server, you may want to configure your Web server so that the application can be accessed
On a production server, you may want to configure your Web server so that the application can be accessed
via the URL `http://hostname/index.php` instead of `http://hostname/basic/web/index.php`. This
via the URL `http://hostname/index.php` instead of `http://hostname/basic/web/index.php`. Such configuration
requires pointing the document root of your Web server to the `basic/web` folder. And you may also
requires pointing the document root of your Web server to the `basic/web` folder. You may also
want to hide `index.php` from the URL, as described in the [URL Parsing and Generation](runtime-url-handling.md) section.
want to hide `index.php` from the URL, as described in the [URL Parsing and Generation](runtime-url-handling.md) section.
In this subsection, we will show how to configure your Apache or Nginx server to achieve these goals.
In this subsection, you'll learn how to configure your Apache or Nginx server to achieve these goals.
> Info: By setting `basic/web` as the document root, you also prevent end users from accessing
> Info: By setting `basic/web` as the document root, you also prevent end users from accessing
your private application code and sensitive data files that are stored in the sibling directories
your private application code and sensitive data files that are stored in the sibling directories
of `basic/web`. This makes your application more secure.
of `basic/web`. Denying access to those other folders is a producent security improvement.
> Info: If your application will run in a shared hosting environment where you do not have the permission
> Info: If your application will run in a shared hosting environment where you do not have permission
to modify its Web server setting, you may adjust the structure of your application. Please refer to
to modify its Web server configuration, you may still adjust the structure of your application for better security. Please refer to
the [Shared Hosting Environment](tutorial-shared-hosting.md) section for more details.
the [Shared Hosting Environment](tutorial-shared-hosting.md) section for more details.