On ne crée pas de projets symfony tous les jours c’est vrai, mais le processus est souvent le même. En plus de cela, je trouve les manip’ un peu pénible quand il faut toucher à la configuration Apache2. Inspiré de cet article http://www.nacho-martin.com/automating-the-creation-of-new-symfony-1-4-projects-doctrine-git, j’ai écrit ma propre commande incluant la configuration d’un vhost Apache2. Je la partage ici.
Voici donc le script mkSfProject :
#!/bin/bash
SYMFREPO="http://github.com/vjousse/symfony-1.4.git"
DBUSER="us3r"
DBPASS="p4ssw0rd"
VENDOR_DIR="lib/vendor/symfony"
AUTHOR="William DURAND <william .durand1@gmail.com>"
PHP="/usr/bin/php"
if [ -z "$DBPASS" ]; then
echo edit $0 to add your mysql password on line 4: DBPASS=\"password\"
exit
fi
if [ -z "$1" ]; then
echo usage: $0 project_name
exit
fi
# Create the project directory
mkdir $1
cd $1
git init
git clone $SYMFREPO $VENDOR_DIR
git submodule add $SYMFREPO $VENDOR_DIR/
git submodule foreach 'git submodule init && git submodule update'
git commit -m 'Initial commit; initialized symfony-git (1.4)'
# Generate the project
$PHP $VENDOR_DIR/data/bin/symfony generate:project $1
# Configure the author
$PHP symfony configure:author "$AUTHOR"
# Create the .gitignore file
echo "config/databases.yml" > .gitignore
echo "cache/*" >> .gitignore
echo "log/*" >> .gitignore
# Fix permissions
$PHP symfony project:permissions
# Commit
git add .
git commit -m 'Initialized symfony project'
# Generate a default app and commit
$PHP symfony generate:app frontend
git add .
git commit -m 'Initialized frontend application'
# Create the database and configure it in symfony
mysqladmin -u$DBUSER -p$DBPASS create $1
$PHP symfony configure:database "mysql:dbname=$1;hostname=localhost" $DBUSER $DBPASS
# Create the local URL
URL_PROJECT=`echo "$1.local" | tr '[[:upper:]]' '[[:lower:]]'`
# vhost config
sudo echo "
<virtualhost *:80>
ServerName $URL_PROJECT
DocumentRoot \"`pwd`/web\"
DirectoryIndex index.php
<directory \"`pwd`\">
AllowOverride All
Allow from all
</directory>
Alias /sf \"`pwd`/lib/vendor/symfony/data/web/sf\"
<directory \"`pwd`/lib/vendor/symfony/data/web/sf\">
AllowOverride All
Allow from All
</directory>
</virtualhost>
" > "/etc/apache2/sites-available/$1"
# Add local url in /etc/hosts
sudo echo "127.0.0.1 $URL_PROJECT" >> /etc/hosts
# Enable the vhost
sudo a2ensite $1
# Reload Apache2
sudo /etc/init.d/apache2 reload
SYMFREPO="http://github.com/vjousse/symfony-1.4.git"
DBUSER="us3r"
DBPASS="p4ssw0rd"
VENDOR_DIR="lib/vendor/symfony"
AUTHOR="William DURAND <william .durand1@gmail.com>"
PHP="/usr/bin/php"
if [ -z "$DBPASS" ]; then
echo edit $0 to add your mysql password on line 4: DBPASS=\"password\"
exit
fi
if [ -z "$1" ]; then
echo usage: $0 project_name
exit
fi
# Create the project directory
mkdir $1
cd $1
git init
git clone $SYMFREPO $VENDOR_DIR
git submodule add $SYMFREPO $VENDOR_DIR/
git submodule foreach 'git submodule init && git submodule update'
git commit -m 'Initial commit; initialized symfony-git (1.4)'
# Generate the project
$PHP $VENDOR_DIR/data/bin/symfony generate:project $1
# Configure the author
$PHP symfony configure:author "$AUTHOR"
# Create the .gitignore file
echo "config/databases.yml" > .gitignore
echo "cache/*" >> .gitignore
echo "log/*" >> .gitignore
# Fix permissions
$PHP symfony project:permissions
# Commit
git add .
git commit -m 'Initialized symfony project'
# Generate a default app and commit
$PHP symfony generate:app frontend
git add .
git commit -m 'Initialized frontend application'
# Create the database and configure it in symfony
mysqladmin -u$DBUSER -p$DBPASS create $1
$PHP symfony configure:database "mysql:dbname=$1;hostname=localhost" $DBUSER $DBPASS
# Create the local URL
URL_PROJECT=`echo "$1.local" | tr '[[:upper:]]' '[[:lower:]]'`
# vhost config
sudo echo "
<virtualhost *:80>
ServerName $URL_PROJECT
DocumentRoot \"`pwd`/web\"
DirectoryIndex index.php
<directory \"`pwd`\">
AllowOverride All
Allow from all
</directory>
Alias /sf \"`pwd`/lib/vendor/symfony/data/web/sf\"
<directory \"`pwd`/lib/vendor/symfony/data/web/sf\">
AllowOverride All
Allow from All
</directory>
</virtualhost>
" > "/etc/apache2/sites-available/$1"
# Add local url in /etc/hosts
sudo echo "127.0.0.1 $URL_PROJECT" >> /etc/hosts
# Enable the vhost
sudo a2ensite $1
# Reload Apache2
sudo /etc/init.d/apache2 reload
Je lance cette commande et en moins d’une minute, j’ai accès à un projet symfony fonctionnel dans mon navigateur. Voilà ![]()


















