RSS

To Install LEMP (Nginx, MySQL, PHP) On Centos for WordPress

20 Sep

To Install LEMP (Nginx, MySQL, PHP) On Centos
1. Installing EPEL in CentOS 

# yum install epel-release
2. To install php

# install php-fpm php-mysql

# vi /etc/php.ini

;cgi.fix_pathinfo=1 -> change to ;cgi.fix_pathinfo=0

# vi /etc/php-fpm.d/www.conf

[www]
listen = /var/run/php-www.socket
user = www-data
group = www-data

listen.owner = www-data
listen.group = www-data
listen.mode = 0660

request_slowlog_timeout = 5s
slowlog = /var/log/php-fpm/blogcms_log
listen.allowed_clients = 127.0.0.1

pm = dynamic
pm.max_children = 10
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 4
pm.max_requests = 400
listen.backlog = -1
pm.status_path = /status

request_terminate_timeout = 120s
rlimit_files = 131072
rlimit_core = unlimited

catch_workers_output = yes

php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
php_admin_value[error_log] = /var/log/php-fpm/www-error_log
php_admin_flag[log_errors] = on
3. Install and Configure PHP-APC

# yum install php-pecl-apc

# vi /etc/php.d/apc.ini

extension = apc.so
apc.enabled=1
apc.shm_segments=1
apc.shm_size=128M
apc.num_files_hint=1024
apc.user_entries_hint=4096
apc.ttl=7200
apc.use_request_time=1
apc.user_ttl=7200
apc.gc_ttl=3600
apc.cache_by_default=1
apc.filters
apc.mmap_file_mask=/tmp/apc.XXXXXX
apc.file_update_protection=2
apc.enable_cli=0
apc.max_file_size=1M
apc.stat=1
apc.stat_ctime=0
apc.canonicalize=0
apc.write_lock=1
apc.report_autofilter=0
apc.rfc1867=0
apc.rfc1867_prefix =upload_
apc.rfc1867_name=APC_UPLOAD_PROGRESS
apc.rfc1867_freq=0
apc.rfc1867_ttl=3600
apc.include_once_override=0
apc.lazy_classes=0
apc.lazy_functions=0
apc.coredump_unmap=0
apc.file_md5=0
apc.preload_path

# /etc/init.d/php-fpm start
# chkconfig php-fpm on

4. Installing and Configuring NGINX

# yum install nginx

# /etc/init.d/nginx start

# chkconfig nginx on

# mkdir /var/www/wordpress/public_html -p
# mkdir /var/www/wordpress/logs -p
# chown -R nginx:nginx /srv/www/wordpress

# mkdir /etc/nginx/sites-available -p
# mkdir /etc/nginx/sites-enabled -p

# cd /tmp
# wget http://wordpress.org/latest.tar.gz

# tar -xvf latest.tar.gz -C /var/www/wordpress/public_html/ –strip-components=1

# vi /etc/nginx/nginx.conf

include /etc/nginx/sites-enabled/*;          # to add this line at end

5. To create a file as following

# cd /etc/nginx/sites-available/

# cat lqs.co.in.conf
server {
server_name lqs.co.in;

access_log /var/www/wordpress/logs/access.log;
error_log /var/www/wordpress/logs/error.log;
root /var/www/wordpress/public_html;

location / {
index index.php;
}
# Disable favicon.ico logging
location = /favicon.ico {
log_not_found off;
access_log off;
}
# Allow robots and disable logging
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Enable permalink structures
if (!-e $request_filename) {
rewrite . /index.php last;
}
# Handle php requests
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/wordpress/public_html$fastcgi_script_name;
}
# Disable static content logging and set cache time to max
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
# Deny access to htaccess and htpasswd files
location ~ /\.ht {
deny all;
}
}

# cd ../sites-enabled/
# ln -s /etc/nginx/sites-available/lqs.co.in.conf

6. Installing and Configuring MySQL

yum install mysql-server

service mysqld start

mysql_secure_installation

[root@localhost public_html]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE USER wordpressuser@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> SET PASSWORD FOR wordpressuser@localhost= PASSWORD(“nginx@123”);
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

Edit the /etc/my.cf file to match the following, limiting the server only to listen to local connections:

# cat /etc/my.cnf
[mysqld]
bind-address = 127.0.0.1 # server listen to locally
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

# /etc/init.d/mysqld restart

# chkconfig mysqld on

7. Finally go to browser and check as follow:

http://localhost or IP-address

 

 
Leave a comment

Posted by on September 20, 2017 in Documents, Linux, Web Service

 

Leave a comment