Introduction:
In our previous blogs, we discussed on creating a Compute Engine VM instance and installing LAMP server on Google Cloud Platform(GCP). In this blog, we will discuss about installing magento2 on google cloud platform(GCP). For installing magento on GCP, you will need a registered GCP account. You can then create a VM on google cloud to setup a LAMP server and finally install magento framework on it.
Create a VM on GCP and Setup LAMP server:
For installing magento2, we will need to setup a LAMP server on GCP. For this blog, we will use the following LAMP configurations:
- OS: Ubuntu 16.04
- Database: MySQL 5.7
- PHP: php v7.0
First of all, we need to create a Compute Engine VM on GCP along with a MySQL database using SQL service of GCP. Then you setup LAMP server on it for installing magento. You can follow my blog for the steps for creating and connecting to Compute engine VM and setting up a LAMP server.
Download Magento2:
Now let us download and install the latest source code from github. At the time of this blog, the latest version is 2.2.6.
To install magento2 with composer, first create the Access keys of magento marketplace. If you have an account on Magento Marketplace, simply signin and generate the access keys. If you don’t have an account, create an account by registering yourself on marketplace.magento.com
For generating Access keys, login in to magento marketplace and from the top right corner of the page where your user name is displayed, navigate to My profile > Marketplace > My products > Access Keys
Now create a new pair of Access keys. You need to provide the public Key as username and Private Key as password when prompt.
First install composer on the server.
1 2 |
sudo wget -O /usr/local/bin/composer http://getcomposer.org/composer.phar sudo chmod +x /usr/local/bin/composer |
The syntax for installing magento2 through composer is as follows.
composer create-project –repository=https://repo.magento.com/ magento/project-community-edition <install-directory-name>
You can use the below command for installing magento2 latest version through composer.
1 |
composer create-project --repository=https://repo.magento.com/ magento/project-community-edition magento2 |
For installing a specific version of magento2, mention the magento version at the end of the command as follows.
1 |
composer create-project --repository=https://repo.magento.com/ magento/project-community-edition magento2 v2.2.6 |
During this process, you will be asked to provide the username and password. Provide the generated Access Keys where the public Key is the username and Private Key is the password. Also, you will be asked whether you want to store the credentials in auth.json. You can select “n” if you don’t wish to save your credentials on the server.
Then copy the magento2 files to the Document root of the webserver.
1 |
sudo mv magento2 /var/www/ |
Give the proper web-server permissions.
1 |
sudo chown -R www-data:www-data /var/www/ |
Configure Apache:
Configure the Apache with the below configuration. If you need to run the magento on a domain , uncomment the ServerName and ServerAlias section and update your domain name. Else you can leave it as it is.
1 |
sudo vim /etc/apache2/sites-enabled/000-default.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<VirtualHost *:80> #ServerName mydomain.com #ServerAlias www.mydomain.com DocumentRoot /var/www/magento2 <Directory /var/www/magento2> Options Indexes FollowSymLinks MultiViews Require all granted AllowOverride all </Directory> ErrorLog /var/log/apache2/error.log CustomLog /var/log/apache2/access.log combined </VirtualHost> |
Restart Apache server.
1 |
sudo service apache2 restart |
Create a MySQL Database and User:
Login to your MySQL server and create a user and database for your Magento application. Change the database name, database user and password as per your need.
1 |
mysql -h <mysql-instance-public-ip> -u root -p |
1 2 3 4 5 |
> CREATE DATABASE magento2; > CREATE USER 'magento_user'@'%' IDENTIFIED BY 'user_pwd'; > GRANT ALL PRIVILEGES ON magento2.* TO 'magento_user'@'%'; > FLUSH PRIVILEGES; > exit |
Installing Magento2:
You can install magento2 by hitting the public IP of the instance or the domain name if configured in DNS on the web browser.
Follow the web GUI interface and provide the required information to install magento2 on the server.
Note: If your installation screen on web browser seems stuck, you can also check the installation logs to check if the installation is complete.
1 |
tailf /var/www/magento2/var/log/install.log |
After the installation of magento2 is complete, you can access the frontend and backend with the associated URLs. You can note the admin URL displayed after the installation is complete.
Congrats, you have successfully installed Magento2 on Google Cloud Platform.
Stay Connected!
You can also check Cloudkul GCP hosting plans for Magento 2 and other e-commerce platforms.
In case of any help or query, please contact us or raise a ticket at support@webkul.com.