LNMP build in linux

1. Install nginx

[root@nginx ~]# yum -y install pcre-devel zlib-devel openssl-devel
[root@nginx ~]# useradd -M -s /sbin/nologin nginx
[root@nginx ~]# tail -1 /etc/passwd;tail -1 /etc/group
[root@nginx ~]# cd tools/
[root@nginx tools]# tar xf nginx-1.6.0.tar.gz -C /usr/src/
[root@nginx tools]# cd /usr/src/nginx-1.6.0/
[root@nginx nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-file-aio  --with-http_mp4_module --with-http_ssl_module && make && make install

vim /etc/profile

Add two lines

PATH=$PATH:/usr/local/nginx/sbin
export PATH

Execute script

source /etc/profile

[root@nginx ~]# nginx -t 
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@nginx ~]# nginx 
[root@nginx ~]# ss -atp|grep nginx
LISTEN     0      128        *:http                     *:*                     users:(("nginx",pid=4596,fd=6),("nginx",pid=4595,fd=6))

[root@nginx ~]# curl -I http://192.168.2.14
HTTP/1.1 200 OK
Server: nginx/1.6.0
Date: Tue, 07 Aug 2018 21:02:28 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 07 Aug 2018 10:38:12 GMT
Connection: keep-alive
ETag: "5b697694-264"
Accept-Ranges: bytes

2. Deploy the database

[root@nginx ~]# yum -y install ncurses-devel
[root@nginx ~]# cd tools/
[root@nginx tools]# tar xf cmake-2.8.6.tar.gz -C /usr/src/
[root@nginx tools]# cd /usr/src/cmake-2.8.6/
[root@nginx cmake-2.8.6]# ./configure && gmake &&gmake install
[root@nginx cmake-2.8.6]# echo $?
0
[root@nginx cmake-2.8.6]# cd /root/tools/
[root@nginx tools]# tar xf mysql-5.5.22.tar.gz -C /usr/src/
[root@nginx tools]# cd /usr/src/mysql-5.5.22/
[root@nginx mysql-5.5.22]#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc && make && make install
[root@nginx mysql-5.5.22]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@nginx mysql-5.5.22]# . /etc/profile
[root@nginx mysql-5.5.22]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin
[root@nginx ~]# /bin/cp -p /usr/src/mysql-5.5.22/support-files/my-medium.cnf /etc/my.cnf
[root@nginx ~]# /bin/cp -p /usr/src/mysql-5.5.22/support-files/mysql.server /etc/init.d/mysqld
[root@nginx ~]# chmod +x /etc/init.d/mysqld 
[root@nginx ~]# chkconfig --add mysqld
[root@nginx ~]# chkconfig mysqld on
[root@nginx ~]# useradd -M -s /sbin/nologin mysql
[root@nginx ~]# chown -R mysql:mysql /usr/local/mysql/
[root@nginx ~]# /usr/local/mysql/scripts/mysql_install_db  --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql
[root@nginx ~]# /etc/init.d/mysqld start
Starting MySQL... SUCCESS! 
[root@nginx ~]# netstat -anptu|grep 3306
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      2694/mysqld   
[root@nginx ~]# mysqladmin -uroot  password "123123" 

3. Deploy php

[root@nginx ~]# yum -y install gd libxml2-devel libjpeg-devel libpng-devel
[root@nginx ~]# cd tools/
[root@nginx tools]# tar xf php-5.3.28.tar.gz -C /usr/src/
[root@nginx tools]# cd /usr/src/php-5.3.28/
[root@nginx php-5.3.28]# ./configure  --prefix=/opt/php5  --with-gd  --with-zlib --with-mysql=/usr/local/mysql/  --with-config-file-path=/usr/local/php5  --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib && make && make install
[root@nginx php-5.3.28]# echo $?
0

Insert picture description here

[root@nginx php-5.3.28]# cp -p /usr/src/php-5.3.28/php.ini-development /opt/php5/php.ini

Insert picture description here

[root@nginx php-5.3.28]# ln -s /opt/php5/bin/* /usr/local/bin/
[root@nginx php-5.3.28]# ln -s /opt/php5/sbin/* /usr/local/sbin/
[root@nginx php-5.3.28]# cd /root/tools/

[root@nginx tools]# cd /opt/php5/etc/

Insert picture description here

[root@nginx etc]# cp -p php-fpm.conf.default php-fpm.conf
[root@nginx etc]# vim php-fpm.conf
25 pid = run/php-fpm.pid //指定 pid 文件位置
140 user = nginx //程序用户
141 group = nginx //程序组
217 pm.max_children = 50 //子进程的最大数
222 pm.start_servers = 20 //启动时开启的进程数
227 pm.min_spare_servers = 5 //最少空闲进程数
232 pm.max_spare_servers = 35 //最大空闲进程数

Start PHP:

[root@nginx etc]# php-fpm 
[root@nginx etc]# netstat -anput|grep php
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      99439/php-fpm: mast

Integration of LAMP services:

[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
46             index  index.php index.html index.htm;
60         location ~ \.php$ {
61                 root html;
62                 fastcgi_pass 127.0.0.1:9000;
63                 fastcgi_index index.php;
64                 include fastcgi.conf;
65         }
[root@nginx ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@nginx ~]# nginx -s reload
root@nginx ~]# vim /usr/local/nginx/html/test.php
[root@nginx ~]# cat /usr/local/nginx/html/test.php
<?php
$link=mysql_connect('localhost','root','123123');
if($link) echo "<h1>successful</h1>";
mysql_close();
?>

Configuration complete

Note: If there is nothing displayed on the parsed PHP page, modify the configuration file of fastcgi:

[root@nginx ~]# vim /usr/local/nginx/conf/fastcgi_params
[root@nginx ~]# tail -2 /usr/local/nginx/conf/fastcgi_params
fastcgi_param SCRIPT_FILENAME 	$document_root$fastcgi_script_name;
fastcgi_param PATH_INFO                $fastcgi_script_name;

After restarting nginx, the access is normal

[root@nginx ~]# curl http://192.168.2.14/test.php
<h1>successful</h1>

Guess you like

Origin blog.csdn.net/qq_39109226/article/details/110955114