Ref: https://www.rosehosting.com/blog/how-to-install-magento-2-4-with-lemp-stack-on-ubuntu-20-04/
Requirements: PHP7.4, Nginx/Apache2, MySQL, ElasticSearch
CHECK PHP VERSION. IF NOT PHP7.4, INSTALL/CHANGE IT TO 7.4
|
1 2 3 4 5 6 7 |
teddy@teddy:~$ php -v PHP Warning: Module 'curl' already loaded in Unknown on line 0 PHP 7.2.33-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Aug 7 2020 14:44:29) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.33-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies with blackfire v1.34.3~linux-x64-non_zts72, https://blackfire.io, by Blackfire |
FIND OUT IF THERE IS PHP7.4 INSTALLED OR NOT
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
teddy@teddy:~$ sudo update-alternatives --config php There are 5 choices for the alternative php (providing /usr/bin/php). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/bin/php7.3 73 auto mode 1 /usr/bin/php5.6 56 manual mode 2 /usr/bin/php7.0 70 manual mode 3 /usr/bin/php7.1 71 manual mode * 4 /usr/bin/php7.2 72 manual mode 5 /usr/bin/php7.3 73 manual mode Press <enter> to keep the current choice[*], or type selection number: |
IT SEEMS I HAVEN’T INSTALLED PHP7.4 YET (BUT I FOUND IT ON /etc/php/7.4). IT MEANS IT ALREADY INSTALLED BUT IT DIDN’T HAVE THE OTHERS MODULES (PHP-FPM, ETC). SO INSTALL THEM
|
1 |
sudo apt-get install php7.4-common php7.4-mysql php7.4-curl php7.4-cgi php7.4-mbstring php7.4-zip php7.4-fpm php7.4-xml php7.4-xmlrpc php7.4-xdebug php7.4-intl php7.4-gmp php7.4-gd php7.4-bcmath php-soap |
NOTE: I HAVE TO INSTALL THEM VIA TELKOMSEL FLASH BECAUSE INDIHOME CAN’T INSTALL THEM!
CHECK AGAIN THE AVAILABLE PHP AND MAKE SURE PHP7.4 IS INSTALLED THEN SELECT IT
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
teddy@teddy:~$ sudo update-alternatives --config php [sudo] password for teddy: There are 6 choices for the alternative php (providing /usr/bin/php). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/bin/php7.4 74 auto mode 1 /usr/bin/php5.6 56 manual mode 2 /usr/bin/php7.0 70 manual mode 3 /usr/bin/php7.1 71 manual mode * 4 /usr/bin/php7.2 72 manual mode 5 /usr/bin/php7.3 73 manual mode 6 /usr/bin/php7.4 74 manual mode Press <enter> to keep the current choice[*], or type selection number: 6 update-alternatives: using /usr/bin/php7.4 to provide /usr/bin/php (php) in manual mode |
NOW
|
1 2 3 4 5 6 |
teddy@teddy:~$ php -v PHP 7.4.12 (cli) (built: Oct 31 2020 17:04:09) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.12, Copyright (c), by Zend Technologies with Xdebug v2.9.8, Copyright (c) 2002-2020, by Derick Rethans |
THEN CHANGE PHP7.4-FPM SETTING:
|
1 |
sudo gedit /etc/php/7.4/fpm/php.ini |
CHANGE THE CONTENT:
|
1 2 3 4 5 6 7 |
cgi.fix_pathinfo=0 upload_max_filesize = 2000M -> (default 2M) max_file_uploads = 2000 -> (default 20) post_max_size = 2000M -> (default 8M) max_execution_time = 6000 -> (default 30) in second max_input_time = 600 -> (default 60) in second memory_limit = 2560M -> (default 128M) |
THEN RESTART PHP7.4-FPM SERVICE:
|
1 |
sudo systemctl restart php7.4-fpm |
CHECK NGINX SYNTAX: sudo nginx -t
RESTART NGINX: sudo systemctl restart nginx
OPEN IT: http://localhost/phpinfo.php (NEED TO CLEAR THE BROWSER CACHE FIRST)
IF YOU CAN’T OPEN http://localhost/phpinfo.php PROPERLY, PLS MAKE SURE THE NGINX CONFIGURATION FILE IS CORRECT
|
1 |
teddy@teddy:~$ sudo gedit /etc/nginx/sites-available/default |
MAKE SURE THE ‘DEFAULT’ PORT IS 80 NOT 8080 AND THE PHP-FPM POINT TO PHP7.4
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# Default server configuration # server { listen 80 default_server; listen [::]:80 default_server; ... root /var/www/html; # Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html; server_name _; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { include snippets/fastcgi-php.conf; # # # With php7.0-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php7.0-fpm: fastcgi_pass unix:/run/php/php7.4-fpm.sock; #USE PHP7.4-FPM # fastcgi_pass unix:/run/php/php7.3-fpm.sock; # fastcgi_pass unix:/run/php/php7.2-fpm.sock; # fastcgi_pass unix:/run/php/php7.0-fpm.sock; # fastcgi_pass unix:/run/php/php5.6-fpm.sock; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } } |
OKAY. DON’T FORGET TO RESTART NGINX SERVICE
|
1 |
teddy@teddy:~$ sudo systemctl restart nginx |
THE CURRENT PHP VERSION FOR FPM IS 7.4.12
CHECK STATUS ELASTICSEARCH
|
1 |
teddy@teddy:~$ sudo systemctl status elasticsearch |
IF IT’S NOT ACTIVE OR DISABLED, THE START THE SERVICE
|
1 |
teddy@teddy:~$ sudo systemctl start elasticsearch |
THEN CHECK THE ELASTICSEARCH VERSION BY OPENING THE PORT 9200 ON THE BROWSER: http://localhost:9200/
HERE IS THE FINE RESULT
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
{ "name" : "teddy", "cluster_name" : "elasticsearch", "cluster_uuid" : "naHr_JQ-RaK7dDx1CAdiDw", "version" : { "number" : "7.8.0", "build_flavor" : "default", "build_type" : "deb", "build_hash" : "757314695644ea9a1dc2fecd26d1a43856725e65", "build_date" : "2020-06-14T19:35:50.234439Z", "build_snapshot" : false, "lucene_version" : "8.5.1", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } |
INSTALL MAGENTO 2.4 VIA COMMAND LINE — AVOID THIS BECAUSE SOMEHOW I GOT THE ‘DEV’ VERSION NOT STABLE VERSION. SO IT’D BE BETTER TO DOWNLOAD THE ARCHIVE HERE https://magento.com/tech-resources/download
CREATE A NEW DIR ‘magento24’ THEN USE GIT CLONE TO GET THE MAGENTO CODE (NOTE: IT TOOK A WHILE)
|
1 2 3 |
teddy@teddy:~$ cd Documents/works/magento24/ teddy@teddy:~/Documents/works/magento24$ git clone https://github.com/magento/magento2.git /home/teddy/Documents/works/magento24/ |
RUN ‘composer install’
|
1 |
teddy@teddy:~/Documents/works/magento24$ composer install |
BUT I GOT THIS ERROR
|
1 2 3 4 5 |
Problem 1 - The requested PHP extension ext-soap * is missing from your system. Install or enable PHP's soap extension. Problem 2 - Installation request for laminas/laminas-soap 2.8.0 -> satisfiable by laminas/laminas-soap[2.8.0]. - laminas/laminas-soap 2.8.0 requires ext-soap * -> the requested PHP extension soap is missing from your system. |
IT SEEMED I FORGOT TO INSTALL php-soap (THERE IS NO php7.4-soap). INSTALL IT
|
1 |
teddy@teddy:~/Documents/works/magento24$ sudo apt-get install php-soap |
THEN ENABLE IT IN ‘/etc/php/7.4/cli/php.ini’ AND ‘/etc/php/7.4/fpm/php.ini’. FOR EXAMPLE
|
1 |
teddy@teddy:~/Documents/works/magento24$ sudo gedit /etc/php/7.4/cli/php.ini |
THEN UNCOMMENT
|
1 |
extension=soap |
DON’T FORGET TO RESTART NGINX
CHECK IT
|
1 2 3 4 5 6 7 8 9 10 11 |
teddy@teddy:~/Documents/works/magento24$ php -i | grep -i soap PHP Warning: Module 'soap' already loaded in Unknown on line 0 /etc/php/7.4/cli/conf.d/20-soap.ini, soap Soap Client => enabled Soap Server => enabled soap.wsdl_cache => 1 => 1 soap.wsdl_cache_dir => /tmp => /tmp soap.wsdl_cache_enabled => 1 => 1 soap.wsdl_cache_limit => 5 => 5 soap.wsdl_cache_ttl => 86400 => 86400 |
ALSO CHECK IT ON http://localhost/phpinfo.php
IF EVERYTHING ALRIGHT, RERUN ‘composer install’
IF EVERYTHING ALRIGHT, THEN CREATE A NEW DATABASE ‘magento24’ WITH COLLATION ‘utf8mb4_unicode_520_ci’ THEN RUN THIS:
|
1 |
teddy@teddy:~/Documents/works/magento24$ php bin/magento setup:install --base-url=http://magento24.test/ --db-host=localhost --db-name=magento24 --db-user=root --db-password=teddy --admin-firstname=Satria --admin-lastname=Faestha --admin-email=advcha@yahoo.com --admin-user=madmin --admin-password=Teddy@222 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1 |
MAKE SURE EVEYTHING IS FINE
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
Starting Magento installation: File permissions check... [Progress: 1 / 834] Required extensions check... [Progress: 2 / 834] Enabling Maintenance Mode... [Progress: 3 / 834] Installing deployment configuration... [Progress: 4 / 834] Installing database schema: Schema creation/updates: Module 'Magento_AdminAnalytics': [Progress: 5 / 834] Module 'Magento_Store': ... [Progress: 832 / 834] Post installation file permissions check... For security, remove write permissions from these directories: '/home/teddy/Documents/works/magento24/app/etc' [Progress: 833 / 834] Write installation date... [Progress: 834 / 834] [SUCCESS]: Magento installation complete. [SUCCESS]: Magento Admin URI: /admin_h6y3c2 Nothing to import. |
Change the ownership of the magento2 directory to www-data with the following command:
|
1 |
teddy@teddy:~/Documents/works/magento24$ sudo chown -R www-data:www-data /home/teddy/Documents/works/magento24/ |
THEN CREATE NGINX CONFIG FILE
|
1 |
sudo gedit /etc/nginx/sites-available/magento24.test |
The content:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
server { listen 80; server_name magento24.test; set $MAGE_ROOT /home/teddy/Documents/works/magento24; root $MAGE_ROOT; index index.php; autoindex off; charset UTF-8; error_page 404 403 = /errors/404.php; #add_header "X-UA-Compatible" "IE=Edge"; client_max_body_size 100M; # PHP entry point for setup application location ~* ^/setup($|/) { root $MAGE_ROOT; location ~ ^/setup/index.php { fastcgi_split_path_info ^(.+?\.php)(/.*)$; fastcgi_buffers 1024 4k; fastcgi_read_timeout 600s; fastcgi_connect_timeout 600s; fastcgi_pass unix:/run/php/php7.4-fpm.sock; #FOR AWS SERVER #fastcgi_pass 127.0.0.1:9000; #fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ ^/setup/(?!pub/). { deny all; } location ~ ^/setup/pub/ { add_header X-Frame-Options "SAMEORIGIN"; } } # PHP entry point for update application location ~* ^/update($|/) { root $MAGE_ROOT; location ~ ^/update/index.php { fastcgi_split_path_info ^(/update/index.php)(/.+)$; fastcgi_pass unix:/run/php/php7.4-fpm.sock; #FOR AWS SERVER #fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; include fastcgi_params; } # Deny everything but index.php location ~ ^/update/(?!pub/). { deny all; } location ~ ^/update/pub/ { add_header X-Frame-Options "SAMEORIGIN"; } } location / { try_files $uri $uri/ /index.php?$args; } location /pub/ { location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\.xml) { deny all; } alias $MAGE_ROOT/pub/; add_header X-Frame-Options "SAMEORIGIN"; } location ~ ^/pub/static/version { rewrite ^/pub/static/(version\d*/)?(.*)$ /pub/static/$2 last; } location /static/ { # Uncomment the following line in production mode # expires max; # Remove signature of the static files that is used to overcome the browser cache location ~ ^/static/version { rewrite ^/static/(version\d*/)?(.*)$ /static/$2 last; } location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ { add_header Cache-Control "public"; add_header X-Frame-Options "SAMEORIGIN"; expires +1y; if (!-f $request_filename) { rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last; } } location ~* \.(zip|gz|gzip|bz2|csv|xml)$ { add_header Cache-Control "no-store"; add_header X-Frame-Options "SAMEORIGIN"; expires off; if (!-f $request_filename) { rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last; } } if (!-f $request_filename) { rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last; } add_header X-Frame-Options "SAMEORIGIN"; } location /media/ { try_files $uri $uri/ /get.php?$args; location ~ ^/media/theme_customization/.*\.xml { deny all; } location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ { add_header Cache-Control "public"; add_header X-Frame-Options "SAMEORIGIN"; expires +1y; try_files $uri $uri/ /get.php?$args; } location ~* \.(zip|gz|gzip|bz2|csv|xml)$ { add_header Cache-Control "no-store"; add_header X-Frame-Options "SAMEORIGIN"; expires off; try_files $uri $uri/ /get.php?$args; } add_header X-Frame-Options "SAMEORIGIN"; } location /media/customer/ { deny all; } location /media/downloadable/ { deny all; } location /media/import/ { deny all; } # PHP entry point for main application location ~ (index|get|static|report|404|503)\.php$ { try_files $uri =404; fastcgi_pass unix:/run/php/php7.4-fpm.sock; #FOR AWS SERVER #fastcgi_pass 127.0.0.1:9000; fastcgi_buffers 1024 4k; fastcgi_read_timeout 600s; fastcgi_connect_timeout 600s; # to configure profiler in Magento 2 fastcgi_param MAGE_PROFILER html; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #include fastcgi_params; #FOR DEVELOPMENT MODE ONLY - BEGIN fastcgi_param MAGE_IS_DEVELOPER_MODE true; fastcgi_param PHP_VALUE display_startup_errors=on; fastcgi_param PHP_VALUE display_errors=on; fastcgi_param PHP_VALUE html_errors=on; fastcgi_param PHP_VALUE log_errors=on; fastcgi_param PHP_VALUE error_log=/home/teddy/Documents/works/magento24/var/log/system.log; #FOR DEVELOPMENT MODE ONLY - END include fastcgi_params; #FOR DEBUGGING WITH XDEBUG - BEGIN #fastcgi_read_timeout 600; #FOR DEBUGGING WITH XDEBUG - END } gzip on; gzip_disable "msie6"; gzip_comp_level 6; gzip_min_length 1100; gzip_buffers 16 8k; gzip_proxied any; gzip_types text/plain text/css text/js text/xml text/javascript application/javascript application/x-javascript application/json application/xml application/xml+rss image/svg+xml; gzip_vary on; # Banned locations (only reached if the earlier PHP entry point regexes don't match) location ~* (\.php$|\.htaccess$|\.git) { deny all; } } |
Then
|
1 |
sudo ln -s /etc/nginx/sites-available/magento24.test /etc/nginx/sites-enabled/magento24.test |
Then
|
1 |
sudo gedit /etc/hosts |
Then insert
|
1 |
127.0.0.1 magento24.test |
CHECK THE NGINX AND RESTART
|
1 2 3 |
sudo nginx -t sudo service nginx restart |
IF NEEDED SET THE FILE PERMISSION and ownership
|
1 2 3 4 5 6 |
teddy@teddy:~/Documents/works/magento24$ sudo su root@teddy:/home/teddy/Documents/works/magento24# find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \; root@teddy:/home/teddy/Documents/works/magento24# find var vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} \; root@teddy:/home/teddy/Documents/works/magento24# chown -R www-data:www-data . root@teddy:/home/teddy/Documents/works/magento24# chmod u+x bin/magento root@teddy:/home/teddy/Documents/works/magento24# chmod -R 777 var/ pub/ app/etc/ setup/ generated/ |
COMPILE
|
1 2 |
teddy@teddy:~/Documents/works/magento24$ sudo su -s /bin/bash www-data www-data@teddy:/home/teddy/Documents/works/beautybeat$ php bin/magento setup:upgrade --keep-generated && php bin/magento setup:di:compile && php bin/magento setup:static-content:deploy -f && php bin/magento indexer:reindex && php bin/magento cache:clean && php bin/magento cache:flush |
BUT WHEN I OPENED IT ON THE BROWSER http://magento24.test/
I GOT 404 ERROR.
FROM THE /var/log/nginx/error, I FOUND
|
1 |
2020/11/24 16:47:23 [error] 10247#10247: *15 directory index of "/home/teddy/Documents/works/magento24/" is forbidden, client: 127.0.0.1, server: magento24.test, request: "GET / HTTP/1.1", host: "magento24.test" |
I TRIED TO COPY index.php FILE INTO THE magento24 DIR. IT’S WORKING BUT IT FAILED TO LOAD THE STATIC FILES (CSS, JS, ETC) SO I THINK I’LL INSTALL IT VIA FILE DOWNLOADED ON https://magento.com/tech-resources/download
IT SEEMS THE COMMAND LINE INSTALLED THE DEV VERSION
|
1 2 3 4 |
teddy@teddy:~/Documents/works/magento24$ sudo su -s /bin/bash www-data www-data@teddy:/home/teddy/Documents/works/magento24$ php bin/magento --version PHP Warning: Module 'soap' already loaded in Unknown on line 0 Magento CLI dev-2.4-develop |
—
INSTALL FROM THE DOWNLOADED FILE (ALSO READ http://myprojects.advchaweb.com/index.php/2019/02/26/install-magento-2-3-on-ubuntu-16-04-and-nginx/)
BUT STUCK ON http://magento24.test/setup/#/landing
CAN’T FIND ANY BUTTON TO CONTINUE!!!

