Thursday, July 23, 2015

Install LEMP on Centos 7.1

1. Install Nginx, then test it at http://ip_address
    yum install nginx -y
    systemctl start nginx 
    systemctl enable nginx

2. Modify /etc/nginx/nginx.conf to add following:
    location ~ \.php$ {
            root           /usr/share/nginx/html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME \ $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

3. Restart Nginx server:
    systemctl restart nginx

4. Install MySQL
    yum install mariadb-server mariadb
    systemctl start mariadb
    mysql_secure_installation 
    systemctl enable mariadb.service 

5. Install PHP
    yum install php php-common php-fpm php-mysql -y
    systemctl start php-fpm
    systemctl enable php-fpm

6. Modify /etc/php.ini to make "cgi.fix_pathinfo=0"

7. Modify /etc/php-fpm.d/www.conf to change both user and group equal to nginx instead of apache.

8. Restart Nginx:
    systemctl restart php-fpm

9. Create /usr/share/nginx/html/info.php with following code to test php. The php information page should be displayed at http://ip/info.php
    <?php phpinfo(); ?>

10. After the information on page http://ip/info.php confirmed. delete the file /usr/share/nginx/html/info.php.


If needed do the following to change the default PHP-FPM port to Unix socket:

1. Modify /etc/php-fpm.d/www.conf as show below:
from:
    listen = 127.0.0.1:9000
to:
    listen = /var/run/php-fpm/php5-fpm.sock

2. Modify /etc/nginx/nginx.conf
from:
    fastcgi_pass 127.0.0.1:9000;
to:
    fastcgi_pass unix:/var/run/php-fpm/php5-fpm.sock;

Finally, restart Nginx and PHP-FPM:
    systemctl restart nginx
    systemctl restart php-fpm

No comments: