Installing Symfony 3+ on Reclaim Hosting from GitHub


#1

Subdomain (optional)

Create a subdomain, if you need it. Putting your Symfony app in a subdomain separates it from other things you have on your site. Example: create subdomain “phk” and map to “subdomains/phk”.

Login to the command line. Change to the parent above the Web root. e.g.:

cd ~/subdomains

Erase existing files in the Web root directory, like “~/subdomains/phk/cgi”. This will make Git cloning easier. Using the cPanel FileManager is the easiest way to erase directories.

Clone from GitHub

Clone the project from GitHub. E.g.:

git clone https://github.com/.../phk.git

You can get the URL from the home page of the project’s GitHub repository.

This will put the files in a directory with the name “phk”, so be sure to run the clone command from the parent directory, e.g., “~/subdomains”, not “~/subdomains/phk”.

Once the files are cloned, switch to the Web root directory, e.g.:

cd phk

PHP libraries

Symfony projects use PHP libraries. Those libraries are usually not added to the project on GitHub. Check for the presence of a vendor directory, e.g., “~/subdomains/phk/vendor”. If the directory exists and has lots of subdirectories in it, the dependencies (that is, the libraries) have already been included in the GitHub download. If “~/subdomains/phk/vendor” does not exist (this is the most likely case) or is empty, you will need to tell a program called Composer to install the libraries.

There will be a file called “composer.json” in the project that lists project dependencies. Run…

composer install

This may take a while, as Composer downloads all of the libraries the application needs.

Database

You may need to make a database. If it’s a MySQL database, use the MySQL database wizard in cPanel. Then you will need to edit the file “app/config/parameters.yml” to tell Symfony how to connect to the database. Your app’s documentation will tell you how. Hopefully. The database host is “localhost”. The database port is 3306.

You may need to run some commands to create the database tables, and pull in some data. The commands will be like:

php bin/console doctrine:migrations:migrate

The project’s documentation should tell you how.

Redirect

Symfony uses a front-end controller. It’s a PHP program that all Web requests go through. It’s in the “/web” directory, and is called “app.php”. There’s another file called “app_dev,php”, that gives you internal information useful for developers. You want to use “app.php” in production.

You need to tell Apache to route Web requests into the file. The “.htaccess” file (e.g., at “~/subdomains/phk/.htaccess”) lets you do that. Create the file if it doesn’t exist, and add this to the top:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteBase /web/

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>

You can edit .htaccess in cPanel’s File manager, or from the command line with:

nano .htaccess

Celebrate

You earned it.