Linux Ubuntu

Installing Nginx, MySQL and PHP (LEMP) on Ubuntu 17.04 | 17.10

Installing Nginx, MySQL and PHP (LEMP) on Ubuntu 17.04 | 17.10 &-8211; this Article or News was published on this date:2020-09-27 21:17:34 kindly share it with friends if you find it helpful

This brief tutorial shows students and new users how to install Nginx, MySQL and PHP (LEMP) on Ubuntu 17.04 | 17.10 servers or VPS. LEMP is an acronym for Linux, Nginx (aka engine-x), MySQL and PHP.

LEMP, a stack of opensource applications that powered many of the PHP-based websites and web applications online today. LEMP and LAMP are similar except LAMP uses Apache2 webserver and LEMP uses Nginx.

LEMP is rapidly gaining popularity because it provides speed and scalability.

Continue with the steps below to get LEMP installed.

Step 1: Install / Update Ubuntu Server

LEMP won’t exist without a Linux system. For this post, we’re going to be using Ubuntu as our Linux machine.

This post assumes that you already have Ubuntu server installed and that you have administrative rights to install packages and make changes to the server.

After installing Ubuntu, run the commands below to update the server

sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove

You may have to reboot the systems after running the commands above..

Step 2: Install Nginx Webserver

Now that Ubuntu is updated, run the commands below to install Nginx webserver

sudo apt-get install nginx

After installing Nginx, the commands below can be used to stop, start, and enable Nginx webserver to always start up when the server boots.

sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

After installing Nginx, test it out by browsing to the server IP address or hostname. When you see the page below, then Nginx is installed and functioning.

nginx default home page test

Step 3: Install MySQL Server

After installing Nginx above, the commands below show you how to install MySQL Server.

sudo apt-get install mysql-server mysql-client

Shortly after continuing with the installation, you’ll be prompted to create and confirm MySQL root user password. Please create a strong password for security.

nginx default home page test

After installing MySQL database server, the commands below show you how to stop, start and enable MySQL to always start up with the system boots.

sudo systemctl stop mysql.service
sudo systemctl start mysql.service
sudo systemctl enable mysql.service

Now that MySQL is installed, run the commands below to secure it.

sudo mysql_secure_installation

Use the guide below to answer the questions when asked.

Enter password for user root: TYPE CURRENT ROOT PASSWORD

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Using existing password for root.

Estimated strength of the password: 50 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

After that, MySQL should be ready to use. To test whether MySQL is functioning, run the commands below to logon.

sudo mysql -u root -p

Enter the password you created earlier in the post and you should see MySQL welcome message.

Step 4: Install PHP-FPM and Related Modules

Lastly, run the commands below to install PHP and related PHP modules.

sudo apt-get install php-fpm php-mysql

The commands above will install PHP, but may also install Apache2 webserver. Run the commands below to disable Apache2 from starting.

sudo systemctl disable apache2.service

Remove Apache2 default index.html page.

sudo rm /var/www/html/index.html

To run PHP-based websites on Nginx you’ll want to edit its default site configuration file. Run the commands below to create a backup of the default file.

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak

Then edit the default file and make the highlighted changes below

sudo nano /etc/nginx/sites-available/default

Then make the highlighted change.

