1,环境搭建准备
安装包 |
版本 |
|
MySQL |
mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz |
|
PHP |
php-5.6.30.tar.gz |
|
Nginx |
nginx-1.17.8.tar.gz |
2,安装MySQL及配置
//上传安装包
//移动到目录下
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# ls
mysql-5.6.47-linux-glibc2.12-x86_64
//安装常用工具
[root@localhost src]# yum install -y vim net_tools tree
[root@lnmp src]# tar -zxf mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
# 移动
[root@lnmp src]# mv mysql-5.6.47-linux-glibc2.12-x86_64 /usr/local/mysql
# 创建MySQL用户,不要登录,启动的时候登录
[root@lnmp src]# useradd -s /sbin/nologin mysql
[root@lnmp src]# cd /usr/local/mysql/
# 创建存放数据目录;更改权限
[root@lnmp mysql]# mkdir -p /data/mysql
[root@lnmp mysql]# chown -R mysql:mysql /data/mysql/
[root@lnmp mysql]# cd /data/mysql/
[root@lnmp mysql]# ls -la
total 2
drwxr-xr-x. 5 mysql mysql 104 Aug 9 18:10 .
drwxr-xr-x. 3 root root 18 Aug 9 18:05 ..
[root@lnmp mysql]# cd /usr/local/mysql/
# 安装所需要依赖
[root@lnmp mysql]# yum install -y perl-Module-Install
# 初始化,上面有两个ok确定安装成功
[root@lnmp mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/
配置MySQL文件
//复制更改配置文件
[root@lnmp mysql]# cp support-files/my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
[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. 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 0.0.0.0:22 0.0.0.0:* LISTEN 1462/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2605/master
tcp6 0 0 :::3306 :::* LISTEN 7891/mysqld
tcp6 0 0 :::22 :::* LISTEN 1462/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2605/master
3,安装PHP及配置
//移动
[root@lnmp src]# cd /usr/local/src/
[root@lnmp src]# ls
mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz php-5.6.30.tar.gz
//安装依赖
[root@lnmp src]# 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
//解压PHP
[root@lnmp src]# tar -zxf php-5.6.30.tar.gz
//移动
[root@lnmp src]# cd php-5.6.30
//编译
[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
//如果发生这样错:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
#yum install -y epel-release
#yum install -y libmcrypt-devel
两个不能一起安装,因为CentOs6默认的yum源没有 libmcrypt-devel这个包,只能借助epel的yum源,所以先安装epel,再安装libmcrypt。
//安装
[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
[09-Aug-2021 21:21:15] 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
//启动PHP-fpm
[root@lnmp php-5.6.30]# chkconfig php-fpm on
//查看端口
[root@lnmp php-5.6.30]# ps aux |grep php-fpm
root 6970 0.0 0.2 128280 5076 ? Ss 22:11 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm 6971 0.0 0.2 128280 4812 ? S 22:11 0:00 php-fpm: pool www
php-fpm 6972 0.0 0.2 128280 4812 ? S 22:11 0:00 php-fpm: pool www
php-fpm 6973 0.0 0.2 128280 4812 ? S 22:11 0:00 php-fpm: pool www
php-fpm 6974 0.0 0.2 128280 4812 ? S 22:11 0:00 php-fpm: pool www
php-fpm 6975 0.0 0.2 128280 4816 ? S 22:11 0:00 php-fpm: pool www
php-fpm 6976 0.0 0.2 128280 4820 ? S 22:11 0:00 php-fpm: pool www
php-fpm 6977 0.0 0.2 128280 4820 ? S 22:11 0:00 php-fpm: pool www
php-fpm 6978 0.0 0.2 128280 4820 ? S 22:11 0:00 php-fpm: pool www
php-fpm 6979 0.0 0.2 128280 4820 ? S 22:11 0:00 php-fpm: pool www
php-fpm 6980 0.0 0.2 128280 4820 ? S 22:11 0:00 php-fpm: pool www
php-fpm 6981 0.0 0.2 128280 4820 ? S 22:11 0:00 php-fpm: pool www
php-fpm 6982 0.0 0.2 128280 4820 ? S 22:11 0:00 php-fpm: pool www
php-fpm 6983 0.0 0.2 128280 4820 ? S 22:11 0:00 php-fpm: pool www
php-fpm 6984 0.0 0.2 128280 4820 ? S 22:11 0:00 php-fpm: pool www
php-fpm 6985 0.0 0.2 128280 4820 ? S 22:11 0:00 php-fpm: pool www
php-fpm 6986 0.0 0.2 128280 4820 ? S 22:11 0:00 php-fpm: pool www
php-fpm 6987 0.0 0.2 128280 4820 ? S 22:11 0:00 php-fpm: pool www
php-fpm 6988 0.0 0.2 128280 4820 ? S 22:11 0:00 php-fpm: pool www
php-fpm 6989 0.0 0.2 128280 4820 ? S 22:11 0:00 php-fpm: pool www
php-fpm 6990 0.0 0.2 128280 4820 ? S 22:11 0:00 php-fpm: pool www
root 7013 0.0 0.0 112828 980 pts/0 R+ 22:14 0:00 grep --color=auto php-fpm
4,安装Nginx及配置
//移动到目录下
[root@lnmp ~]# cd /usr/local/src/
[root@lnmp src]# ls
mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz php-5.6.30
nginx-1.17.8.tar.gz php-5.6.30.tar.gz
//je
[root@lnmp src]# tar zxf nginx-1.17.8.tar.gz
[root@lnmp src]# cd nginx-1.17.8
[root@lnmp nginx-1.17.8]# ./configure --prefix=/usr/local/nginx
//相比MySQL,PHP 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): [ OK ]
//查看Nginx端口
[root@ln[root@bai nginx-1.17.8]# ps aux |grep nginx
root 9638 0.0 0.0 20572 636 ? Ss 22:33 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody 9639 0.0 0.1 22968 3196 ? S 22:33 0:00 nginx: worker process
nobody 9640 0.0 0.1 22968 3196 ? S 22:33 0:00 nginx: worker process
root 9645 0.0 0.0 112828 976 pts/0 S+ 22:36 0:00 grep --color=auto nginx
mp nginx-1.17.8]# ps aux |grep 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 0.0.0.0:80 0.0.0.0:* LISTEN 9638/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1468/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1932/master
tcp6 0 0 :::3306 :::* LISTEN 10412/mysqld
tcp6 0 0 :::22 :::* LISTEN 1468/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1932/master
//检验
[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>
测试PHP能否解析
//测试能否正确解析PHP
[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]#
//测试成功。