Installing Composer+Symfony on PHP7 and Setup Apache to run symfony-demo application

1. Install Composer globally

1.1 Install Composer in curent directory. 

1.1.1 with default options.
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

1.1.2 with specifying --installer-dir
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php --install-dir=/home/dev/PHP/composer
php -r "unlink('composer-setup.php');"

1.1.3 with specifying --filename
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php --filename=composer
php -r "unlink('composer-setup.php');"

1.1.4 with specifying --version
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php --version=1.5.6
php -r "unlink('composer-setup.php');"
for all the available versions: https://getcomposer.org/download/

1.2 Move Symfony to system directory.

cp composer /usr/local/bin

2. Install Symfony locally. 


# yum install php-pdo php-mbstring php-xml
$ composer create-project symfony/symfony-demo

3. Run Symfony

3.1 Run Symfony on dev server

$ cd symfony-demo
$ bin/console server:run 0.0.0.0:8000

3.2 Run Symfony on Apache

3.2.1 add extra vhost
add Listen 8000 in httpd.conf

3.2.2 add vhost config file - simple version
<VirtualHost *:8000>

    DocumentRoot /home/dev/PHP/Symfony/symfony-demo/public
    <Directory /home/dev/PHP/Symfony/symfony-demo/public>
        #AllowOverride None
        #Order Allow,Deny
        #Allow from All
        Require all granted

        <IfModule mod_rewrite.c>
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ index.php [QSA,L]
        </IfModule>
    </Directory>

    # uncomment the following lines if you install assets as symlinks
    # or run into problems when compiling LESS/Sass/CoffeScript assets
    # <Directory /var/www/project>
    #     Options FollowSymlinks
    # </Directory>

    ErrorLog /var/log/httpd/symfony-demo_error.log
    CustomLog /var/log/httpd/symfony-demo_access.log combined

</VirtualHost>

3.3 Run Symfony on NGINX

    server {
        listen       8011 default_server;
        listen       [::]:8011 default_server;
        server_name  _;
        root         /home/dev/PHP/Symfony/symfony-demo/public;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        #location / {
        #}

        # Added for Symphony
        #####################################################################################################
        location ~ ^/index\.php(/|$) {
            fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            include fastcgi_params;

            autoindex on;

            # optionally set the value of the environment variables used in the application
            # fastcgi_param APP_ENV prod;
            # fastcgi_param APP_SECRET <app-secret-id>;
            # fastcgi_param DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name";

            # When you are using symlinks to link the document root to the
            # current version of your application, you should pass the real
            # application path instead of the path to the symlink to PHP
            # FPM.
            # Otherwise, PHP's OPcache may not properly detect changes to
            # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
            # for more information).
            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT $realpath_root;
            # Prevents URIs that include the front controller. This will 404:
            # http://domain.tld/index.php/some-path
            # Remove the internal directive to allow URIs like this
            internal;
        }

        # return 404 for all other php files not matching the front controller
        # this prevents access to other php files you don't want to be accessible.
        #location ~ \.php$ {
        #    return 404;
        #}
        #####################################################################################################

        #error_page 404 /404.html;
        #    location = /40x.html {
        #}

        #error_page 500 502 503 504 /50x.html;
        #    location = /50x.html {
        #}

        error_log /var/log/nginx/symfony-demo_error.log;
        access_log /var/log/nginx/symfony-demo_access.log;
    }




4. Test Symfony

4.1 Test Symfony on dev server

$ cd symfony-demo/
$ ./vendor/bin/simple-phpunit
















Comments