LNMP
环境:
- 系统CentOS7.2 内核版本3.10.0
- yum源:aliyum源
- 软件版本
- nginx 1.61.1
- mysql 5.7.28
- php 72.30
下载
#nginx
wget -c http://nginx.org/download/nginx-1.16.1.tar.gz
#mysql
wget -c http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.28-el7-x86_64.tar.gz
#php
wget -c https://www.php.net/distributions/php-7.2.30.tar.gz
编译安装
- 安装nginx
tar -zxvf nginx-1.16.1.tar.gz -C /usr/local/src
cd /usr/local/src/nginx-1.16.1
#创建用户
useradd nginx -s /sbin/nologin
#安装依赖包
yum install pcre pcre-devel openssl-devel -y
#编译参数
./configure \
--prefix=/usr/local/nginx \
--conf-path=/etc/nginx/nginx.conf \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--http-log-path=/var/log/nginx/nginx_access.log
make
make install
#查看nginx版本号
./usr/local/nginx/sbin/nginx -v
#检查配置文件
./usr/local/nginx/sbin/nginx -t
#关闭防火墙SELINUX
systemctl stop firewalld&&setenforce 0
#启动
./usr/local/nginx/sbin/nginx
- 安装MySQL
#创建MySQL用户
groupadd mysql
useradd mysql -r -s /sbin/nologin -g mysql
tar -zxvf mysql-5.7.28-el7-x86_64.tar.gz -C /usr/local/
#创建软链接
ln -s /usr/local/mysql-5.7.28-el7-x86_64/ /usr/local/mysql
#创建mysql数据存储位置
mkdir /usr/local/mysql/data
chown -R mysql:mysql /usr/local/mysql/data
chmod -R 750 /usr/local/mysql/data
cd /usr/local/mysql/bin/
#初始化数据库
./mysqld --initialize --datadir=/usr/local/mysql/data --user=mysql
rm -rf /etc/my.cnf
#加入系统服务中
cp /usr/local/mysql/bin/mysqld /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld
#修改密码
/usr/local/mysql/bin/mysqladmin -uroot -p'000000' #提示输入初始密码
- 安装PHP
#创建用户
useradd php -r -s /sbin/nologion
tar -zxvf php-7.2.30.tar.gz -C /usr/local/src
#安装依赖包
yum install libxml2 libxml2-devel libpng libpng-devel -y
#预编译
cd /usr/local/src/php
./configure \
--prefix=/usr/local/php \
--enable-fpm \
--with-fpm-user=php \
--with-fpm-group=php \
--with-config-file-scan-dir=/etc/php7.d \
--with-gd \
--with-mysqli \
--with-mysql-sock=/tmp/mysql.sock \
--enable-pdo \
--with-pdo-mysql \
--enable-mbstring
#编译安装
make&&make install
#后续配置
#复制启动脚本
cd /usr/local/src/php-7.2.30/sapi/fpm/
cp init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
cp /usr/local/src/php-7.2.30/php.ini-production /usr/local/php/php.ini
sed -i 's/^;pid/pid/g' php-fpm.conf
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
service start php-fpm
修改nginx配置文件
vim /etc/nginx/nginx.conf +65
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#PHP信息打印测试界面
cat <<EOF >/usr/local/nginx/html/index.php
<?php
phpinfo();
?>
EOF
#重启nginx
/usr/local/nginx/sbin/nginx -s reload
查看进程运行状态
[root@localhost ~]#ps -aux |grep -E 'nginx|php-fpm|mysql'
root 43609 0.0 0.1 46044 1432 ? Ss 01:38 0:00 nginx: master process ./nginx
root 44364 0.0 0.0 115368 92 ? S 02:03 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
mysql 44451 0.1 1.0 1119336 10156 ? Sl 02:03 0:21 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
nginx 50953 0.0 0.1 46288 1920 ? S 04:18 0:00 nginx: worker process
root 53249 0.0 0.5 155516 5012 ? Ss 05:05 0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
php 53250 0.0 0.4 155516 4652 ? S 05:05 0:00 php-fpm: pool www
php 53251 0.0 0.4 155516 4652 ? S 05:05 0:00 php-fpm: pool www
查看端口开放状态
[root@localhost ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 80 :::3306 :::*
浏览器访问服务器地址:www.服务器IP地址/index.php显示出PHP信息即正常