Last active
August 19, 2017 18:05
-
-
Save okovalov/37fa0ededf8878c616df7faab99afed7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Taken from https://www.howtoforge.com/tutorial/how-to-install-magento-with-nginx-on-ubuntu/ | |
How to Install Magento with Nginx on Ubuntu 16.04 | |
Prerequisites: | |
Ubuntu 16.04 - 64 bit. | |
Root Privileges. | |
Step 1 - Install Nginx | |
Login to your Ubuntu server with your root account (e.g. by SSH) and update the repository. | |
sudo su | |
apt-get update | |
Then install Nginx: | |
apt-get install nginx -y | |
Verify that nginx has been installed properly by checking the port: | |
netstat -plntu | grep 80 | |
Step 2 - Install and Configure PHP-FPM | |
In this step we will to install PHP 7 in PHP-FPM mode. Additionally we will install the following PHP extensions that are required by magento. | |
php-gd | |
php-mhash | |
php-mcrypt | |
php-xsl | |
php-pear | |
php-soap | |
Install the packages with the apt command below: | |
apt-get install php php7.0-mcrypt php7.0-xml php-all-dev php7.0-curl php7.0-gd | |
php7.0-intl php7.0-zip php7.0-mysql php7.0-fpm php7.0-cli | |
php7.0-xsl php7.0-json php7.0-intl php-pear php7.0-dev php7.0-common | |
php7.0-mbstring php-soap libcurl3 curl -y | |
Now edit the php.ini files for fpm and cli. | |
vim /etc/php/7.0/fpm/php.ini | |
vim /etc/php/7.0/cli/php.ini | |
and increase the memory limit and php execution time and turn on zlib compression by adding the following lines at the end of the files: | |
memory_limit = 512M | |
max_execution_time = 1800 | |
zlib.output_compression = On | |
NOTE | |
you might need to switch to php7.0 | |
$ sudo update-alternatives --set php /usr/bin/php7.0 | |
$ sudo update-alternatives --set phar /usr/bin/phar7.0 | |
$ sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.0 | |
NOTE | |
You might need to remove existing php and install required packages | |
apt-get remove php-common | |
apt-get install php7.0-common php7.0-curl php7.0-gd php7.0-imap php7.0-json php7.0-mbstring php7.0-opcache | |
php7.0-pgsql php7.0-readline php7.0-sqlite3 php7.0-xml php7.0-zip php-gd php-mcrypt php7.0-xml php-pear | |
php-soap php-memcached php-igbinary php-msgpack php-pear php-xdebug php7.0-bcmath php7.0-dev php7.0-fpm | |
php7.0-cli php7.0-intl php7.0-mcrypt php7.0-xml php-all-dev php7.0-curl php7.0-gd php7.0-intl php7.0-zip | |
php7.0-mysql php7.0-fpm php7.0-cli php7.0-xsl php7.0-json php7.0-intl php-pear php7.0-dev php7.0-common | |
php7.0-mbstring php-soap libcurl3 curl -y | |
Save the file and exit the editor. | |
Restart the PHP-FPM service to apply the configuration changes: | |
systemctl restart php7.0-fpm | |
Step 3 - Install and Configure MariaDB | |
I will use MariaDB instead of MySQL here. Install MariaDB with the apt command: | |
apt-get install mariadb-server mariadb-client -y | |
Set the MariaDB root user password with this command: | |
mysqladmin -u root password mypassword | |
mysql_secure_installation | |
Set root password? [Y/n] Y | |
New password: | |
Re-enter new password: <-- Enter the new password | |
Remove anonymous users? [Y/n] Y | |
... Success! | |
Disallow root login remotely? [Y/n] Y | |
... Success! | |
Remove test database and access to it? [Y/n] Y | |
Reload privilege tables now? [Y/n] Y | |
... Success! | |
Then connect to the MySQL shell (the MariaDB shell gets started with the command mysql) with your root password, create a database with the name 'magentodb' and a user 'magentouser' with the password 'magentouser@'. Please choose a secure password for the 'magentouser' on your server and not the one 'magentouser@' that I used in this example! | |
Login to the MySQL shell: | |
mysql -u root -p | |
In the MySQL shell, run these commands: | |
create database magentodb; | |
CREATE USER 'magentouser'@'localhost' IDENTIFIED BY 'magentopassword'; | |
grant all privileges on magentodb.* to magentouser@localhost identified by 'magentopassword'; | |
flush privileges; | |
\q | |
Database created and configured. | |
Step 4 - Install and Configure Magento 2 | |
We will install Magento in the directory '/var/www/magento2'. For the Magento installation, we need the PHP composer. | |
- Install php composer | |
Go to the root directory, download the composer installer file with curl and run it to install composer. | |
cd ~/ | |
curl -sS https://getcomposer.org/installer | php | |
Move the file 'composer.phar' file to the bin directory of your server and rename it to composer so it can be executed easily: | |
mv composer.phar /usr/bin/composer | |
Or you could do | |
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" | |
php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" | |
php composer-setup.php | |
php -r "unlink('composer-setup.php');" | |
mv composer.phar /usr/bin/composer | |
Now verify that composer command is working: | |
composer -v | |
- Download and Extract Magento 2 | |
Go to the web directory '/var/www/' and download Magento from it's Github repository, then unpack the downloaded tar.gz file: | |
cd /var/www/ | |
wget https://github.com/magento/magento2/archive/2.0.7.tar.gz | |
tar -xzvf 2.0.7.tar.gz | |
mv magento2-2.0.7/ magento2/ | |
Done. | |
- Configure the Magento Key | |
Register an account on the Magento website repo.magento.com. This account is required to use Magento and the Magento composer store. When you have registered, go to the Tab 'My Account > Developer > Secure Keys', next generate your keys. | |
- Install Third-party Components for Magento | |
Go to the Magento 2 installation directory '/var/www/magento2' and run the composer command: | |
cd /var/www/magento2/ | |
composer install -v | |
You will be asked for the Magento authentication, use the public key as username and the private key for the password. | |
Or you could save those locally into your ~/.composer/auth.json by doing | |
composer global config http-basic.repo.magento.com <public_key> <private_key> | |
- Configure the Nginx Virtualhost | |
Magento offers a ready-made Nginx virtual host configuration, so we just have to include it in our configuration. | |
Go to the Nginx virtual host directory and create new file called magento: | |
cd /etc/nginx/sites-available/ | |
vim magento | |
Paste configuration below: | |
upstream fastcgi_backend { | |
server unix:/run/php/php7.0-fpm.sock; | |
} | |
server { | |
listen 80; | |
server_name www.newmagento.com; | |
set $MAGE_ROOT /var/www/magento2; | |
set $MAGE_MODE developer; | |
include /var/www/magento2/nginx.conf.sample; | |
} | |
Replace www.newmagento.com with the domain name of the website that your shop shall use. | |
Save and exit. | |
Now activate the virtual host and restart Nginx: | |
ln -s /etc/nginx/sites-available/magento /etc/nginx/sites-enabled/ | |
systemctl restart nginx | |
- Install Magento | |
We will install magento on the command line. In the Magento directory '/var/www/magento2/' there is binary file with the name 'magento' that is used to install and manage magento. Run the command: | |
bin/magento setup:install --backend-frontname="adminlogin" \ | |
--key="biY8vdWx4w8KV5Q59380Fejy36l6ssUb" \ | |
--db-host="localhost" \ | |
--db-name="magentodb" \ | |
--db-user="magentouser" \ | |
--db-password="magentopassword" \ | |
--language="en_US" \ | |
--currency="USD" \ | |
--timezone="America/New_York" \ | |
--use-rewrites=1 \ | |
--use-secure=0 \ | |
--base-url="http://www.newmagento.com" \ | |
--base-url-secure="https://www.newmagento.com" \ | |
--admin-user=adminuser \ | |
--admin-password=admin123@ \ | |
--admin-email=admin@newmagento.com \ | |
--admin-firstname=admin \ | |
--admin-lastname=user \ | |
--cleanup-database | |
backend-frontname = the admin page for our magento site, we use 'adminlogin'. | |
Key = our magento keys, we can generate it, or find it random on http://randomkeygen.com/. | |
Base-url = make sure it is same with virtual host configuration. | |
At the end of the installation procedure you should see these lines: | |
[SUCCESS]: Magento installation complete. | |
[SUCCESS]: Magento Admin URI: /adminlogin | |
Before we will test the Magento installation, ensure the web directory owner is 'www-data', then restart nginx. | |
cd /var/www/magento2/ | |
chmod 700 /var/www/magento2/app/etc | |
chown -R www-data:www-data . | |
systemctl restart nginx | |
Now open the Magento domain in your browser: | |
In my case, the domain name is: www.newmagento.com. | |
Try to log in to the Magento admin dashboard: | |
www.newmagento.com/adminlogin | |
Note : | |
If you get an error about a missing Magento indexer cronjob, then you can solve it by adding the following cronjob to your server: | |
crontab -u www-data -e | |
Add the following lines: | |
* * * * * /usr/bin/php /var/www/magento2/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/magento2/var/log/magento.cron.log | |
* * * * * /usr/bin/php /var/www/magento2/update/cron.php >> /var/www/magento2/var/log/update.cron.log | |
* * * * * /usr/bin/php /var/www/magento2/bin/magento setup:cron:run >> /var/www/magento2/var/log/setup.cron.log | |
Save and exit. | |
Magento 2 with Nginx and PHP-FPM 7 on Ubuntu 16.04 is installed now. | |
PS | |
If you want to be able to edit source files under your user, you might (it is unsecure though) to change a user under nginx runs and change the ownership of the magento source again | |
(to be run from magento root directory) | |
sudo chown -R oleks:oleks . | |
Also after running magento commands (like cache clean etc) you might have permissions related problems , so the to fix that you might run | |
sudo find . -type f -exec chmod -R 664 {} \; | |
sudo find ./var/ -type d -exec chmod -R 777 {} \; | |
sudo find ./pub/ -type d -exec chmod -R 777 {} \; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sudo chown -R oleks:www-data .
https://magento.stackexchange.com/questions/142286/cant-disable-magento-2-cache
(Both files should be owned by :)