Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
No Result
View All Result
Home Google Cloud

How to Install LEMP stack on CentOS 7 – Google Cloud

by Cloudbooklet
5 years ago
in Google Cloud, Compute Engine
How To Install Lemp Stack On Centos 7 - Google Cloud
ShareTweetSendShare
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

How to install LEMP Stack on CentOS 7 with Google Compute Engine with Nginx, PHP7.3 and connect with Cloud SQL. Not using CentOS 7? Choose a different OS: Ubuntu 18.04 LTS ADVERTISEMENT CentOS 7 You might also like How to Install Git on Linux 3 months ago DataStax Enhances Astra DB on Google Cloud with […]

ADVERTISEMENT

How to install LEMP Stack on CentOS 7 with Google Compute Engine with Nginx, PHP7.3 and connect with Cloud SQL.

Not using CentOS 7? Choose a different OS:

Ubuntu 18.04 LTS

ADVERTISEMENT

CentOS 7

Debian 9

The installation is mostly done via command line so I assume you are comfortable using command line interface.

ADVERTISEMENT

Prerequisites

  • Your Compute Engine Instance running.
  • For setting up Compute Engine, see the Setting up Compute Engine Instance with CentOS 7.
  • Setup and secure your new CentOS 7 server.
  • Point your domain to Google Cloud, see the Setting up Google Cloud DNS for your domain

1. Install Nginx

Go to Compute Engine >> VM Instances page, here you will have your instances listed. Click the SSH button to launch the terminal in a new browser window.

Nginx packages are available in the EPEL repositories. So you need to install EPEL repository before installing Nginx. If you have followed the steps to setup secure server with CentOS, you should have your EPEL repository installed. If you haven’t installed this follow this step to install.

ADVERTISEMENT

You might also like

How To Setup Ssh Keys On Ubuntu

How to Setup SSH Keys on Ubuntu 20.04

4 months ago
Draggan Ai Editing Tool Install And Use Draggan Photo Editor

DragGAN AI Editing Tool Install and Use DragGAN Photo Editor

4 months ago
sudo yum install epel-release

Once you have the EPEL installed you can proceed to install Nginx

sudo yum install nginx

Once complete, you can confirm that Nginx has been installed by issuing this command

ADVERTISEMENT
nginx -v

Once the installation is complete you need to start the Nginx service.

sudo systemctl enable nginx
sudo systemctl start nginx

Now you can check the status of Nginx.

ADVERTISEMENT
sudo systemctl status nginx

You should see the output similar to this which means Nginx has started successfully.

Output
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2019-02-19 04:42:46 UTC; 5s ago
Process: 4499 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 4497 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 4496 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 4501 (nginx)
CGroup: /system.slice/nginx.service
├─4501 nginx: master process /usr/sbin/nginx
└─4502 nginx: worker process
Feb 19 04:42:46 lemp systemd[1]: Starting The nginx HTTP and reverse proxy server…
Feb 19 04:42:46 lemp nginx[4497]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Feb 19 04:42:46 lemp nginx[4497]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Feb 19 04:42:46 lemp systemd[1]: Failed to read PID from file /run/nginx.pid: Invalid argument
Feb 19 04:42:46 lemp systemd[1]: Started The nginx HTTP and reverse proxy server.

Visit your domain in your browser, you will see the Nginx welcome page.

2. Configure Firewall

If you have followed the server setup for CentOS 7 you must have installed UFW and enabled it. Now you need to allow connections to the VM Instance from the public. So, now you can add the ports,HTTP (80) HTTPS (443)for the public access.

If you haven’t enabled this go ahead and run the following command.

sudo ufw allow http
sudo ufw allow https

3. Configure Nginx

Next, open the Nginx configuration file, which can be found at /etc/nginx/nginx.conf

sudo nano /etc/nginx/nginx.conf

Start by setting the user to the username that you’re currently logged in with. This will make managing file permissions much easier in the future.

The worker_processes directive is the amount of CPU cores your instance. In my case, this is 1.

Uncomment the multi_accept directive and set it to on.

Lower the keepalive_timeout directive to 15.

For security reasons, you should uncomment the server_tokens directive and ensure it is set to off.

Add the new client_max_body_size directive below the server_tokens and set the value to 64m.

Uncomment the gzip_proxied directive and set it to any, uncomment the gzip_comp_level directive and set it to the value of 2 and finally uncomment the gzip_types directive.

In order for Nginx to correctly serve PHP you also need to ensure the fastcgi_param SCRIPT_FILENAME directive is set, otherwise, you will receive a blank white screen when accessing any PHP scripts. So open fastcgi_params file by issuing

