How to install Symfony3 under shared webhosting in Developement mode
1. Log in to SSH
2. Install Composer (We assume that composer is not yet installed):
export COMPOSERDIR=~/bin;mkdir bin curl -sS https://getcomposer.org/installer | php -- --install-dir=$COMPOSERDIR --filename=composer
(Composer will be installed under: /home/username/bin/composer )
3. To test that installation was successful – You can run:
~/bin/composer
4. Make environment global INSTALLDIR:
export INSTALLDIR=~/public_html/symfony mkdir $INSTALLDIR
(Assuming that Your webhosting has public_html under Your userdir – if not, that variable needs to be changed accordingly!)
5. Note down You settings/credentials for following:
– database_host (localhost is recommended)
– database_port (usually 3306)
– database_name (use different already created DB)
– database_user (your mysql username for that DB)
– database_password (your mysql user password for that DB)
– mailer_transport (smtp is recommended using AUTHENTICATION!)
– mailer_host (smtp servers hostname)
– mailer_user (e-mail username to authenticate)
– mailer_password (e-mail usernames password to authenticate)
6. Install Symfony3 via newly created composer to INSTALLDIR:
~/bin/composer create-project symfony/framework-standard-edition $INSTALLDIR
7. Check and correct all Files/Folders permissions:
find $INSTALLDIR/ -type f -exec chmod 644 {} \; find $INSTALLDIR/ -type d -exec chmod 755 {} \;
8. Add/check .htaccess (For Apache 2.4):
# To switch to production mode from dev mode, comment out all directives where # app_dev.php appears, and uncomment all directives where app.php appears. RewriteEngine on RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ # Apache RewriteRule ^(.*) - [E=BASE:%1/web] # Redirect to URI without front controller to prevent duplicate content # So in case you get a "too many redirects" error or you always get redirected # to the start page because your Apache does not expose the REDIRECT_STATUS # environment variable, you have 2 choices: # - disable this feature by commenting the following 2 lines or # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the # following RewriteCond (best solution) RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteRule ^app_dev\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] #RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] RewriteCond %{REQUEST_FILENAME} -f RewriteRule .? - [L] # Rewrite all other queries to the front controller. RewriteRule .? %{ENV:BASE}/app_dev.php [L] #RewriteRule .? %{ENV:BASE}/app.php [L]
9. To allow Your own IP access to Symfony3 in DEV mode:
– open app_dev.php
vi $INSTALLDIR/web/app_dev.php
– Find row “!(in_array(@$_SERVER[‘REMOTE_ADDR’], array(‘127.0.0 …….” and add Your IP to array
10. Modify Symfony3 router to work with Installed subdirectory:
echo ' prefix: /symfony' >> $INSTALLDIR/app/config/routing.yml sed -i.bak 's/\/_/\/symfony\/_/g' $INSTALLDIR/app/config/routing_dev.yml
Your installation is complete and may be accessed by You from YOUR IP from Your domains subfolder.
Additional/common tasks
1. Keeping all Symfony3 components up-to-date:
cd $INSTALLDIR ~/bin/composer update
2. To view more about the Symfony console:
cd $INSTALLDIR php app/console
All local mail sent out via external smarthost (Exim4 on Ubuntu 16.04) Fix for old code when GLOBALS are needed on newer PHP versions