編譯LNMP+Wordpress部署
阿新 • • 發佈:2022-03-20
一.原始碼編譯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_
提交
進行安裝
站點標題