编译LNMP+Wordpress部署
一.源码编译nginx
1.安装依赖包
yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre*
2.创建nginx运行用户
useradd -M -s /sbin/nologin nginx
3.解压pcre包
unzip pcre-8.42.zip -d /usr/local/src/ yum -y install unzip unzip pcre-8.42.zip -d /usr/local/src/
4.解压nginx源码包
tar zxf nginx-1.14.0.tar.gz -C /usr/local/src/ cd /usr/local/src/nginx-1.14.0/
5.编译安装
./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-http_ssl_module --user=nginx --group=nginx --with-pcre=/usr/local/src/pcre-8.42 make make install
6.修改配置文件
cd /usr/local/nginx/conf/ cp nginx.conf nginx.conf.bak vim nginx.conf user nginx nginx; #修改用户和组 location ~ .*\.(php|php5)?$ { 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; } 测试配置文件修改是否有错误 /usr/local/nginx/sbin/nginx -t
7.编辑profile文件,添加环境变量
vim /etc/profile export PATH=$PATH:/usr/local/nginx/sbin #根据自己安装目录进行调整 加载变量立即生效 source /etc/profile
8.配置启动脚本
vim /etc/init.d/nginx #! /bin/bash #chkconfig: 2345 80 90 #description:nginx run # nginx启动脚本 # @author Devil # @version 0.0.1 # @date 2017-08-12 PATH=/usr/local/nginx DESC="nginx1" NAME=nginx DAEMON=$PATH/sbin/$NAME CONFIGFILE=$PATH/conf/$NAME.conf PIDFILE=$PATH/logs/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME set -e [ -x "$DAEMON" ] || exit 0 do_start() { $DAEMON -c $CONFIGFILE || echo -n "nginx already running" } do_stop() { $DAEMON -s stop || echo -n "nginx not running" } do_reload() { $DAEMON -s reload || echo -n "nginx can't reload" } case "$1" in start) echo -n "Starting $DESC: $NAME" do_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" do_stop echo "." ;; reload|graceful) echo -n "Reloading $DESC configuration..." do_reload echo "." ;; restart) echo -n "Restarting $DESC: $NAME" do_stop do_start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2 exit 3 ;; esac exit 0 添加执行权限 chmod +x /etc/init.d/nginx 设置开机自启动 chkconfig --add nginx chkconfig nginx on
二.源码编译安装mysql
1.卸载系统自带mariadb*
yum -y remove mariadb* boost-*
2.安装依赖包
yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-devel
3.解压源码包
tar zxf mysql-boost-5.7.20.tar.gz -C /usr/local/src/
4.配置编译并安装
cd /usr/local/src/mysql-5.7.20/ cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/src/mysql-5.7.20/boost/boost_1_59_0 -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_USER=mysql make make install
5.创建数据库用户
useradd -M -s /sbin/nologin -r mysql
6.创建所需目录
mkdir -p /usr/local/mysql/data #数据存储目录 mkdir -p /usr/local/mysql/log #日志目录 chown -R mysql.mysql /usr/local/mysql/ #更改属主属组为mysql
7.配置my.cnf文件(以下是简单配置)
vim /etc/my.cnf [client] socket=/usr/local/mysql/mysql.sock [mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data port=3306 socket=/usr/local/mysql/mysql.sock symbolic-links=0 character-set-server=utf8 pid-file=/usr/local/mysql/mysqld.pid log-error=/usr/local/mysql/log/mysqld.log
8.配置mysql启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld vim /etc/init.d/mysqld basedir=/usr/local/mysql datadir=/usr/local/mysql/data
9.配置环境变量
vim /etc/profile 路径根据自己安装的目录进行更改 export PATH=$PATH:/usr/local/mysql/bin 加载变量立刻生效 source /etc/profile
10.设置开机自启动
chkconfig --add mysqld
chkconfig mysqld on
11.安全初始化数据库 --这样初始化之后,数据库是没有密码的。如果想初始化之后分配临时密码,可以将-insecure去掉,初始化之后,可以分配到一个临时密码。
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 启动数据库 /etc/init.d/mysqld start 进入数据库更改数据库密码 mysql -u root alter user 'root'@'localhost' identified by 'XXXXXX'; flush privileges;
三.源码编译安装PHP
1.安装依赖包
yum -y install php-mcrypt libmcrypt libmcrypt-devel autoconf freetype gd libmcrypt libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel re2c net-snmp-devel libjpeg-devel php-ldap openldap-devel openldap-servers openldap-clients freetype-devel gmp-devel
2.解压压缩包
tar zxf php-7.2.6.tar.gz -C /usr/local/src/ cd /usr/local/src/php-7.2.6/
3.编译安装-->--with-ldap --with-ldap-sasl如果不添加这两项,要是安装zabbix监控的时候,会有提示还得需要再次编译,如果不安装zabbix也可以忽略。
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysqli --with-pdo-mysql --with-mysql-sock=/usr/local/mysql/mysql.sock --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-curl --with-gd --with-gmp --with-zlib --with-xmlrpc --with-openssl --without-pear --with-snmp --with-gettext --with-mhash --with-libxml-dir=/usr --with-ldap --with-ldap-sasl --with-fpm-user=nginx --with-fpm-group=nginx --enable-xml --enable-fpm --enable-ftp --enable-bcmath --enable-soap --enable-shmop --enable-sysvsem --enable-sockets --enable-inline-optimization --enable-maintainer-zts --enable-mbregex --enable-mbstring --enable-pcntl --enable-zip --disable-fileinfo --disable-rpath --enable-libxml --enable-opcache --enable-mysqlnd 出现报错error: configure: error: Cannot find ldap libraries in /usr/lib 解决方案: cp -frp /usr/lib64/libldap* /usr/lib/ 编译安装 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysqli --with-pdo-mysql --with-mysql-sock=/usr/local/mysql/mysql.sock --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-curl --with-gd --with-gmp --with-zlib --with-xmlrpc --with-openssl --without-pear --with-snmp --with-gettext --with-mhash --with-libxml-dir=/usr --with-ldap --with-ldap-sasl --with-fpm-user=nginx --with-fpm-group=nginx --enable-xml --enable-fpm --enable-ftp --enable-bcmath --enable-soap --enable-shmop --enable-sysvsem --enable-sockets --enable-inline-optimization --enable-maintainer-zts --enable-mbregex --enable-mbstring --enable-pcntl --enable-zip --disable-fileinfo --disable-rpath --enable-libxml --enable-opcache --enable-mysqlnd make make报错: /usr/bin/ld: ext/ldap/.libs/ldap.o: undefined reference to symbol 'ber_strdup' /usr/lib64/liblber-2.4.so.2: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status 解决方案: vim Makefile EXTRA_LIBS = -lcrypt -lz -lresolv -lcrypt -lrt -lldap -lgmp -lpng -lz -ljpeg -lz -lrt -lm -ldl -lnsl -lpthread -lxml2 -lz -lm -ldl -lssl -lcryp to -lcurl -lxml2 -lz -lm -ldl -lssl -lcrypto -lfreetype -lxml2 -lz -lm -ldl -lnetsnmp -lssl -lssl -lcrypto -lm -lxml2 -lz -lm -ldl -lcrypt -lxm l2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lssl -lcrypto -lcrypt -llber 在结尾添加-llber make make install
4.配置php配置文件
移动php配置文件的位置,并修改名称 cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.conf 复制php.ini文件 cp /usr/local/src/php-7.2.6/php.ini-production /usr/local/php/etc/php.ini
5.启动脚本
复制php启动脚本到/etc/init.d/ cp /usr/local/src/php-7.2.6/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm 添加执行权限,添加到启动项并设置开机启动 chmod +x /etc/init.d/php-fpm chkconfig --add php-fpm chkconfig php-fpm on 启动php-fpm /etc/init.d/php-fpm start
6.修改nginx配置文件支持php页面
vim /usr/local/nginx/conf/nginx.conf location / { root html; index index.php index.html index.htm; #再该行增加index.php } 修改完配置文件重启nginx服务 /etc/init.d/nginx restart
7.编写php测试页
vim /usr/local/nginx/html/index.php <?php phpinfo(); ?>
8.访问测试
浏览器访问ip地址出现页面
四.博客程序搭建
1.数据库创建wordpress并授权
mysql -uroot -pXXXXXX create database wordpress; show databases like 'wordpress'; grant all on wordpress.* to wordpress@'localhost' identified by 'XXXXXX'; flush privileges; show grants for wordpress@'localhost'; select user,host from mysql.user; quit;
2.nginx及php环境配置
cd /usr/local/nginx/conf/ vim nginx.conf user nginx nginx; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; server_tokens off; sendfile on; keepalive_timeout 65; #server { # listen 80 default_server; # listen [::]:80 default_server; # server_name _; # return 444; #} server { listen 80; server_name blog.wordpress.com; if ( $host != 'blog.wordpress.com' ) { return 403; } location / { root html/blogcom; index index.html index.htm index.php; if ( -f $request_filename/index.html ) { rewrite (.*) $1/index.html break; } if ( -f $request_filename/index.php ) { rewrite (.*) $1/index.php; } if ( !-f $request_filename ) { rewrite (.*) /index.php; } } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ .*\.(php|php5)?$ { root html/blogcom; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } } 重启服务 /etc/init.d/nginx restart
3.创建博客目录
cd /usr/local/nginx/html/ mkdir blogcom cd /usr/local/nginx/html/blogcom/ 获取wordpress博客程序,并放置到/usr/local/nginx/html/blogcom/ tar xf wordpress-5.4.2-zh_CN.tar.gz mv wordpress-5.4.2-zh_CN.tar.gz /root/ mv wordpress/* . 修改属主属组 chown -R nginx.nginx /usr/local/nginx/html/blogcom/
4.开始安装博客程序,浏览器访问域名
数据库名:wordpress
用户名:wordpress
密码:
数据库主机:localhost
表前缀: ol_
提交
进行安装
站点标题
零星的变得优秀,也能拼凑出星河。
欢迎任何形式的转载,但请务必注明出处。
限于本人水平,如果文章和代码有表述不当之处,还请不吝赐教。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?