Documente Academic
Documente Profesional
Documente Cultură
Install Nginx
Nginx (pronounced engine-x) is a free, open-source, high-performance HTTP server and
reverse proxy, as well as an IMAP/POP3 proxy server written by Igor Sysoev.
To install Nginx enter the following command in your terminal:
Note: If you have already installed apache2 in your system, remove it first to avoid
conflicts. To uninstall apache, run the following commands:
sudo apt-get purge apache2*
sudo apt-get autoremove
Now, install nginx using command:
sudo apt-get install nginx
Start Nginx service using the command:
sudo service nginx start
Test nginx
Open up your web browser and navigate to http://ip-address/ or http://localhost/.
You will see a screen something like below.
Configure Nginx
Open the file /etc/nginx/nginx.conf in any editor:
sudo nano /etc/nginx/nginx.conf
Set the worker_processes (i.e No. of CPUs in your system). To see the no. of CPUs,
use the command lscpu. In my case its 1. So I set this as 1.
worker_processes 1;
Restart Nginx service:
sudo service nginx restart
default
vhost(server
block)
is
defined
in
the
/etc/nginx/sites-
available/default file.
Open the file /etc/nginx/sites-available/default in any editor.
sudo nano /etc/nginx/sites-available/default
Under the Server section, set the server FQDN or IP address as shown below.
[...]
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name server.unixmen.local;
[...]
Make sure youve added index.php line.
Here,
Now scroll down further and find the section #location ~ \.php$. Uncomment and modify
the following lines as shown below.
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#
#
#
fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
Install MySQL
MySQL is a relational database management system (RDBMS) that runs as a server
providing multi-user access to a number of databases, though SQLite probably has more
total embedded deployments
sudo apt-get install mysql-server mysql-client
During installation, youll be asked to setup the MySQL root user password. Enter the
password and click Ok.
Install MariaDB
MariaDB is a drop in replacement for MySQL. It is a robust, scalable and reliable SQL
server that comes rich set of enhancements.
First you have to remove existing MySQL packages if any. To completely uninstall MySQL
with configuration files, enter the following command:
sudo apt-get purge mysql*
Run the following command to remove unwanted packages.
sudo apt-get autoremove
Now add MariaDB PPA to install it. Run the following commands to add PPA.
sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a
1bb943db
sudo add-apt-repository 'deb http://mirrors.scie.in/mariadb/repo/5.5/ubuntu trust
y main'
Update the software sources list and install MariaDB using following commands:
sudo apt-get update
sudo apt-get install mariadb-server mariadb-client -y
During installation you will be asked to set database root user password.
Re-enter
password:
MariaDB [(none)]>
Check if mariadb is running or not, using the following command:
sudo service mysql status
Sample output:
* /usr/bin/mysqladmin
686
Server version
Protocol version
Connection
5.5.37-MariaDB-0ubuntu0.14.04.1
10
Localhost via UNIX socket
UNIX socket
/var/run/mysqld/mysqld.sock
Uptime:
3 min 34 sec
Opens: 338
Flush tables: 4
Open ta
Install PHP
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely used open-source
general purpose scripting language that is especially suited for web development and can
be embedded into HTML.
Install PHP with following command:
sudo apt-get install php5 php5-fpm php5-mysql
Configure PHP
Open php.ini file in any editor:
sudo nano /etc/php5/fpm/php.ini
Find the line cgi.fix_pathinfo=1, uncomment it and change the value 1 to 0.
cgi.fix_pathinfo=0
Now restart php-fpm service.
sudo service php5-fpm restart
Test PHP
Create a sample testphp.php file in nginx document root folder.
sudo nano /usr/share/nginx/html/testphp.php
Add the following lines in it.
<?php
phpinfo();
?>
Save and exit the file.
Navigate to
the
line
fastcgi_pass
unix:/var/run/php5-fpm.sock;
and
change
#
#
fastcgi_pass 127.0.0.1:9000;
#
#
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
Save and exit the file. Finally restart nginx service.
sudo service nginx restart
it
Manage
MySQL
Databases
phpMyAdmin (Optional)
Using
phpMyAdmin is a free open-source web interface tool used to manage your MySQL
databases.
Install phpMyAdmin
It is available in the Official Debian repositories. So install it with command:
sudo apt-get install phpmyadmin
Select any webserver. By default, nginx will not be displayed here. So, select apache or
lighttpd and let us link phpmyadmin to work with nginx webserver later.
Now you can manage your MySQL databases from phpMyAdmin web interface.
Thats it. Your LEMP server is up and running now.