sudo nano /etc/nginx/fastcgi_params

Add the following at the end of the file

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

That’s all, this is the basic Nginx configuration, hit CTRL+X followed by Y to save the changes. Ensure that the configuration file contains no errors and restart Nginx for the changes to take effect by issuing the following command

sudo nginx -t

If you get a successful message, then proceed with the following command

sudo service nginx restart

4. Install PHP 7.3

To install PHP 7.3 add the REMI repository with the following command.

sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

Now you can install PHP 7.3 and some required packages.

sudo yum --enablerepo=remi-php73 install php-common php-mysql php-xml php-xmlrpc php-curl php-gd php-imagick php-cli php-dev php-imap php-mbstring php-opcache php-soap php-zip unzip

After the installation has completed, confirm that PHP 7.3 has installed correctly with this command.

php -v

You will receive an output similar to this.

Output
PHP 7.3.2 (cli) (built: Feb 5 2019 13:10:03) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.2, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.2, Copyright (c) 1999-2018, by Zend Technologies

5. Configure PHP 7.3

Now that PHP 7.3.* has installed and you need to configure the user and group that the service will run under.

sudo nano /etc/php-fpm.d/www.conf

Change the following lines by replacing the apache or nobody with your username.

user = username 
group = username
listen.owner = username
listen.group = username

Now we configure PHP for WordPress by changing some values in php.ini.

sudo nano /etc/php.ini

Hit F6 for search inside the editor and update the following values

upload_max_filesize = 32M 
post_max_size = 48M
memory_limit = 256M
max_execution_time = 600
max_input_vars = 3000
max_input_time = 1000

Hit CTRL+X and Y to save the configuration and check if the configuration is correct and start PHP and enable it.

sudo systemctl start php-fpm
sudo systemctl enable php-fpm

Now we have completed NGINX and PHP 7.3 on CentOS 7.

6. Set up Cloud SQL

Once everything is in place you can create a Cloud SQL Instance and connect with your VM Instance.

Learn How to connect your Google Compute Engine with Cloud SQL database.

Tags: CentOSCompute Engine
ShareTweetSendShare
Cloudbooklet

Cloudbooklet

Comments 2

  1. Avatar Of Ayush Ayush says:
    4 years ago

    For cent os ufw is not command ..
    to enable http and https-
    $ sudo firewall-cmd –permanent –zone=public –add-service=http
    $ sudo firewall-cmd –permanent –zone=public –add-service=https
    $ sudo firewall-cmd –reload
    are the commands.

    Reply
    • Avatar Of Cloudbooklet Cloudbooklet says:
      4 years ago

      You can install ufw on CentOS using this command.
      yum install -y ufw

      By the way thanks for your interest in Cloudbooklet

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

Set Up Deep Learning With Nvidia, Cuda, Cudnn On Ubuntu

How to Set Up Deep Learning with Nvidia, CUDA, cuDNN on Ubuntu 22.04

7 months ago
How To Install Or Upgrade Php 8.2 On Ubuntu 22.04

How to Install or Upgrade PHP 8.2 on Ubuntu 22.04

9 months ago
How To Change Timezone On Ubuntu 22.04

How to Change Timezone on Ubuntu 22.04

1 year ago
How To Install Ansible On Ubuntu 22.04

How to Install Ansible on Ubuntu 22.04

1 year ago

Follow Us

Trending Articles

Tiktok

5 Best TikTok Private Account Viewer in 2023

September 18, 2023

Top 10 Advantages of a Cloud VPS Server

7 Best AI Girl Generators for Creating Realistic and Beautiful AI Girls

HeyGen AI: Free AI Video Generator to Create Amazing Videos

How to Delete Netflix Account Permanently

Amazon Prime Big Deal Days 2023: Best Deals

Popular Articles

Change Image Background Online Free

10 Best Tools Change Image Background Online Free

September 7, 2023

Microsoft Unveils New Disc-Less Xbox Series X with Lift-to-Wake Controller

7 Best AI Content Detectors to Check Plagiarism

Microsoft Surface Event: The Most Exciting and Innovative Launches and Updates

Google Watermark Feature: A Solution for AI Image Verification

6 Best AI Voice Cloning Tools that You Need to Try in 2023

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Cloudbooklet Logo

Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.

  • About
  • Contact
  • Disclaimer
  • Privacy Policy

Cloudbooklet © 2023 All rights reserved.

No Result
View All Result
  • News
  • Artificial Intelligence
  • Applications
  • Linux

Cloudbooklet © 2023 All rights reserved.