部署lnmp
环境信息:
系统:CentOS 7.2
Nginx版本:nginx-1.13.11
PHP版本:php-7.2.3
Mysql版本:5.7
一、初始化系统
1、安装常用软件
yum -y install lftp bash-completion vim-enhanced
2、关闭防火墙,禁用SELinux
systemctl stop firewalld && systemctl disable firewalld
setenforce 0
sed -ri '/^SELINUX/c\SELINUX=disabled' /etc/selinux/config
二、安装nginx
1、安装依赖包
yum -y install gcc openssl-devel pcre-devel
2、下载源码包并安装
mkdir -p /tmp/src && cd /tmp/src
wget http://nginx.org/download/nginx-1.13.11.tar.gz -P /tmp/src/
tar xf nginx-1.13.11.tar.gz && cd nginx-1.13.11
./configure --with-http_ssl_module && make -j 2 && make install
3、启动并测试访问
/usr/local/nginx/sbin/nginx
ss -an |grep 80
curl 127.0.0.1
4、添加到开机启动
echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local
chmod a+x /etc/rc.d/rc.local
echo 'export PATH=$PATH:/usr/local/nginx/sbin' >>/etc/profile
source /etc/profile
三、安装PHP
1、安装依赖包
yum -y install bzip2 libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel libcurl libcurl-devel libxslt-devel openssl-devel
2、下载源码包并安装
wget http://cn2.php.net/distributions/php-7.2.3.tar.bz2 -P /tmp/src/
cd /tmp/src
tar -xvf php-7.2.3.tar.bz2
cd php-7.2.3
./configure \
--prefix=/usr/local/php \
--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-jpeg-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-mysql \
--with-mysqli \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-gd-native-ttf \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip
make -j 8 && make install
3、拷贝配置文件
1>php-fpm配置文件(影响php程序性能、最大连接数、进程数等)
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
2>php配置文件(影响php代码、客户端最大上传文件大小、php支持等扩张功能等,例如是否可以连接mysql等)
cp php.ini-production /usr/local/php/lib/php.ini
4、配置开机启动项
cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
chmod a+x /etc/rc.d/init.d/php-fpm
chkconfig php-fpm on
cd /usr/local/php/etc/php-fpm.d/
mv www.conf.default www.conf && cd
四、整合Nginx和PHP
1、修改nginx配置文件
vi /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.php index.html index.htm;
}
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;
}
2、重启Nginx和php-fpm
/usr/local/nginx/sbin/nginx -s reload
/etc/init.d/php-fpm restart
3、添加测试文件
echo "" >>/usr/local/nginx/html/php.php
4、通过浏览器访问ip/php.php
五、安装mysql
mysql版本:5.7
方法:yum
msyql工作目录:/var/lib/mysql
msyql配置文件:/etc/my.cnf
防火墙:关闭
1、关闭防火墙
1)关闭firewalld
systemctl stop firewalld
systemctl disable firewalld
2)关闭selinux
setenforce 0
sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
2、配置yum仓库
1) 下载yum仓库
wget http://developer1.bj.bcebos.com/mysql/yum/mysql57-community-release-el7-11.noarch.rpm
2) 添加yum仓库
yum -y install mysql57-community-release-el7-11.noarch.rpm
3) 查看yum仓库是否添加成功
yum repolist enabled | grep "mysql.*-community.*"
4) 选择一个发布系列、禁用mysql5.6,启用5.7(也可在mysql-community.repo配置)
yum repolist all | grep mysql
yum-config-manager --disable mysql56-community
yum-config-manager --enable mysql57-community
5) 验证子库是否可用
yum repolist enabled | grep mysql
3、安装mysql、启动、开机自启动
1)默认安装
yum -y install mysql-community-server
2)启动
systemctl start mysqld
3、开机自启
systemctl enable mysqld
4、修改密码(Baidu@123)
grep 'temporary password' /var/log/mysqld.log |awk '{print $NF}'>/root/mysqloldpassword.txt
mysqladmin -uroot -p"`cat /root/mysqloldpassword.txt`" password "Baidu@123"
5、测试
mysql -uroot -pBaidu@123 -e "show databases"
6、开通公网访问权限(根据实际需求确认是否开通)
mysql -uroot -pBaidu@123 -e "Grant all privileges on . to ‘root’@’%’ identified by ‘Baidu@123’ with grant option;
mysql -uroot -pBaidu@123 -e "flush privileges"
7、测试公网访问(IP为EIP的公网IP)(根据实际ip填写)
mysql -h106.12.9.xx -uroot -pBaidu@123
六、配置SSL
1、把申请的证书下载后放到/usr/local/nginx/ssl/
证书名称和私钥分别上:214248009920161.pem、214248009920161.key
2、配置nginx.conf文件(把HTTPS server的注释取消,配置证书位置、整合PHP)
# HTTPS server
server {
listen 443 ssl;
server_name localhost;
#ssl_certificate /etc/pki/tls/certs/server.crt;
#ssl_certificate_key /etc/pki/tls/certs/server.key;
ssl_certificate /usr/local/nginx/ssl/214248009920161.pem;
ssl_certificate_key /usr/local/nginx/ssl/214248009920161.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.php index.html index.htm;
}
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;
}
}
七、部署wordpress
1、在数据库中创建wp库名的数据库
mysql -pBaidu@123 -e "create database wp;"
2、下载wordpress的模板
wget https://cn.wordpress.org/wordpress-4.7.4-zh_CN.tar.gz -P /usr/local/nginx/html/
3、解压模板
cd /usr/local/nginx/html/ && tar -xf wordpress-4.7.4-zh_CN.tar.gz
mv /usr/local/nginx/html/wordpress/* /usr/local/nginx/html/
4、安装(数据库密码是在安装mysql时设置的)
1>在浏览器中访问自有ip地址或者域名
2>数据库名:wp
3>用户名:root
4>密码:Baidu@123
5>数据库主机:127.0.0.1
6>表前缀:默认就可以了