Jump to content
Forgot your email address? ×
×
×
  • Create New...

LEMP Server installation on Debian 7


Recommended Posts

This is a Debian 7 nginx, MariaDB, and PHP-FPM (+phpMyAdmin) installation guide.
 
Note on MariaDB: This is meant to be a REPLACEMENT of MySQL. It should work where MySQL works.
 
 
1. Installing and configuring nginx.

# apt-get install nginx
# service nginx start

Now if you open your IP address or website address in your browser you should see a "Welcome to nginx!" page. This means you've successfully installed nginx.
 
Now to configure...

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

Under the Server section set your "server_name" to your FQDN (fully qualified domain name). Don't forget to include "index.php" on the "index" line. It should look somewhat like this when finished:

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 mywebsitedomain.com;

Scroll down to the Location section and uncomment the necessary lines. Make modifications as shown:

location ~ .php$ {
		try_files $uri =404;
		fastcgi_split_path_info ^(.+.php)(/.+)$;
	#	# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
	#
	#	# With php5-cgi alone:
	#	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;
	}

CTRL+X, Y, Enter.
 
Now you need to edit the nginx.conf file:

# nano /etc/nginx/nginx.conf 

Set your "worker_processes" equal to your amount of cores. In this case I'll be using 4. Set your "worker_connections" equal to the input of the following command:

# ulimit -n

Change "keepalive_timeout 65;" to "keepalive_timeout 15;" then add these lines under the http block:

client_body_buffer_size 10K;
client_header_buffer_size 1k;
client_max_body_size 8m;
large_client_header_buffers 2 1k;
client_body_timeout 12;
client_header_timeout 12;
send_timeout 10;

CTRL+X, Y, Enter.
 
You can test your configuration before proceeding, and if there are any mistakes you will be notified what they are and on which line.

# nginx -t

A correct modification of the configuration should output this data:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Restart nginx:

# service nginx restart

2. Installation of MariaDB.

# apt-get install python-software-properties
# apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
# add-apt-repository 'deb http://mirrors.syringanetworks.net/mariadb/repo/10.1/debian wheezy main'
# apt-get update
# apt-get install mariadb-server mariadb-client -y

Set the root user password for mysql when prompted.
 
This is how you enter the prompt, when finished just type "quit":

# mysql -v -u root -p

Enter the root sql password you just chose. It will look like this, and you can figure out more things by following the notes:

Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 2579
Server version: 10.1.1-MariaDB-1~wheezy-wsrep-log mariadb.org binary distribution, wsrep_25.10.r4123

Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.

Reading history-file /root/.mysql_history
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]>

You can check the status of the server like this:

# service mysql status

Example output of command:

[info] /usr/bin/mysqladmin  Ver 9.1 Distrib 10.1.1-MariaDB, for debian-linux-gnu on x86_64
Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.

Server version          10.1.1-MariaDB-1~wheezy-wsrep-log
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/run/mysqld/mysqld.sock
Uptime:                 11 hours 8 min 3 sec

Threads: 1  Questions: 44634  Slow queries: 0  Opens: 431  Flush tables: 1  Open tables: 113  Queries per second avg: 1.113.

3. Installation of PHP-FPM

# apt-get install php5 php5-fpm php5-mysql
# nano /etc/php5/fpm/php.ini

Scroll down to the line "cgi.fixpathinfo=1" and uncomment it. Change the value from 1 to 0. Restart the service:

# service php5-fpm restart

Create a phpinfo page:

# nano /usr/share/nginx/html/phpinfo.php

Here are the contents of the file you've created:

<?php
 phpinfo();
?>

CTRL+X, Y, Enter.
 
Now in your browser, navigate to your IP address or domain followed by the phpinfo.php file. Here's an example:

http://mywebsitedomain.com/phpinfo.php

4. Installation of phpMyAdmin

# apt-get install phpmyadmin

Select either option and hit OK. Even though we aren't using apache2 or lighttpd, we can make this work with nginx. Select "<Yes>" when prompted to configure database for phpmyadmin with dbconfig-common. Enter the SQL password you chose earlier as the "administrative user" password. Now enter a password for use with phpMyAdmin.
 
Now to make it work with nginx we're going to use a symlink:

# ln -s /usr/share/phpmyadmin/ /usr/share/nginx/html
# service nginx restart

Navigate in your browser to your IP/domain name and append a "/phpmyadmin" to the end like this:

http://mywebsitedomain.com/phpmyadmin

You can now login with the username root and password chosen earlier. You can use phpMyAdmin to easily setup databases and user accounts for anything you want to install that requires SQL.

  • Love 3
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Announcements

  • -15% Discount in Metin2 Dev Store (01/10/2021 => 31/12/2021) => Code => 15_PCT_OCT_TO_DEC_2021


Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.