Basic apache(httpd) virtualhost with symfony project setup

Apache Server Virtual host

Configure HTTPD virtual host

This is the basic configuration file in which each line is important and necessary. To add it into the virtual host. Edit this file according to your requirement.

Open terminal using (ssh connection)

cd /etc/httpd/conf.d/

vim filename.conf

<VirtualHost *:80>

ServerAdmin [email protected]_domain.com

DocumentRoot "/var/www/html/project_directory/"

ServerName your_domain.com

ServerAlias www.your_domain.com

ErrorLog "/var/log/httpd/your_domain.com-error_log"

CustomLog "/var/log/httpd/your_domain.com-access_log" combined

<Directory "/var/www/html/project_directory/">

DirectoryIndex index.html index.php

Options FollowSymLinks

AllowOverride All

Require all granted

</Directory>

</VirtualHost>

Copy your code in directory as mentioned in virtualhost –  /var/www/html/project_directory/

cd /var/www/html/project_directory/

Now test your Symfony code.

Run Symfony commands one by one



php app/console cache:clear --env=prod

php app/console assets:install --env=prod

php app/console assetic:dump --env=prod --no-debug

Run URL and check logs you will find that PHP does not have permission to read cache folder

To Solve, this problem follow the below process

If you have single website on your server follow these commands

Creating user with primary group apache and project Directory.

 

Note :- Replace username with your custom requirement

#This command will make user with group apache and Directory /home/dewey/www

useradd -g apache d /home/dewey/www username

Set password

passwd username

enter the password

Now provide permissions and ownership to the project directory

cd /home/dewey

chown -R username:apache www/

find www/ -type f -exec chmod 644 {} \;

find www/ -type d -exec chmod 755 {} \;

Edit apache configuration file so that whenever we run Symfony commands, then cache should be created by web server user

vim /etc/httpd/conf/httpd.conf

replace user apache with username

 

Now test your configured code

Goto Project directory

cd /home/dewey/www

Run Symfony commands one by one

php app/console cache:clear --env=prod

php app/console assets:install --env=prod

php app/console assetic:dump --env=prod --no-debug

For multiple Domains use this

cd /home/dewey/

~ setfacl -R -m u:username:permission www/

~ setfacl -R -dm u:username:permission www/

 

For any query comment below.
Thank You

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.