Bu yazıda örnek bir symfony projesi oluşturup, ona yaratacağımız sanal host ile ulaşacağız. Yaratacağımız projenin ismi "sport" olacak


Veritabanını yaratma


mysql> CREATE DATABASE IF NOT EXISTS symfony CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Query OK, 1 row affected (0.00 sec)

mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| symfony |
+--------------------+
4 rows in set (0.01 sec)

Symfony projesini kurma


Mac OS içindeki web alanının varsayılan yeri /Library/WebServer/Documents/ olarak tanımlıdır. Composer paketini global olarak yüklediğinizi varsayalım.


Inanzzz-MBP:~ inanzzz$ cd /Library/WebServer/Documents/
Inanzzz-MBP:Documents inanzzz$ composer create-project symfony/framework-standard-edition sport

İzinleri atama


Inanzzz-MBP:~ inanzzz$ cd sport
Inanzzz-MBP:sport inanzzz$ rm -rf app/cache/*
Inanzzz-MBP:sport inanzzz$ rm -rf app/logs/*
Inanzzz-MBP:sport inanzzz$ HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
Inanzzz-MBP:sport inanzzz$ sudo chmod +a "$HTTPDUSER allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
Inanzzz-MBP:sport inanzzz$ sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs

Bundle yaratma


Inanzzz-MBP:sport inanzzz$ php app/console generate:bundle --namespace=Your/NewBundle

Sanal host yaratma


Inanzzz-MBP:sport inanzzz$ sudo nano /private/etc/apache2/extra/httpd-vhosts.conf

# Bu satırları girin
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents/sport/web"
ServerName sport.local

<Directory "/Library/WebServer/Documents/sport/web">
Options Indexes FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

ErrorLog "/private/var/log/apache2/sport.local-error_log"
CustomLog "/private/var/log/apache2/sport.local-access_log" common
</VirtualHost>

Sanal hostu apache konfig içinde aktifleştirme


Inanzzz-MBP:sport inanzzz$ sudo nano /etc/apache2/httpd.conf

# Aktifleştir
LoadModule dir_module libexec/apache2/mod_dir.so
LoadModule alias_module libexec/apache2/mod_alias.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php5_module libexec/apache2/libphp5.so

# <Directory "/Library/WebServer/Documents"> blok ayarları aşağıdaki gibi olacak:
Options FollowSymLinks Multiviews Indexes
AllowOverride All

# Aktifleştir
Include /private/etc/apache2/extra/httpd-autoindex.conf
Include /private/etc/apache2/extra/httpd-languages.conf
Include /private/etc/apache2/extra/httpd-vhosts.conf

Hostu ekleme


Inanzzz-MBP:sport inanzzz$ sudo nano /etc/hosts

# Bu satırı ekleyin
127.0.0.1 sport.local

Apache'yi yeniden başlatma


Inanzzz-MBP:sport inanzzz$ sudo apachectl restart

Test


Eğer tarayıcınızda http://sport.local/app_dev.php/hello/inanzzz adresini ziyaret ederseniz, "Hello inanzzz!" mesajını göreceksiniz.