Once you start using Symfony framework sooner or later you will need to publish your work. Digital Ocean is a perfect hosting solution. In this tutorial I will show you how to run generic Symfony Standard on Digital Ocean.
The assumption is that you How to use SSH keys to access Digital Ocean droplet already.
2. Create a new droplet
Log in to you Digital Ocean account, press Create button and select the droplet LAMP on Ubuntu 14.04.
developerSSH key for this droplet. The procedure to generate and configure the key is described in the post titled: How to use SSH keys to access Digital Ocean droplet
3. Check ssh access
Verify that your ssh key was configured correctly. Run the command:
$ ssh DigitalOcean
It should start ssh session to your newly created droplet.
4. Install missing software
The default droplet configuration misses the following software that we will need:
- apache module mod_rewrite
To install it, run the following commands (they all should be executed inside ssh session to your droplet):
$ apt-get update -y $ apt-get install git -y $ apt-get install php5-curl -y $ a2enmod rewrite $ cd $ curl -sS https://getcomposer.org/installer | php $ mv composer.phar /usr/local/bin/composer
sudobefore each of them.
5. Clone Symfony Standard
Using ssh session to your droplet clone the Symfony Standard
$ mkdir /apps $ cd /apps $ mkdir my-new-app $ cd my-new-app $ git clone https://github.com/symfony/symfony-standard.git .
I will use the default application included in v2.3.23 distribution. This is a single webpage with the message Homepage.
Run the command:
$ git checkout -b the-app v2.3.23
You will have a branch named
the-app with the
Symfony Standard v2.3.23.
Now we need to install dependencies.
6. Install dependencies
The commands shown below should also be executed inside your droplet’s ssh console:
$ cd /apps/my-new-app $ composer install
You will be asked a couple of questions:
database_driver (pdo_mysql): database_host (127.0.0.1): database_port (null): database_name (symfony): database_user (root): database_password (null): mailer_transport (smtp): mailer_host (127.0.0.1): mailer_user (null): mailer_password (null): locale (en): secret (ThisTokenIsNotSoSecretChangeIt):
Use default values for all of them. Just press enter as many times as you are asked anything.
Now we can publish the project. To do this we need to change file ownership and reconfigure Apache.
7. Change the owner
Change the owner of all files stored within
to Apache user (e.g.
$ chown -R www-data:www-data /apps
8. Reconfigure Apache’s public html dir
By default, Apache publishes the contents of
We will replace it with a symbolic link to our project.
$ rm -rf /var/www/html
Create a new symbolic link:
$ ln -s /apps/my-new-app/web /var/www/html
9. Reconfigure Apache
Edit the file
$ vi /etc/apache2/apache2.conf
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride None <=== this is to be changed Require all granted </Directory>
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All <=== new valued here Require all granted </Directory>
The above change turns on
.htaccess files in
and its subdirectories.
10. Restart the Apache
Run either of the two commands:
$ /etc/init.d/apache2 restart $ service apache2 restart
11. Visit your app
Start your browser and visit:
You should see:
The IP comes from your droplet configuration.