메뉴 건너뛰기

컴' 게시판

본문시작

조회 수 37210 추천 수 0 댓글 0

How to Install Linux, nginx, MySQL, PHP (LEMP) stack on Ubuntu 12.04


About Lemp


LEMP stack is a group of open source software to get web servers up and running. The acronym stands for Linux, nginx (pronounced Engine x), MySQL, and PHP. Since the server is already running Ubuntu, the linux part is taken care of. Here is how to install the rest. 

Setup


The steps in this tutorial require the user to have root privileges. You can see how to set that up in the Initial Server Setup Tutorial in steps 3 and 4. 

Step One—Update Apt-Get


Throughout this tutorial we will be using apt-get as an installer for all the server programs. On May 8th, 2012, a serious php vulnerability was discovered, and it is important that we download all of the latest patched software to protect the virtual private server. 

Let's do a thorough update.
sudo apt-get update

Step Two—Install MySQL


Once everything is fresh and up to date, we can start to install the server software, beginning with MySQL and dependancies.
sudo apt-get install mysql-server

During the installation, MySQL will ask you to set a root password. If you miss the chance to set the password while the program is installing, you can easily create it later within the MySQL shell. 

Step Three—Install nginx


Once MySQL is all set up, we can move on to installing nginx on the VPS.
sudo apt-get install nginx

nginx does not start on its own. To get nginx running, type:
sudo service nginx start

You can confirm that nginx has installed an your web server by directing your browser to your IP address. You can run the following command to reveal your VPS's IP address.
ifconfig eth0 | grep inet | awk '{ print $2 }'

Step Four—Install PHP


To install PHP-FPM, open terminal and type in these commands. We will configure the details of nginx and php details in the next step:
sudo apt-get install php5-fpm

Step Five—Configure php


We need to make one small change in the php configuration.Open up php.ini:
 sudo nano /etc/php5/fpm/php.ini

Find the line, cgi.fix_pathinfo=1, and change the 1 to 0.
cgi.fix_pathinfo=0
If this number is kept as 1, the php interpreter will do its best to process the file that is as near to the requested file as possible. This is a possible security risk. If this number is set to 0, conversely, the interpreter will only process the exact file path—a much safer alternative. Save and Exit. 

Restart php-fpm:
sudo service php5-fpm restart

Step Six—Configure nginx


Open up the default virtual host file.
sudo nano /etc/nginx/sites-available/default

The configuration should include the changes below (the details of the changes are under the config information):
 [...]
server {
        listen   80;
     

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

        server_name example.com;

        location / {
                try_files $uri $uri/ /index.html;
        }

        error_page 404 /404.html;

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

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ .php$ {
                #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;
                
        }

}
[...]

Here are the details of the changes:

  • Add index.php to the index line.

  • Change the server_name from local host to your domain name or IP address (replace the example.com in the configuration)

  • Change the correct lines in “location ~ .php$ {“ section

Save and Exit

Step Seven—Create a php Info Page


We can quickly see all of the details of the new php configuration. 

To set this up, first create a new file:
sudo nano /usr/share/nginx/www/info.php

Add in the following line:
<?php
phpinfo();
?>

Then Save and Exit. 

Restart nginx
sudo service nginx restart

You can see the nginx and php-fpm configuration details by visiting http://youripaddress/info.php

Your LEMP stack is now set up and configured on your virtual private server.

See More

After installing LEMP, you can Install WordPress, go on to do more with MySQL (A Basic MySQL Tutorial) or Install phpMyAdminCreate an SSL Certificate, or Install an FTP Server
TAG •

  1. 08
    Jun 2013
    10:27

    NGINX 502 Gateway Error

    CategoryIT/개발 By꿈자 Reply0 Views18718 Votes0
    Read More
  2. 04
    Jun 2013
    09:44

    우분투 NGINX 가상호스트 설정

    CategoryIT/개발 By꿈자 Reply0 Views29105 Votes0
    Read More
  3. 21
    May 2013
    18:16

    ajaxFileupload.js 사용시 ...

    CategoryIT/개발 By꿈자 Reply0 Views18531 Votes0
    Read More
  4. 14
    May 2013
    21:57

    PHP 백그라운드 비동기 처리

    CategoryIT/개발 By꿈자 Reply0 Views28811 Votes0 secret
    Read More
  5. 08
    May 2013
    09:55

    RSA XML to PEM 변환

    CategoryIT/개발 By꿈자 Reply0 Views27739 Votes0 file
    Read More
  6. 27
    Apr 2013
    00:29

    우분투 종료/재부팅 및 관...

    CategoryIT/개발 By꿈자 Reply0 Views25422 Votes0
    Read More
  7. 27
    Apr 2013
    00:12

    우분투(Ubuntu) LEMP(Linux...

    CategoryIT/개발 By꿈자 Reply0 Views37210 Votes0
    Read More
  8. 25
    Apr 2013
    15:35

    시화/안산 - 강남 간 고속버스

    Category개인자료 By꿈자 Reply0 Views52724 Votes0 file
    Read More
  9. 25
    Apr 2013
    09:16

    XMPP

    CategoryIT/개발 By꿈자 Reply0 Views211 Votes0
    Read More
  10. 19
    Apr 2013
    22:52

    색감 테스트

    Category카메라 By꿈자 Reply1 Views46 Votes0 file
    Read More
Board Pagination Prev 1 ... 10 11 12 13 14 ... 17 Next
/ 17