Home Linux How to install nginx, mysql, phpmyadmin, php in Ubuntu

How to install nginx, mysql, phpmyadmin, php in Ubuntu

0

How to install nginx, mysql, phpmyadmin, php in Ubuntu

Lets first update local repository.

To install nginx in Ubuntu

#sudo apt-get update
#sudo apt-get install nginx

once installed you can check if the nginx service is running or not

#sudo service nginx restart

#sudo service nginx status

#sudo service nginx stop

#sudo service nginx start

These are the commands to check status/stop/restart/start of nginx service as shown in Image – 1

How to install nginx, mysql, phpmyadmin, php in Ubuntu

Image – 1

If there is no port conflict then nginx service will start. else you can check the setting here

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

and change the default port to some other port then save and close the editor as shown in Image – 2

Image – 2

Like I had changed the port to 8081 and in browser type localhost:8081 which shows Welcome to nginx!

To install MySql Server in Ubuntu

#sudo apt-get install mysql-server

Follow the steps to install Mysql-Server while it will ask for creating password for the root user.

once after successfully installed MySql server. you can check the service if its running

To check mysql service is running or not

#sudo service mysql status

#sudo service mysql start

#sudo service mysql stop

#sudo service mysql restart

You can set mysql root user password and in case If you want to reset the current mysql password then run this command and follow the steps as shown in Image – 4

Image – 4

#sudo dpkg-reconfigure mysql-server-5.5

To log in mysql in terminal

#sudo mysql -u root -p

as shown in Image – 5

Image – 5

To install PhpMyadmin in Ubuntu

#sudo apt-get install phpmyadmin

Once installed you can browse and login using root and default set password as shown in Image – 6

http://localhost/phpmyadmin

Image – 6

How to configure Apache to Allow .htaccess Overrides

Lets first enable .htaccess file by editing our Apache configuration file.

sudo nano /etc/apache2/conf-available/phpmyadmin.conf

Add an AllowOverride All directive within the <Directory /usr/share/phpmyadmin> section of the configuration file

like this:

<Directory /usr/share/phpmyadmin>
Options FollowSymLinks
DirectoryIndex index.php
AllowOverride All
. . .

Save and close the file

Restart apache service

#sudo service apache2 restart

Create an .htaccess File inside /usr/share/phpmyadmin

#sudo nano /usr/share/phpmyadmin/.htaccess

Add below lines

AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user

Save and close the editor

Create the .htpasswd file for Authentication

For this we need to install additional package.

#sudo apt-get install apache2-utils

The location that we selected for the password file was “/etc/phpmyadmin/.htpasswd”. Let’s create this file and a user.

#sudo htpasswd -c /etc/phpmyadmin/.htpasswd username

It will prompt for password for the user as shown in Image – 7

Image – 7

If you want to add another user then command is

#sudo htpasswd /etc/phpmyadmin/.htpasswd additionaluser

Now, when you access your phpMyAdmin subdirectory, you will be prompted for the additional account name and password that you just configured: as shown in Image – 8

Image – 8

http://localhost/phpmyadmin

After entering the Apache authentication, you’ll be taken to the regular phpMyAdmin authentication page to enter your login credentials.

This will add an additional layer of security since phpMyAdmin has suffered from vulnerabilities in the past.

To install PHP in ubuntu

#sudo apt-get install php5-cli

once installed check the version of php installed

#php -v

as shown in Image – 9

Image – 9

You might like to upgrade PHP Version from 5.5.9 to PHP 7.1 then check my post here

solve phpinfo() shows version 5.5.9 but in cli php -v shows version 7.1

To configure PHP Processor and configure nginx to use PHP Processor

#sudo apt-get install php5-fpm

We have installed PHP components. Open php5-fpm configuration file to do some changes

#sudo nano /etc/php5/fpm/php.ini

find out this line of code (cgi.fix_pathinfo=0)

and do uncomment and change the value 1 to 0 as shown in Image – 10

Image – 10

#sudo service php5-fpm restart

How to change configuration so that nginx will use PHP Processor

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

Code in bold need to add in the default page.

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;
index index.php index.html index.htm;

server_name server_domain_name_or_IP;

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

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
#sudo service nginx restart

To test PHP is working 

Create a info.php file in side /usr/share/nginx/html with this code and save as info.php

#sudo nano /usr/share/nginx/html/info.php
<?php
phpinfo();
?>

Now open browser and type localhost/info.php

If you can see this page as shown in image –  then PHP processing with Nginx successfully configured.

You might also like:

How to resolve network wifi issue in Ubuntu 16.04 LTS

Cannot change screen brightness in ubuntu

How to install .deb file in Ubuntu

VPN Connection issue in Windows 10

 

NO COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Exit mobile version