编译安装nginx、php -- 搭建个人博客(LNMP)

一、部署环境说明

使用系统:CentOS 7.6

Linux 3.10.0-957.el7.x86_64 GNU/Linux

使用软件包版本说明

nginx :nginx-1.16.0
mysql  :mysql-5.7.26-linux-glibc2.12-x86_64
php  :php-7.3.6
libiconv :libiconv-1.16.tar

软件包官方下载地址

nginx :http://nginx.org
mysql :http://mysql.com
php  :http://php.net
libiconv :http://www.gnu.org/software/libiconv/

部署环境准备

第一个历程:查看selinux与firewall防火墙是否关闭

getenforce				
systemctl is-active firewall
systemctl is-enabled firewalld

第二个历程:关闭selinux与firewall防火墙(以关闭直接跳过此步)

sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/sysconfig/selinux
systemctl stop firewalld
systemctl disable firewalld

第三个历程:创建目录

mkdir -p /server/tools/ 
mkdir -p /application
mkdir -p /html/blog

第四个历程:将使用的软件包上传至/server/tools/

1.可以将软件包下载好在上传
2.可以使用wget命令直接在服务器上下载 (l列如:wget http://nginx.org/download/nginx-1.16.0.tar.gz)
PS:wget需要手动下载

第五个历程:配置repo源

curl -o  /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

第六个历程:安装相关依赖

yum -y install php-mcrypt libmcrypt-devel libxml2 libxml2-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libxslt libxslt-devel cyrus-sasl-plain cyrus-sasl cyrus-sasl-devel cyrus-sasl-lib m4 autoconf gcc gcc-c++ openssl openssl-devel pcre pcre-devel zlib zlib-devel wget net-tools zip unzip bzip2

一、编译安装nginx

第一个历程:创建用户

useradd -u 1025 -s /sbin/nologin -M nginx 

第二个历程:下载依赖包

yum install -y pcre pcre-devel		
yum install -y openssl openssl-devel

第三个历程:下载nginx软件包并解压

cd /server/tools
tar xf nginx-1.16.0.tar.gz 
cd nginx-1.16.0/

第四个历程:编译与安装

./configure \
--user=nginx \
--group=nginx \
--prefix=/application/nginx-1.16.0/ \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-pcre

make&&make install

第五个历程:创建软连接

ln -s /application/nginx-1.16.0/ /application/nginx

第六个历程:设置为systemctl管理

vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/application/nginx-1.16.0/logs/nginx.pid
ExecStartPre=/application/nginx-1.16.0/sbin/nginx -t -c /application/nginx-1.16.0/conf/nginx.conf
ExecStart=/application/nginx-1.16.0/sbin/nginx -c /application/nginx-1.16.0/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

第七个历程:生效、启动、开机自启

systemctl daemon-reload
systemctl start nginx
systemctl enable nginx

二、安装mysql

第一个历程:创建一个用户、创建目录

useradd -u1026 -s /sbin/nologin -M mysql

第二个历程:解压mysql安装包

cd /server/tools
tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz 
mv mysql-5.7.26-linux-glibc2.12-x86_64 /application/
 ln -s /application/mysql-5.7.26-linux-glibc2.12-x86_64/ /application/mysql

第三个历程:卸载mariadb(避免内部冲突)

[rpm -e --nodeps mariadb-libs

第四个历程:编写配置文件

[root@web02 application]# vim /etc/my.cnf
[mysqld]
basedir = /application/mysql/
datadir = /application/mysql/data
socket = /tmp/mysql.sock
server_id = 1
port = 3306
log_error = /application/mysql/data/bossx_mysql.err

[mysql]
socket = /tmp/mysql.sock
prompt = oldboy [\\d]>

第五个历程:初始化mysql并且设置为无密码

yum install libaio-devel -y
mkdir -p /application/mysql/data
chown -R mysql.mysql /application/mysql/
/application/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/application/mysql/ --datadir=/application/mysql/data

第六个历程:配置mysql启动服务

[root@web02 bin]# vim /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server by oldboy
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

第七个历程:设置环境变量

echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
 . /etc/profile

第八个历程:启动mysql服务

systemctl start mysqld
systemctl enable mysqld
systemctl status mysqld

九个历程:设置登录密码

 mysqladmin -u root password 'oldboy123'

第十个历程:重启mysql

systemctl restart mysqld

三、编译安装PHP

第一个历程:安装php扩展

yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel -y
yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y

第二个历程:上传并安装libiconv(字符集转换库使用)

cd /server/tools/

tar zxf libiconv-1.16.tar.gz

 cd libiconv-1.16

./configure --prefix=/application/libiconv

make && make install

第三个历程:安装相关依赖

yum install libmcrypt-devel -y 
yum install mhash -y
yum install mcrypt -y
yum install openssl openssl-devel -y

第四个历程:安装PHP

cd /server/tools/

tar xf php-7.3.6.tar.gz

cd php-7.3.6/

./configure \
--prefix=/application/php-7.3.6 \
--enable-mysqlnd  \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/application/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-gd \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp \
--enable-opcache=no

make && make install

第五个历程:生成配置文件

cp /application/php/etc/php-fpm.conf.default /application/php/etc/php-fpm.conf
cp /application/php/etc/php-fpm.d/www.conf.default /application/php/etc/php-fpm.d/www.conf

第六个历程:设置为systemctl管理

命令:vim /usr/lib/systemd/system/php-fpm.service(内容如下↓)

[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Servi\]ce]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/application/php/sbin/php-fpm --nodaemonize --fpm-config /application/php/etc
/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID

[Install]
WantedBy=multi-user.target

第七个历程:启动服务

systemctl start php-fpm
systemctl enable php-fpm
systemctl status php-fpm

四、搭建wordpress

第一个历程: 生成nginx.conf文件

cd /app/nginx/conf/
cp nginx.conf.default nginx.conf

第二个历程编写nginx.conf文件

命令:vim nginx.conf(清空内容)

user  nginx;
worker_processes  1;

pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  logs/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    
    server {
        listen       80;
        server_name  blog.bossx.com;
        
        location / {
              root   /html/blog;
              index  index.php index.html index.htm;
          }
          
        location ~ .*\.(php|php5)?$ {
              root /html/blog;
              fastcgi_pass  127.0.0.1:9000;
              fastcgi_index index.php;
              include fastcgi.conf;
          }
     }
}

第三个历程:查看nginx语法与重启

nginx -t
systemctl reload nginx

第四个历程:创建用户和数据库

mysql -uroot -poldboy123
#数据内操作,结尾必须有分号号
MariaDB [(none)]> creal database wordpress;
MariaDB [(none)]> show databases;
MariaDB [(none)]> grean all on wordpress.* to 'wordpress'@'10.0.0.%' identified by '123456';
MariaDB [(none)]> flush privileges;

10.0.0.% 填写为你的服务器IP或者为星号(*)
第五个历程:解压站点文件并移动到站点目录

cd  /server/tools
taf xf wordpress-5.2.1.tar
 mv wordpress/* /html/blog/

第六个历程:授予权限

chown nginx.nginx /html/blog/ -R
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值