Hi everyone, welcome back to another SimiCart’s Magento 2 tutorials.
Today, we will guide you on how to install Magento 2 on Ubuntu 16 using Nginx. You can actually do that on CentOS 7 as well but we will take Ubuntu 16 as an example.
Note: Want to know about Magento 2 System Requirements? Here is the full checklist. Don’t skip it!
Step 1: Install nginx
Run the command:
apt-get -y install nginx
Step 2: Install and configure php-fpm
- Install php-fpm and php-cli:
Run the command:
apt-get -y install php7.0-fpm php7.0-cli
- Open the php.ini files in an editor:
Run the following commands:
vim /etc/php/7.0/fpm/php.ini vim /etc/php/7.0/cli/php.ini
- Make modification in those files to match the following lines:
memory_limit = 2G max_execution_time = 1800 zlib.output_compression = On
- Save and exit the editor you using
- Restart the php-fpm service by using the below command:
systemctl restart php7.0-fpm
Step 3: Install and configure MySQL
- Run the following command:
sudo apt install -y mysql-server mysql-client
- Secure the installation by entering the line:
sudo mysql_secure_installation
- Test the installation with the command:
mysql -u root -p
- You can increase the value for packet which is larger than Magento default by opening /etc/mysql/mysql.cnf in a text editor and navigate to max_allowed_packet.
Then, save to mysql.cnf and restart MySQL by entering service mysql restart.
Run the following command at a mysql> prompt to verify your set value:
SHOW VARIABLES LIKE 'max_allowed_packet';
- Make your Magento database configuration
Install and configure Magento 2
Download your Magento 2 and then we are good to go.
- Run the following to change to docroot directory:
cd /var/www/html
- Extract the Magento 2 you downloaded and name it magento2/:
wget https://github.com/magento/magento2/archive/2.0.tar.gz tar -xzvf 2.0.tar.gz mv magento2-2.0/ magento2/
- Enter the following lines to set directory ownership and file permissions.
cd /var/www/html/magento2 find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \; find var vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} \; chown -R :www-data . chmod u+x bin/magento
- Install Composer globally.
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer
- Update Magento dependencies:
cd /var/www/html/magento2 composer install -v
- Enter your Magento authentication keys.
- Run the below in command line to install Magento:
cd /var/www/html/magento2/bin ./magento setup:install --base-url=http://www.magento-dev.com/ --db-host=localhost --db-name=magento --db-user=magento --db-password=magento --admin-firstname=admin --admin-lastname=admin [email protected] --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America/Chicago --use-rewrites=1
Remove http://www.magento-dev.com and add your domain name.
- Last but not least, change to developer mode to continue with nginx configuration:
cd /var/www/html/magento2/bin ./magento deploy:mode:set developer
Step 4: Configure nginx
- Run the line to create a new virtual host for your Magento site:
vim /etc/nginx/sites-available/magento
- Make the following configuration:
upstream fastcgi_backend { server unix:/run/php/php7.0-fpm.sock; } server { listen 80; server_name www.magento-dev.com; set $MAGE_ROOT /var/www/html/magento2; include /var/www/html/magento2/nginx.conf.sample; }
- Match your domain name with the base URL you chose when installing Magento.
- Save and exit the editor.
- Activate host by creating a symlink:
ln -s /etc/nginx/sites-available/magento /etc/nginx/sites-enabled
- Verify if the syntax is correct:
nginx -t
- Run the command to restart nginx:
systemctl restart nginx
Step 5: Verify the installation
Now try your site’s URL on a web browser to verify the site yourself.
Related posts:
How to install Magento 2 on localhost
How to Install Magento 2 Using Composer
How to Install Magento 2 on WAMP Server Localhost
Magento 2 Permissions: What You Need To Know?
thanks very much for the perfect advice
how can I access admin panel after installation? Thanks
Hi Ellis,
You can just add “/admin/” to the end of your domain URL. That’s the default path for Magento backend.
Nice manual! Thank you so much!
Do you have a manual to install ElasticSearch for Magento 2.3? I’m not able to make it work, my system is an Ubuntu 18.04 with nginx and mysql
You can check this manual from Magento: https://devdocs.magento.com/guides/v2.3/config-guide/elasticsearch/es-config-nginx.html
This file permissions is for production mode o developer mode? Thanks