5 commentaires
Excellente idée !
Par contre Kris a lancer le repo officiel de symfony 1.* sur github http://github.com/symfony/symfony1
Bonne continuation et merci
Merci pour le repo (que je n’avais pas vu…) et pour le commentaire
Another question :
I’m on MacOS, I adapt the script but when a run the script I get an error :
/Users/clement/symfonyadmin.sh: line 63: /opt/local/apache2/conf/extra/httpd-vhosts.conf: Permission denied
/Users/clement/symfonyadmin.sh: line 84: /etc/hosts: Permission denied
here is the command line who throws the exception:
sudo echo « 127.0.0.1 $URL_PROJECT » >> « /etc/hosts »
and
sudo echo »
ServerName $URL_PROJECT
DocumentRoot \ »`pwd`/web\ »
DirectoryIndex index.php
AllowOverride All
Allow from all
Alias /sf \ »`pwd`/lib/vendor/symfony/data/web/sf\ »
AllowOverride All
Allow from All
» >> « /opt/local/apache2/conf/extra/httpd-vhosts.conf »
Do you know how to remove this errors ? Thanks a lot
Ps : My LAMP stack is made by macport
Yep due to required permissions you have to create an another script « mkVhost » and put the following content :
if [ -z "$1" ] ; then
echo "Usage: $0 vhost_name"
fi
# Create the local URL
URL_PROJECT=`echo "$1.local" | tr '[[:upper:]]' '[[:lower:]]'`
# vhost config
sudo echo "
<virtualhost *:80>
ServerName $URL_PROJECT
DocumentRoot \"`pwd`/web\"
DirectoryIndex index.php
<directory \"`pwd`\">
AllowOverride All
Allow from all
</directory>
Alias /sf \"`pwd`/lib/vendor/symfony/data/web/sf\"
<directory \"`pwd`/lib/vendor/symfony/data/web/sf\">
AllowOverride All
Allow from All
</directory>
</virtualhost>
" > "/etc/apache2/sites-available/$1"
# Add url local in /etc/hosts
sudo echo "127.0.0.1 $URL_PROJECT" >> /etc/hosts
# Enable the vhost
sudo a2ensite $1
# Reload Apache2
sudo /etc/init.d/apache2 reload
Once everything seems ok, change the first script by removing all after :
And just add :
That should solve your error.
Very nice! good additions
2 trackbacks
[...] Ce billet était mentionné sur Twitter par William DURAND, Bazinga. Bazinga a dit: RT @couac: New post : Création automatique d’un projet symfony + MySQL + Git et Apache2 http://bit.ly/aKvecO [...]
[...] more here: Création automatique d'un projet symfony + MySQL + Git et Apache2 … No [...]