Tuesday, February 18, 2020

How To Deploy Symfony with Nginx on Ubuntu 18.04

Video Tutorial -  https://youtu.be/9Q6r0CG4p58

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

𝐒𝐲𝐦𝐩𝐡𝐨𝐧𝐲 𝐂𝐌𝐒 𝐢𝐬 𝐚 𝐗𝐒𝐋𝐓-𝐩𝐨𝐰𝐞𝐫𝐞𝐝 𝐨𝐩𝐞𝐧 𝐬𝐨𝐮𝐫𝐜𝐞 𝐜𝐨𝐧𝐭𝐞𝐧𝐭 𝐦𝐚𝐧𝐚𝐠𝐞𝐦𝐞𝐧𝐭 𝐬𝐲𝐬𝐭𝐞𝐦 𝐰𝐡𝐢𝐜𝐡 𝐞𝐧𝐚𝐛𝐥𝐞𝐬 𝐮𝐬𝐞𝐫𝐬 𝐭𝐨 𝐜𝐫𝐞𝐚𝐭𝐞 𝐚𝐧𝐝 𝐦𝐚𝐧𝐚𝐠𝐞 𝐰𝐞𝐛𝐬𝐢𝐭𝐞𝐬 𝐚𝐧𝐝 𝐰𝐞𝐛 𝐚𝐩𝐩𝐥𝐢𝐜𝐚𝐭𝐢𝐨𝐧𝐬.
𝐎𝐟𝐟𝐜𝐢𝐚𝐥 𝐖𝐞𝐛𝐬𝐢𝐭𝐞:𝐡𝐭𝐭𝐩𝐬://𝐬𝐲𝐦𝐟𝐨𝐧𝐲.𝐜𝐨𝐦/
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
𝐎𝐮𝐫 𝐒𝐞𝐫𝐯𝐞𝐫 𝐒𝐩𝐞𝐜𝐢𝐟𝐢𝐜𝐚𝐭𝐢𝐨𝐧- 𝐎𝐬:𝐔𝐛𝐮𝐧𝐭𝐮 𝟏𝟖.𝟎𝟒 𝐋𝐓𝐒 𝐁𝐢𝐨𝐧𝐢𝐜 𝐁𝐞𝐚𝐯𝐞𝐫 𝟔𝟒𝐁𝐢𝐭 | 𝐇𝐨𝐬𝐭𝐧𝐚𝐦𝐞 :𝐰𝐰𝐰.𝐲𝐨𝐮𝐫𝐝𝐨𝐦𝐚𝐢𝐧.𝐜𝐨𝐦   |𝐈𝐏 𝐚𝐝𝐝𝐫𝐞𝐬𝐬- 𝟏𝟗𝟐.𝟏𝟔𝟖.𝟏.𝟓𝟎   
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
lsb_release -cd ; hostname ; hostname -I ; whoami ; getconf LONG_BIT ; apt install -y build-essential software-properties-common net-tools git make wget curl lsb-release

add-apt-repository ppa:ondrej/php -y
apt-get update ; apt install -y nginx php7.2 php7.2-cli php7.2-fpm php7.2-cgi php7.2-bcmath php7.2-curl php7.2-gd php7.2-intl php7.2-json php7.2-mbstring php7.2-mysql php7.2-opcache php7.2-sqlite3 php7.2-xml php7.2-zip php7.2-snmp php7.2-imap php7.2-common php7.2-tidy php7.2-pgsql php7.2-ldap php7.2-soap php7.2-xsl php7.2-recode php7.2-redis php7.2-xmlrpc php7.2-zip php-imagick php-pear php-memcache php-apcu
systemctl start nginx ; systemctl enable nginx

sed -i "s/;date.timezone.*/date.timezone = Asia\/\Kolkata/" /etc/php/7.2/fpm/php.ini ; sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php/7.2/fpm/php.ini ; leafpad  /etc/php/7.2/fpm/pool.d/www.conf &>/dev/null 
[ env[HOSTNAME] = $HOSTNAME ]


curl -sS https://getcomposer.org/installer | php ; mv composer.phar /usr/local/bin/composer ; chmod +x /usr/local/bin/composer
cd /var/www/html ; composer create-project symfony/skeleton symfony5
chown -R www-data:www-data /var/www/html/ ; chmod -R 755 /var/www/html/

Setting up Nginx Server Blocks (Virtual Hosts):-
leafpad /etc/nginx/sites-available/default &>/dev/null
server {
         listen 80;
         listen [::]:80 ipv6only=on;

         # Log files for Debugging
         access_log /var/log/nginx/yourdomain-access.log;
         error_log /var/log/nginx/yourdomain-error.log;

         # Webroot Directory
         root /var/www/html/symfony5/public/;
         index index.php index.html index.htm;

         # Your Domain Name
         server_name www.yourdomain.com;

         location / {
                 try_files $uri $uri/ /index.php?$query_string;
         }

         # PHP-FPM Configuration Nginx
         location ~ \.php$ {
                 try_files $uri =404;
                 fastcgi_split_path_info ^(.+\.php)(/.+)$;
                 fastcgi_pass unix:/run/php/php7.2-fpm.sock;
                 fastcgi_index index.php;
                 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                 include fastcgi_params;
         }
 }

nginx -t  ; echo "192.168.1.50 www.yourdomain.com" >> /etc/hosts ; systemctl restart nginx
http://www.yourdomain.com

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment