Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Install and configure LNMP

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Source code installation configuration LNMP

Updated: 2016-08-02

System environment: CentOS 6.5

Software environment: nginx 1.8.1, mysql 5.6.22, php 5.6.19

Native IP: 192.168.1.88, 192.168.1.36

Turn off firewalls and security mechanisms

# service iptables stop

# setenforce 0

# getenforce

[nginx]

1. Create a user

# groupadd nginx

# useradd-M-s / sbin/nologin nginx-g nginx

two。 Compilation and installation

# yum-y install pcre-devel zlib-devel gcc

# tar zvxf nginx-1.8.1.tar.gz-C / usr/src/

# cd / usr/src/nginx-1.8.1/

#. / configure-prefix=/usr/local/nginx-user=nginx-group=nginx-with-http_stub_status_module-with-http_flv_module-with-http_gzip_static_module

# make & & make install

3. Create a soft connection # ln-s / usr/local/nginx/sbin/* / usr/local/sbin/

4. Check the configuration file

# nginx-t

5. Start the nginx service

# nginx

# netstat-anpt | grep nginx

Tcp 0 0 0.0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0 of the LISTEN 17295/nginx.

Browsers access native IP

Nginx configuration optimization

The number of processes to be started by worker_processes auto / / nginx, which is generally equal to the total number of cores of cpu (set to "auto" to try to detect it automatically)

Worker_rlimit_nofile 102400 / / this directive means that when a nginx process opens the maximum number of file descriptors, the theoretical value should be the maximum number of open files (ulimit-n) divided by the number of nginx processes, but the nginx allocation request is not so uniform, so it is best to be consistent with the value of ulimit-n.

Worker_connections 5000 / / the maximum number of connections allowed per process, theoretically the maximum number of connections per nginx server is worker_processes*worker_connections.

Keepalive_timeout 60 / / keepalive timeout

Access_log / var/log/nginx/access.log / / sets whether nginx will store access logs

Error_log / var/log/nginx/error.log / / tells nginx to log only serious errors

[mysql]

1. Create a user

# useradd mysql2. Compilation and installation

# yum-y install ncurses ncurses-devel gcc libtool gcc-c++ make cmake#tar zvxf mysql-5.6.22.tar.gz-C / usr/src

# cd / usr/src/mysql-5.6.22/

# cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\

-DMYSQL_DATADIR=/usr/local/mysql/data\

-DSYSCONFDIR=/etc\

-DWITH_MYISAM_STORAGE_ENGINE=1\

-DWITH_INNOBASE_STORAGE_ENGINE=1\

-DWITH_PARTITION_STORAGE_ENGINE=1\

-DENABLE_DOWNLOADS=1\

-DWITH_READLINE=1\

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock\

-DMYSQL_TCP_PORT=3306\

-DDEFAULT_CHARSET=utf8\

-DDEFAULT_COLLATION=utf8_general_ci\

-DEXTRA_CHARSETS=all\

-DMYSQL_USER=mysql

# make & & make install

3. Change the master group

# chown-R mysql:mysql / usr/local/mysql/

Initialize:

# / usr/local/mysql/scripts/mysql_install_db-user=mysql-basedir=/usr/local/mysql/-datadir=/usr/local/mysql/data/

Copy the file:

# cp / usr/local/mysql/support-files/mysql.server / etc/rc.d/init.d/mysqld

# cp / usr/local/mysql/support-files/my-default.cnf / etc/my.cnf

Add and start the mysqld service:

[root@localhost] # chkconfig-- add mysqld

[root@localhost ~] # chkconfig mysqld on

[root@localhost ~] # service mysqld start

Starting MySQL.. [OK]

Soft connection:

[root@localhost] # ln-s / usr/local/mysql/bin/* / usr/local/bin/

4. Set mysql password

# mysqladmin-uroot password 'newpass' error when changing password: mysqladmin: connect to server at' localhost' failed

Error: 'Access denied for user' root'@'localhost' (using password: YES) 'enter the database to change the password:

1.service mysqld stop

2. Mysqld_safe-skip-grant-tables &

3. Enter mysql-uroot-p

> use mysql

> update user set password=PASSWORD ("newpass") where user= "root"

Update permissions for flush privileges;

> quit exit

4.service mysqld restart

5. Mysql-uroot-pnewpass entry

[PHP]

1. Compilation and installation

# yum-y install openssl openssl-devel libxml2 libxml2-devel bzip2 bzip2-devel curl curl-devel libjpeg libpng freetype libjpeg-devel libpng-devel freetype-devel libmcrypt-devel

# tar zvxf php-5.6.19.tar.gz-C / usr/src

# cd / usr/src/php-5.6.19/

# / configure-- prefix=/usr/local/php5-- with-config-file-path=/usr/local/php5-- enable-fpm-- with-fpm-user=php-- with-fpm-group=php-- with-mysql=mysqlnd-- with-mysqli=mysqlnd-- with-pdo-mysql=mysqlnd-- with-iconv-dir-- with-freetype-dir=/usr/local/freetype-- with-jpeg-dir-- with-png-dir-- with-zlib-- with-libxml-dir-- enable-xml-- disable- Rpath-enable-bcmath-enable-shmop-enable-sysvsem-enable-inline-optimization-with-curl-enable-mbregex-enable-mbstring-with-mcrypt-enable-ftp-with-gd-enable-gd-native-ttf-with-openssl-with-mhash-enable-pcntl enable-sockets with-xmlrpc enable-zip enable-soap with-gettext disable-fileinfo enable-opcache

Error report:

1. Configure: error: mcrypt.h not found. Please reinstall libmcrypt.

# tar zvxf libmcrypt-2.5.7.tar.gz-C / usr/src/

# cd / usr/src/libmcrypt-2.5.7/

#. / configure-- prefix=/usr/local/libmcrypt & & make & & make install

2. Configure: error: Don't know how to define struct flock on this system, set-enable-opcache=no

# vim / etc/ld.so.conf.d/local.conf

/ usr/local/lib # add the line

# ldconfig / / make it effective

Continue to compile and install:

# make & & make install

two。 Configure the php-fpm module

[root@localhost php-5.6.19] # cp php.ini-development / usr/local/php5/php.ini

[root@localhost ~] # cd / usr/local/php5/etc/

[root@localhost etc] # ls

Pear.conf php-fpm.conf.default

[root@localhost etc] # cp php-fpm.conf.default php-fpm.conf

[root@localhost etc] # useradd-M-s / sbin/nologin php

Edit configuration file

# vim php-fpm.conf

25 pid = run/php-fpm.pid

131user = php

132 group = php

236 pm.max_children = 50

241 pm.start_servers = 20

246 pm.min_spare_servers = 5

251 pm.max_spare_servers = 35

Start php-fpm

[root@localhost etc] # / usr/local/php5/sbin/php-fpm

[root@localhost etc] # netstat-anpt | grep php-fpm

Tcp 00 127.0.0.1 9000 0.0.0.0 * LISTEN 45716/php-fpm

3. Add php-fpm module to nginx configuration file

# vim / usr/local/nginx/conf/nginx.conf

Server {

Listen 80

Server_name www.baidu.com

Charset utf-8

Access_log logs/host.access.log main

Location / {

Root html/baidu

Index index.html index.htm index.php

}

Location ~\ .php$ {

Root html/baidu

Fastcgi_pass 127.0.0.1:9000

Fastcgi_index index.php

Include fastcgi.conf

}

}

Restart nginx

[root@localhost etc] # killall nginx

[root@localhost etc] # netstat-anpt | grep nginx

[root@localhost etc] # nginx

[root@localhost etc] # netstat-anpt | grep nginx

Tcp 0 0 0.0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0 of the LISTEN 45787/nginx.

4. test

Domain name mapping

# vim / etc/hosts

192.168.1.36 www.baidu.com

Create a web page directory

# mkdir / usr/local/nginx/html/baidu

test

# echo Baidu > / usr/local/nginx/html/baidu/index.html

# elinks-- dump 192.168.1.36

Baidu

Test nginx and PHP connectivity

[root@localhost baidu] # pwd

/ usr/local/nginx/html/baidu

[root@localhost baidu] # cat 2.php

Test database and PHP connectivity

# vim / usr/local/nginx/html/baidu/test.php

[root@localhost html] # elinks-- dump192.168.1.36/test.php

Congratulations, it's done!

Those who inquire on the Internet have not been tested.

The mysql_connect module will be deprecated in the future, please use mysqli or PDO instead.

Solution 1:

Prohibit PHP from reporting an error

Display_errors = On

Change to

Display_errors = Off

In view of the fact that this server is for users, sometimes they need to report errors and can't do this. Let them change the program. See solution 2.

Solution 2:

The commonly used php syntax connection MySQL is as follows

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report