LNMP部署

Mysql安装:

1.安装mysql

wget -c https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
yum install mysql-server -y


 2.设定mysql开机启动

systemctl enable mysqld.service
systemctl start mysqld.service
systemctl status mysqld.service


 3.修改密码

cat /var/log/mysqld.log |grep "A temporary password"   #获取默认密码

mysqladmin -u root -p password  #不登录mysql修改mysqlroot密码

 

 

 

 

 

Nginx安装:

 

1.安装必要的库文件

 

yum install gcc pcre-devel openssl-devel -y


 

2.下载Nginx源码包

 

cd /tmp/
wget -c http://nginx.org/download/nginx-1.12.2.tar.gz

3.安装Nginx

 

groupadd nginx
useradd nginx -g nginx -s /sbin/nologin -M
 
tar -zxf nginx-1.12.2.tar.gz 
cd nginx-1.12.2/
./configure --prefix=/usr/local/nginx-1.12.2/ --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module
 make && make install && echo $?
ln -s /usr/local/nginx-1.12.2/ /usr/local/nginx

 

4.创建nginx.service服务文件

 

vim /lib/systemd/system/nginx.service

nginx.service文件内容如下:

 

[Unit]
Description=nginx
After=network.target
 
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target


 

5.设置nginx开机自动启动:

 

systemctl enable nginx.service
systemctl start nginx.service
systemctl status nginx.service


 

 

 

安装php

 

1.安装依赖库:

 

yum install -y libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel


 

会提示没有软件包libmcryptlibmcrypt-devel,更新epel源地址:http://mirrors.aliyun.com/help/epel

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

yum install -y libmcrypt libmcrypt-devel

 

 

2.下载php

 

cd /tmp
wget http://cn2.php.net/distributions/php-7.2.3.tar.gz

3.编译安装php

cd /tmp
tar -zxf php-7.2.3.tar.gz 
cd php-7.2.3/
 
./configure --prefix=/usr/local/php-7.2.3 --disable-fileinfo --enable-fpm --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-openssl --with-zlib --with-curl --enable-ftp --with-gd --with-xmlrpc --with-jpeg-dir --with-png-dir --with-freetype-dir  --enable-mbstring  --enable-zip --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd  --without-pear  --enable-bcmath
 
make && make install && echo $?
 
ln -s /usr/local/php-7.2.3/ /usr/local/php


 

4.配置php-fpm运行账号

 

groupadd php-fpm-user

useradd -M -g php-fpm-user -s /sbin/nologin php-fpm-user

cp php.ini-development /etc/php.ini

cp /usr/local/php-7.2.3/etc/php-fpm.conf.default /usr/local/php-7.2.3/etc/php-fpm.conf

 

 cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

注意:cat /usr/local/php/etc/php-fpm.conf.default  查看最后一行

 

vim /usr/local/php/etc/php-fpm.d/www.conf

搜索“user”设置运行账号:

 

user=php-fpm-user

 

group=php-fpm-user

 

 

 6. 设置php-fpm为系统服务:

 

vim /etc/systemd/system/php-fpm.service

 

文件内容:

 

[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
PrivateTmp=True
[Install]
WantedBy=multi-user.target


 

7.php-fpm服务开机自动启动

 

systemctl enable php-fpm.service
systemctl start php-fpm.service
systemctl status php-fpm.service

 

 

 

8.配置nginx支持php

图片.png

猜你喜欢

转载自blog.51cto.com/hbgslz/2127867