The following section describes how to install Magento 2 in Ubuntu with Nginx.
Step 1: Install Nginx
Execute the following command:
apt-get -y install nginx
Step 2: Install and configure php-fpm
- Get php-fpm and php-cli installed:
Execute the following command:
apt-get -y install php7.0-fpm php7.0-cli
- In a text editor, open the php.ini files as follows:
Execute these commands:
vim /etc/php/7.0/fpm/php.ini
vim /etc/php/7.0/cli/php.ini
- Change the lines in those files to match the following:
memory_limit = 2G
max_execution_time = 1800
zlib.output_compression = On
- Save your work and close the editor you’re using.
- Use the following command to restart the php-fpm service:
systemctl restart php7.0-fpm
Step 3: Install and configure MySQL
- Execute the command below:
sudo apt install -y mysql-server mysql-client
- Enter the following line to secure the installation:
sudo mysql_secure_installation
- Use the following command to check the installation:
mysql -u root -p
- By accessing
/etc/mysql/mysql.cnf
in a text editor and navigating to max allowed packet, you may raise the value for packets that are bigger than Magento’s default.
After that, save the changes to mysql.cnf and restart MySQL using service mysql restart.
To check your set value, type the following command at a mysql> prompt:
SHOW VARIABLES LIKE ‘max_allowed_packet’;
- Make your Magento database configuration
Install and configure Magento 2
We’re ready to begin after you’ve downloaded Magento 2.
- To go to the docroot directory, perform the following:
cd /var/www/html
- Download Magento 2 and save it to your computer as magento2/:
wget https://github.com/magento/magento2/archive/2.3.0.tar.gz
tar -xzvf 2.3.0.tar.gz
mv magento2-2.3.0/ magento2/
- To set directory ownership and file permissions, use the following commands.
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 on a worldwide basis.
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer
- Magento dependencies must be updated:
cd /var/www/html/magento2
composer install -v
- Fill up your Magento authentication credentials.
- To instal Magento, type the following in the command prompt:
cd /var/www/html/magento2/bin
./magento setup:install --base-url=http://www.dev-magento.com/
--db-host=localhost --db-name=magento2 --db-user=magento2
--db-password=magento2 --admin-firstname=admin
--admin-lastname=admin --admin-email=test@test.com
--admin-user=admin --admin-password=admin123 --language=en_US
--currency=USD --timezone=America/Chicago --use-rewrites=1
Remove http://www.dev-magento.com
and add your domain name.
9. 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
- To create a new virtual host for your Magento site, use the following command:
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;
}
- When installing Magento, make sure your domain name matches the base URL you choose.
- Save your work and close the editor.
- Create a symlink to activate the host:
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 go to your site’s URL in a web browser and double-check it.