server {
        listen  80 default_server;
        listen [::]:80 default_server;
        server_name  _;
        root /var/www/html;
        index index.php index.html;

        location / {
                try_files $uri $uri/ =404;
        }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;

        location = /50x.html {
                root /var/www/html;
        }

        location ~ .php$ {
                include snippets/fastcgi-php.conf;
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

Restart Nginx

sudo systemctl restart nginx.service

Now, create a test PHP file to test.

sudo nano /var/www/html/phpinfo.php

Add the content below in the file and save.

?php
phpinfo();
?>

Now browse to the server IP or hostname followed by /phpinfo.php

You should see PHP file as below. This shows that PHP is functioning with Nginx.

nginx default home page test

Congratulations, you’ve installed LEMP.

Summary:

This post shows how to install Nginx, MySQL and PHP (LEMP) on Ubuntu 17.04 | 17.10.  LEMP is an alternative to LAMP and it’s rapidly gaining popularity because its speed and scalability.

When the above steps are followed, you should be able to quickly run dynamic PHP-based websites and applications.

Enjoy!

You may also like the post below:

Installing Nginx, MariaDB and PHP (LEMP) on Ubuntu 17.04 | 17.10

Installing Nginx, MariaDB and PHP (LEMP) on Ubuntu 17.04 | 17.10 &-8211; this Article or News was published on this date:2020-09-27 21:17:32 kindly share it with friends if you find it helpful

LEMP is an acronym for Linux, Nginx (Engine-x) MariaDB and PHP. It’s based on a collection of opensource software that powers many popular websites and web applications.

One can use LEMP to run WordPress, Joomla, Drupal and other PHP-based content management systems on Linux machines.

This brief tutorial is going to show students and new users how to easily install the LEMP stack on Ubuntu 17.04 | 17.10 if you haven’t already done so.

To get started with install LEMP, follow the steps below:

Step 1: Ubuntu

The LEMP or LAMP stack always begins with the Linux systems. There are many Linux distributions in used today, however, the most popular is Ubuntu. For this post, we’re going to be using Ubuntu Linux as our LEMP based system.

This post also assumes that you have already installed Ubuntu and that you have administrative rights to install packages and make changes.

After installing Ubuntu, run the commands below to update the Ubuntu machine.

sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove

You may want to restart the machine after running the commands above..

Step 2: Install Nginx

Now that the Ubuntu machine is updated, run the commands below to install Nginx web server. Nginx is an alternative to Apache2 and uses system resources very efficiently.

sudo apt-get install nginx

After installing Nginx, the commands below can be used to stop, start and enable Nginx webserver to always start up when the system boots.

sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

To test whether Nginx is working, open your browse and browse to the server IP or hostname and you should see Nginx’s default welcome page.

Nginx web server default test page

Step 3: Install MariaDB

MariaDB is a fork and a drop-in replacement for MySQL. MariaDB is an alternative to MySQL and is rapidly gaining popularity. To install MariaDB, run the commands below.

sudo apt-get install mariadb-server mariadb-client

After installing MariaDB, the commands below can be used to stop, start and enable MariaDB to always start up when the system boots.

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Another thing to do after installing MariaDB is to secure it. To do that, run the commands below.

sudo mysql_secure_installation

You’ll be prompted with series of questions, follow the guide below to answer

Enter current password for root (enter for none): PRESS ENTER

Set root password? [Y/n] Y
CREATE YOUR PASSWORD

Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

To test whether MariaDB is functioning, run the commands below to logon to the server.

sudo mysql -u root -p

When prompted for the password, type the password you created above to logon. If you successfully logon, you should see MariaDB welcome message.

Step 4: Install PHP-FPM and Related Modules

PHP is the last component of LEMP. It allows dynamic websites and applications to be created. Majority of the CMS in used today are using PHP. To install PHP and related modules, run the commands below

sudo apt-get install php-fpm php-mysql php-curl php-gd php-pear php-imagick php-imap php-mcrypt php-recode php-tidy php-xmlrpc

Now that PHP-FPM is installed, go and open Nginx default site configuration file and make sure the lines below are not commented out.

sudo nano /etc/nginx/sites-available/default

Then make the highlighted changes below and save the file.

server {
	listen 80 default_server;
	listen [::]:80 default_server;
        ............
        ............

        index index.php index.html index.htm;

        - pass PHP scripts to FastCGI server
        -
        location ~ .php$ {
        include snippets/fastcgi-php.conf;
        -
        - - With php-fpm (or other unix sockets):
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;        -Ubuntu 17.10
      - fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;        -Ubuntu 17.04
       - - With php-cgi (or other tcp sockets):
       - fastcgi_pass 127.0.0.1:9000;
  }
  ..........

After saving the file above, reload Nginx configuration settings by running the reload commands.

sudo systemctl reload nginx.service

To test whether PHP is installed and functioning, create a test PHP script in Nginx document root directory by running the commands below.

sudo nano /var/www/html/phpinfo.php

Then copy and paste the content below in the file and save.

?php
phpinfo();
?>

After saving the file, open your browser and browse to the server IP or hostname.. and you should see PHP test info page.

http://hostname/phpinfo.php
Nginx web server default test page

This is how to install LEMP on Ubuntu.

Summary:

This post shows students and users how to easily install Nginx, MariaDB and PHP on Ubuntu servers. It’s a beginning to running dynamic websites and applications based on PHP.

If you’re going to be running most content management systems, then this might be the first post to read.

Enjoy!

You may also like the post below:

Quickly Get LetsEncrypt Certificates for Apache2 on Ubuntu 17.04 /17.10

Quickly Get LetsEncrypt Certificates for Apache2 on Ubuntu 17.04 /17.10 &-8211; this Article or News was published on this date:2020-09-27 21:17:27 kindly share it with friends if you find it helpful

This brief tutorial shows students and new users how to quickly obtain LetEncrypt SSL/TLS certificates for your domain using Apache2 webserver on Ubuntu 17.04 | 17.10 systems. For those who don’t know, LetEncrypt is an opensource initiative to provide free SSL certificates to anyone with valid domains.

With LetEncrypt, you will never have to pay for another SSL/TLS certificate again. This post you’re ready today is encrypted via LetEncrypt and renewed every 60 days automatically.

So, if you’re running Ubuntu 17.04 | 17.10 with Apache2 installed, follow the steps below to get a free SSL/TLS certificates for your domains.

Step 1: Get Ubuntu / Apache2

This post assumes that you already have Ubuntu server with Apache2 webserver installed. If not, search this blog to find tutorials on installing Ubuntu and Apache2.

Or run the commands below to install Apache2

sudo apt-get install apache2

After installing Apache2, the commands below can be used to stop, start and enable Apache2 to always startup when the server boots.

sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service

Step 2: Installing LetEncrypt SSL/TLS Management Package

On Ubuntu systems, simply run the commands below to get LetEncrypt package. The package can then be used to obtain certificates for your domains.

sudo apt-get install python-certbot-apache

After running the commands above, your system should be ready to obtain certificates. But before you run the commands to obtain certificates, verify that the your domain name is setup in Apache2.

Step 3: Obtaining LetsEncrypt Certificates

To obtain LetEncrypt SSL/TLS certificates, run the commands to open Apache2 configuration file and add the domain names directives.

sudo nano /etc/apache2/sites-available/000-default.conf

Then verify that these lines are included

ServerName       example.com
ServerAlias      www.example.com

After verifying that information, run the commands below to obtain your certificates.

sudo certbot --apache -m [email protected] -d example.com -d www.example.com

Replacing www.exmaple.com and example.com with your domain name.

When you run the commands above, you must accept the terms.. Type A to accept.

Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf. You must agree
in order to register with the ACME server at
https://acme-v01.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A

You may also want to share your email with the Electronic Frontier Foundation..

Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: Y

Now all you do is sit back and relax.. LetsEncrypt will install and configure Apache2 with a valid SSL/TLS certificate. To correctly Apache2 up to handle all redirects to HTTPS, select option -2

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):2

This is how easy it is to setup LetEncrypt SSL/TLS for Apache2 on Ubuntu 17.04 | 17.10 systems.

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/example.com/privkey.pem
   Your cert will expire on 2018-02-24. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:
   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

To get setup a process to automatically renew the certificates, add a cron job to execute the renewal process.

sudo crontab -e

Then add the line below and save.

0 1 * * * /usr/bin/certbot renew & > /dev/null

The cron job will attempt to renew 30 days before expiring.

Summary:

This post shows students and new users how to easily install and obtain LetEncrypt SSL certificates for Apache2 on Ubuntu system. After setting it up, you’ll never have to pay for certificates again.

Enjoy!

You may also like the post below:

Setup Varnish and Apache2 on Ubuntu 17.04 | 17.10

Setup Varnish and Apache2 on Ubuntu 17.04 | 17.10 &-8211; this Article or News was published on this date:2020-09-27 21:17:21 kindly share it with friends if you find it helpful

Varnish is an opensource HTTP accelerator. It is usually configured to sit in front of webservers to quickly serve HTTP/HTTPS requests. Varnish can also be used as load balancer to distribute loads across multiple webservers.

This brief tutorial is going to show students and new users how to install and configure Varnish with Apache2 on Ubuntu 17.04 | 17.10. In this post, we’ll setup Varnish to be the doorway or front-end to Apache2 to quickly serve HTTP requests.

When you configure Varnish to be the font-end to Apache2 or other webservers, it can greatly enhance the server performance. This is because Varnish stores web caches in system’s memory ensuring faster retrieval in subsequent requests for the same resource.

To get this working, follow the steps below:

Step 1: Install Apache2

First run the commands below to install Apache2 webserver.

sudo apt-get update
sudo apt-get install apache2

After installing Apache2, the commands below can be used to stop, start and enable Apache2 to always startup everytime the server boots up.

sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service

By default apache2 HTTP service automatically is bond to port 80 and 443 for HTTPS. This

Step 2: Install Varnish

Now that Apache2 is installed, run the commands below to install Varnish

sudo apt-get install varnish

After installing Varnish, the commands below can be used to start, stop and enable Varnish to always start up when the server boots

sudo systemctl stop varnish.service
sudo systemctl start varnish.service
sudo systemctl enable varnish.service

Step 3: Switch Apache2 default post to 8080

Since we want Varnish to listen for all traffic coming to port 80 which is Apache2 default port, let’s configure Apache2 to use another port number. You can open Apache2 default port configuration file at /etc/apache2/ports.conf and change the Listen value to 8080.

To quickly change the port run the commands below to open Apache2 default port configuration file.

sudo nano /etc/apache2/ports.conf

Then make sure the file has these lines. Save when done.

- If you just change the port or add more ports here, you will likely also
- have to change the VirtualHost statement in
- /etc/apache2/sites-enabled/000-default.conf

NameVirtualHost 127.0.0.1:8080
Listen 127.0.0.1:8080

Next, open Apache2 default virtualhost config file.

sudo nano /etc/apache2/sites-available/000-default.conf

Then make the highlighted change below.

VirtualHost 127.0.0.1:8080>

Save then file and exit.

Then restart Apache2

sudo systemctl restart apache2.service

Now to access Apache2, you’ll have to enter the server IP or hostname followed by port &-8211; 8080.

ex. http://localhost:8080

Step 4: Configure Varnish to use Port 80

Now that port 80 is free, let’s configure Varnish to use that post instead. To assign port 80 to Varnish, run the commands below.

Varnish default configure file is location at /etc/default/varnish

Open it by running the commands below:

sudo nano /etc/default/varnish

Then look for the config block under Alternative 2 and make the highlighted changes as shown below.

-- Alternative 2, Configuration with VCL
-
- Listen on port 6081, administration on localhost:6082, and forward to
- one content server selected by the vcl file, based on the request.
-
DAEMON_OPTS="-a :80 
-T localhost:6082 
-f /etc/varnish/default.vcl 
-S /etc/varnish/secret 
-s malloc,256m"

Save the file when you’re done.

Next, run the commands below to open the default.vcl file

sudo nano /etc/varnish/default.vcl

Then verify the line shown below is what you see.

- Default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "8080";
}

Save the file and close out.

After that, restart both Apache2 and Varnish

sudo systemctl restart apache2.service
sudo systemctl restart varnish.service

Next, run the commands below to start Varnish if it won’t start.

sudo /usr/sbin/varnishd -a :80 -b localhost:8080

If everything is setup correctly, Varnish should be the default listener of port 80. To test, run the commands below.

curl -I http://localhost

The results should be something like the one below

HTTP/1.1 200 OK
Date: Sun, 23 Jul 2017 17:45:49 GMT
Server: Apache/2.4.25 (Ubuntu)
Last-Modified: Sun, 23 Jul 2017 17:01:05 GMT
Vary: Accept-Encoding
Content-Type: text/html
X-Varnish: 10 3
Age: 9
Via: 1.1 varnish (Varnish/5.0)
ETag: W/"2aa6-554ff0b3c88c9-gzip"
Accept-Ranges: bytes
Connection: keep-alive

Congratulations! You’ve just installed Apache2 with Varnish support.

You may also like the post below:

How to Install Ghost on Ubuntu 17.04 | 17.10

How to Install Ghost on Ubuntu 17.04 | 17.10 &-8211; this Article or News was published on this date:2020-09-27 21:17:17 kindly share it with friends if you find it helpful

This post shows new users and students how to easily install Ghost on Ubuntu 17.04 | 17.10. Ghost is a fairly new blogging platform powered by Node.js. Ghost is a very clean and lightweight platform designed for bloggers who want to focus on blogging and nothing else.

Unlike WordPress and other content management systems based on PHP, Ghost simple in design and function. No additional packages and server needed, just JavaScript.

To get Ghost quickly running on Ubuntu, follow the steps below

Step 1: Update Ubuntu

Before installing Ghost or any other packages in Ubuntu, it’s recommended that you update the server. To do that, run the commands below

sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove

After running the commands above, you may want to restart the server.

Step 2: Install Node.js package

Since Ghost is based on Node.js run the commands below to download Node.js packages from its repository

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -

Next, run the commands below to install Node.js and required packages in order for Ghost to function. Nginx webserver will be needed for this. s

sudo apt-get install nodejs

Step 3: Install and Configure Ghost

Now that you’ve install Node.js and other packages that Ghost needs, let’s go and download Ghost packages from its repository. To do that, run the commands below.

wget https://ghost.org/zip/ghost-latest.zip -O ghost.zip

The commands above download the latest version of Ghost packages.

After downloading Ghost package, run the commands below to create Ghost document root directory.

sudo mkdir -p /var/www/html/ghost/

Then unzip Ghost package in the root directory.

sudo unzip ghost.zip -d /var/www/html/ghost/

Now change into the root directory and install Ghost

cd /var/www/html/ghost
sudo npm install --production

Wait for the installation to complete.

After the installation completes, run the commands below to create Ghost configuration file from its example file.

sudo cp config.example.js config.js

Then open the configuration file and configure make sure the content looks like the highlighted one below.

sudo nano config.js

Validate that you configure the settings below to match your server. The URL is the URL to access the site.

// --- Production
// When running Ghost in the wild, use the production environment.
// Configure your URL and mail settings here
production: {
url: 'http://myghost.com',
mail: {},
database: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '/content/data/ghost.db')
},
debug: false
},

server: {
host: '0.0.0.0',
port: '2368'
}
},

Make the change and save the file.

After saving the file, run the commands below to start Ghost.

sudo npm start --production

Ghost by default runs on port &-8211; 2368. You must type the port number after the URL to access.

ex. http://myghost.com:2368

Ghost should be accessible.

ghost ubuntu

To create an account, type URL followed by /ghost/signup

ex. http://myghost.com:2368/ghost/signup

Step 4 Install Nginx Webserver as Proxy

Since you must always type the hostname followed by the port number to access Ghost, which you probably don’t want your users to type, you must install Nginx and configure it as a proxy server for Ghost. To do that follow the steps below.

sudo apt-get install nginx

Then create a ghost config file by running the commands below.

sudo nano /etc/nginx/conf.d/ghost.conf

Then copy and paste the content below into the file, then save.

server {
    listen 80;
    listen [::]:80;
    server_name myghost.com www.myghost.com;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://127.0.0.1:2368;
    }
}

Restart Nginx and connect to your site via its domain or hostname.

sudo systemctl restart nginx

Congratulations! You’ve just installed Ghost on Ubuntu

Enjoy!

You may also like the post below: