CyberPanel
Using Composer create Symfony application on CyberPanel!

Using Composer create Symfony application on CyberPanel!

Symfony is a rich web application framework based on PHP. They describe symfony as a set of useable decoupled components. Because if you don’t need to use the complete framework you can use components from a framework in your application.

Or even base your own framework on Symfony. Laravel is based on Symfony and Drupal inherits many components from Symfony. In this article, we will be using composer to create a symfony application on CyberPanel.

Step 1: Install CyberPanel!

First, you need to get CyberPanel installed. CyberPanel is a web hosting control panel based on OpenLiteSpeed web server.

You will need a fresh install of CentOS 7.

wget http://cyberpanel.net/install.tar.gz
tar zxf install.tar.gz
cd install
chmod +x install.py
python install.py [IP Address]

Replace IP Address with your vps/dedicated server IP Address. For more details visit installation.

Step 2: Install Composer!

To install Composer you need php-cli. CyberPanel comes with PHP 5.3, 5.4, 5.5, 5.6, 7.0, 7.1. We will use php-cli from PHP 7.1 because Symfony 4 requires php 7.1 and above. You can copy PHP 7.1 binary, so that it is available globally.

cp /usr/local/lsws/lsphp71/bin/php /usr/bin/

With this, you can use php-cli by just trying ‘php’. You can verify this using ‘php -v’.

php -v

You should get :

PHP 7.1.12 (cli) (built: Nov 24 2017 02:33:55) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.12, Copyright (c) 1999-2017, by Zend Technologies

That means you are ready to install composer. To install composer use these commands:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

You can use composer project-wise, but for convenience, you can copy composer binary to a global location using:

cp composer.phar /usr/bin/composer

Now composer is also available globally and you can invoke it just using ‘composer’ command. With all this behind us, we are ready to create our first site and launch a Symfony application.

Step 3: Create Website!

To launch your Symfony application, you need to create a website in your CyberPanel.

From left menu click ‘Create Website’, enter all details and make sure to select ‘PHP 7.1’ because Symfony 4 requires PHP 7.1 and above.

Once the website is successfully created you can use composer to create a Symfony web application.

Step 4: Create Symfony Application

You need to have SSH access to use composer and create Symfony application, the home directory of every CyberPanel website looks like /home/example.com/public_html. Following this directory structure, you can now create your application.

cd /home/symfony.cyberpanel.net/public_html
composer create-project symfony/skeleton cyberpanel

These commands will create a Symfony application with appropriate directory structure, you can replace cyberpanel with the project name that you would like to give to your application.

Visit http://example.com/cyberpanel/public and you should see something like this:

This means you have successfully created Symfony application.

Step 5: Edit Rewrite Rules!

Like all frameworks, Symfony has its own rewrite engine which dispatches requests to different controllers depending on the path in URL, and there is only one front file named index.php which handles all requests and routes them accordingly. You need to specify rewrite rules so that all requests are dispatched to index.php

RewriteRule . /cyberpanel/public/index.php [L]

cyberpanel here is the project name, you can replace it with the project name you used. Follow following guides to set up these rewrite rules:

Setup Rewrite Rules on CyberPanel

10 thoughts on “Using Composer create Symfony application on CyberPanel!

Leave a Reply

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