上传包,解压

安装MySQL

  1. [root@lnmp ~]# tar -zxvf mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
  2. [root@lnmp ~]# cd /usr/local
  3. [root@lnmp local]# mv mysql-5.6.47-linux-glibc2.12-x86_64 mysql
  4. [root@lnmp local]# useradd -s /sbin/nologin mysql //创建MySQL用户,不可登录。启动需要
  5. [root@lnmp local]# cd /usr/local/mysql/
  6. [root@lnmp mysql]# mkdir -p /data/mysql //创建存放数据目录
  7. [root@lnmp mysql]# chown -R mysql:mysql /data/mysql/ //更改权限
  8. [root@lnmp mysql]# cd /data/mysql/
  9. [root@lnmp mysql]# ls -la
  10. 总用量 0
  11. drwxr-xr-x. 2 mysql mysql 6 9 6 09:31 .
  12. drwxr-xr-x. 3 root root 19 9 6 09:31 ..
  13. [root@lnmp mysql]# cd /data/mysql/
  14. [root@lnmp mysql]# yum install -y perl-Module-Install //安装依赖
  15. [root@lnmp mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/ //初始化,出现俩OK即成功

配置MySQL

[root@lnmp mysql]# cp -y support-files/my-default.cnf /etc/my.cnf
[root@lnmp mysql]#  vim /etc/my.cnf     //修改配置文件,以下
basedir =/usr/local/mysql
datadir =/data/mysql
port =3306
server_id =29
socket =/tmp/mysql.sock
# 配置启动脚本
[root@lnmp mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@lnmp mysql]# chmod 777 /etc/init.d/mysqld 
[root@lnmp mysql]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
[root@lnmp mysql]# chkconfig --add mysqld
[root@lnmp mysql]# chkconfig mysqld on
[root@lnmp mysql]# service mysqld start 
Starting MySQL.Logging to '/data/mysql/lnmp.err'.
 SUCCESS! 
# 小查一下
[root@lnmp mysql]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1090/master         
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      941/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1090/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      12138/mysqld        
tcp6       0      0 :::22                   :::*                    LISTEN      941/sshd

安装PHP

[root@lnmp ~]# tar -zxvf php-5.6.30.tar.gz -C /usr/local/src
[root@lnmp ~]# yum install -y gcc libxml2-devel openssl openssl-devel bzip2 bzip2-devel libpng libpng-devel freetype freetype-devel eplel-release libmcrypt-devel libcurl-devel  libjpeg-devel    //安装依赖
[root@lnmp php-5.6.30]# ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-pear --with-curl --with-openssl
#安装会出错,下
#yum install -y epel-release
#yum install -y libmcrypt-devel
#两个不能一起安装,因为CentOs6默认的yum源没有 libmcrypt-devel这个包,只能借助epel的yum源,所以先安装epel,再安装libmcrypt。
[root@lnmp php-5.6.30]# echo $?      //查看是否还有错
0
#再执行3
[root@lnmp php-5.6.30]# make && make install
[root@lnmp php-5.6.30]# echo $?
0

配置PHP

[root@lnmp php-5.6.30]# cp php.ini-production /usr/local/php-fpm/etc/php.ini   //复制配置文件
[root@lnmp php-5.6.30]# vim /usr/local/php-fpm/etc/php-fpm.conf                //编辑配置文件
[global]
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
[root@lnmp php-5.6.30]# useradd -s /sbin/nologin php-fpm
# 带有successful 表示成功
[root@lnmp php-5.6.30]# /usr/local/php-fpm/sbin/php-fpm -t
[06-Sep-2021 10:44:27] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
# 启动php-fpm
[root@lnmp php-5.6.30]# cp /usr/local/src/php-5.6.30/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@lnmp php-5.6.30]# chmod 755 /etc/init.d/php-fpm
[root@lnmp php-5.6.30]# service php-fpm start
Starting php-fpm  done
[root@lnmp php-5.6.30]# chkconfig php-fpm on
[root@lnmp php-5.6.30]# ps aux |grep php-fpm
root     127593  0.0  0.5 128200  5056 ?        Ss   10:46   0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm  127594  0.0  0.4 128200  4792 ?        S    10:46   0:00 php-fpm: pool www
php-fpm  127595  0.0  0.4 128200  4792 ?        S    10:46   0:00 php-fpm: pool www
php-fpm  127596  0.0  0.4 128200  4792 ?        S    10:46   0:00 php-fpm: pool www
php-fpm  127597  0.0  0.4 128200  4792 ?        S    10:46   0:00 php-fpm: pool www
php-fpm  127598  0.0  0.4 128200  4800 ?        S    10:46   0:00 php-fpm: pool www
php-fpm  127599  0.0  0.4 128200  4800 ?        S    10:46   0:00 php-fpm: pool www
php-fpm  127600  0.0  0.4 128200  4800 ?        S    10:46   0:00 php-fpm: pool www
php-fpm  127601  0.0  0.4 128200  4800 ?        S    10:46   0:00 php-fpm: pool www
php-fpm  127602  0.0  0.4 128200  4800 ?        S    10:46   0:00 php-fpm: pool www
php-fpm  127603  0.0  0.4 128200  4800 ?        S    10:46   0:00 php-fpm: pool www
php-fpm  127604  0.0  0.4 128200  4800 ?        S    10:46   0:00 php-fpm: pool www
php-fpm  127605  0.0  0.4 128200  4800 ?        S    10:46   0:00 php-fpm: pool www
php-fpm  127606  0.0  0.4 128200  4800 ?        S    10:46   0:00 php-fpm: pool www
php-fpm  127607  0.0  0.4 128200  4800 ?        S    10:46   0:00 php-fpm: pool www
php-fpm  127608  0.0  0.4 128200  4800 ?        S    10:46   0:00 php-fpm: pool www
php-fpm  127609  0.0  0.4 128200  4800 ?        S    10:46   0:00 php-fpm: pool www
php-fpm  127610  0.0  0.4 128200  4800 ?        S    10:46   0:00 php-fpm: pool www
php-fpm  127611  0.0  0.4 128200  4800 ?        S    10:46   0:00 php-fpm: pool www
php-fpm  127612  0.0  0.4 128200  4800 ?        S    10:46   0:00 php-fpm: pool www
php-fpm  127613  0.0  0.4 128200  4800 ?        S    10:46   0:00 php-fpm: pool www
root     127639  0.0  0.0 112824   984 pts/0    R+   10:47   0:00 grep --color=auto php-fpm

安装配置nginx

[root@lnmp ~]# tar -zxvf nginx-1.17.8.tar.gz -C /usr/local/src/
[root@lnmp ~]# cd /usr/local/src/nginx-1.17.8/
[root@lnmp nginx-1.17.8]# ./configure --prefix=/usr/local/nginx
[root@lnmp nginx-1.17.8]# make && make install
[root@lnmp nginx-1.17.8]# echo $?
0
[root@lnmp nginx-1.17.8]# vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start()
{
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop()
{
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL

reload()
{
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart()
{
stop
start
}
configtest()
{
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL


[root@lnmp nginx-1.17.8]# chmod 755 /etc/init.d/nginx
[root@lnmp nginx-1.17.8]# chkconfig --add nginx
[root@lnmp nginx-1.17.8]# chkconfig nginx on
[root@lnmp nginx-1.17.8]# > /usr/local/nginx/conf/nginx.conf
[root@lnmp nginx-1.17.8]# vim /usr/local/nginx/conf/nginx.conf
user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 6000;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
' $host "$request_uri" $status'
' "$http_referer" "$http_user_agent"';
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm
application/xml;
server
{
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /usr/local/nginx/html;
location ~ \.php$
{
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
}
}
}


[root@lnmp nginx-1.17.8]# /usr/local/nginx/sbin/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@lnmp nginx-1.17.8]# service nginx start 
Starting nginx (via systemctl):                            [  确定  ]
[root@lnmp nginx-1.17.8]# ps aux |grep nginx
root     130283  0.0  0.0  20568   636 ?        Ss   10:59   0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody   130284  0.0  0.3  22964  3192 ?        S    10:59   0:00 nginx: worker process
nobody   130285  0.0  0.3  22964  3192 ?        S    10:59   0:00 nginx: worker process
root     130287  0.0  0.0 112824   984 pts/0    R+   11:00   0:00 grep --color=auto nginx
[root@lnmp nginx-1.17.8]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1090/master         
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      130283/nginx: maste 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      941/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1090/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      12138/mysqld        
tcp6       0      0 :::22                   :::*                    LISTEN      941/sshd        
[root@lnmp nginx-1.17.8]# curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

image.png

# 测试
[root@lnmp nginx-1.17.8]# vim /usr/local/nginx/html/1.php
<?php
        echo "test php scripts"
?>
[root@lnmp nginx-1.17.8]# curl localhost/1.php
test php scripts[root@lnmp nginx-1.17.8]#

成功!!!