About Symfony Application:-
It is an open source framework used in creating web applications and it is useful to develop projects of different requirements, as well as complex or simple and of any size. Below are some benefits of the Symfony Application:
- Symfony platform is a Open source framework so easily available in market
- Well-designed structure
- It gives flexibility to reuse components
- Symfony Application work on different environment like development or production
- Fresh copy of Ubuntu 14.04 running LAMP or LEMP
- Sudo Non – root user
- How to create sudo Non – Root user
- Connect to server with root user so we will have all adequate permissions to add new user
- At prompt write “useradd <UserName>” replace <UserName> with the name of user you want to create
- How to create sudo Non – Root user
- Edit hostname in both both /etc/hosts and /etc/hostname files
- Restart the server
- Add a sudo entry for your new user
- At prompt in shell give sudo visudo which will open a file where you will find root user replace that with your new username
- Create home folder for new user and then give user permissions with the help of chown
- Set a password for the new user with sudo passwd <UserName> and last but not the least add following line to /etc/passwd file
Reboot the server again in order for changes to take effect .
How to install Symfony Application to Production on Ubuntu Server:
Step – 1: Installing the server dependencies
In order to install the server execute following command
sudo apt-get update
Below command will install the required packages:
sudo apt-get install git php5-cli php5-curl acl
is use for checking the application files
is use for setting but the right directory permissions while installing the application
to run PHP on command line
In order to download the application dependencies we will also need composer for that execute below command:
sudo curl –sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin –filename=composer
Step – 2: Configuring MySQL
Assuming that you have install the MySQL, do the below steps to configure MySQL:
Step – 2.1 MySQL Configuration:-
- Setting the Default Collation and Charset – it is necessary as Symfony requires charset and collation of your database to be set to utf8. Perform below steps to change the same
- Open the file “/etc/mysql/my.cnf” by executing sudo nano “/etc/mysql/my.cnf”
- Under that find “[mysqld]” block and add the “collation-server” and “character-set-server” options under Basic Settings Save, Exit and Restart MySQL
sudo service mysql restart Step – 2.2: Creating a User and a Database for the Application
In order to create a user and database for the application do below steps:
- Access MySQL Client with MySQL root account
$ mysql –u root –p
- Supply Correct MySQL Root Password.
- Once connected, Now create a database
mysql>CREATE DATABASE <databasename>(replace <databsaename> with name of database which you want to create.
- Once database is created, we need to create new user and give necessary permission to that user in order access our newly created database
mysql>CREATE USER ‘<username>’@’localhost’ IDENTIFIED BY ‘<password>’;press Enter (replace <username> with name of user you want to create and <password> with password you want use for that user you created.
- Grant right permission to newly create user
mysql>GRANT ALL PRIVILEGES ON <username>.* To ‘<username>-user’@’localhost’;
- In order to apply changes use
Mysql>FLUSH PRIVILEGES Quit
- Now login again with new username and password we created and check database by executing
Step – 3: Verify Application Code
For this step you can use any application which you have built with Symfony to verify the code for which GIT command is use and you will need to choose a location which server as
application root directory and later apply permission needed on the same and lastly clone the application
Step – 4: Fixing folder permission for web server user
In previous step we choose location and clone our application but here our web server will also need access to those file. Moreover, apart from web server “app/cache/” and “app/logs/” also need special permission on the same. In order to configure those permissions use ACL (Access Control Lists) for configuring these special permissions.
Step – 5: Setting Up Application:
We already have now the application files in place, but still need to install the project dependencies and configure the application parameters. As symphony is built to work across different environments, so to make symphony application work we need to define environment by executing
$ export SYMFONY_ENV=prod
Next need to install project dependencies
cd <application path> composer install --no-Dev –optimize-auto loader
At the end of installation, it will prompt you to provide some information which will populate in “parameters.yml” file which has important information for the application like the database connection settings Press enter and accept default value
On finishing the installation check database connectivity by executing
$ php app/console doctrine:schema:validate
In output OK line means database connection is proper and FAIL line means we have not created the database schema which needs to be created
Once that is done lastly generate the application assets.
Step – 6: Setting up the web server
In order to setting up the web server you will need to 1. Set up date.timezone directive in php.ini file and update the default website config file either on Apache or Nginx which is serving our application accompanied with service restart.
Perform below steps for both Configuring Steps for Nginx + PHP-FPM and Apache + PHP5 Web server:
- Open “ini” file
- Locate timezone | Uncomment that, Save, Exit and Restart the server
- Replace Default website config with one serving a Symfony application. http://<yourserverip> in your browser and verify that the page which you setup is accessible or not.
This was our article which has made you learn to deploy a Symfony apps (Projects) to Production on Ubuntu VPS Server . If you have any queries related to this article then do lend your confusion in comment section .