ubuntu 編譯安裝LNMP+wordpress

1、編譯安裝LNMP,並安裝wordpress。php

(一)編譯安裝NGINX。html

一、下載nginx並解壓縮。mysql

root@ubuntu ~# wget http://nginx.org/download/nginx-1.18.0.tar.gz
root@ubuntu ~# tar -xf nginx-1.18.0.tar.gz

二、安裝依賴包。linux

root@ubuntu ~# apt install -y  gcc libgd-dev libgeoip-dev libpcre3 libpcre3-dev libssl-dev openssl

三、開始編譯安裝nginx。nginx

root@ubuntu ~# cd nginx-1.18.0/
root@ubuntu ~/nginx-1.18.0# ./configure --prefix=/apps/nginx --user=nginx  --group=nginx  --with-http_ssl_module
--with-http_v2_module  --with-http_realip_module  --with-http_stub_status_module  --with-http_gzip_static_module  
--with-pcre  --with-stream  --with-stream_ssl_module  --with-stream_realip_module
root@ubuntu ~/nginx-1.18.0# make -j 4
root@ubuntu ~/nginx-1.18.0# make install

四、建立nginx用戶和組,修改/apps/nginx目錄所屬用戶和所屬組。web

root@ubuntu ~/nginx-1.18.0# addgroup --gid 2000 nginx
Adding group `nginx' (GID 2000) ...
Done.
root@ubuntu ~/nginx-1.18.0# useradd -m -r -s /bin/bash -u 2000 -g 2000 nginx
root@ubuntu ~/nginx-1.18.0# chown nginx.nginx -R /apps/nginx/

五、修改nginx配置文件,http段改成下面內容。sql

root@ubuntu /lnmp# vim /apps/nginx/conf/nginx.conf
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   /apps/nginx/html;
            index  index.html index.htm index.php;
        }
        
        location ~ \.php$ {
                 root /apps/nginx/html;
                 fastcgi_pass 127.0.0.1:9000;
                 fastcgi_index index.php;
                 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                 include fastcgi_params;
}

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

六、nginx設爲服務並啓動。數據庫

root@ubuntu ~# vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx service
After=network.target

[Service]
Type=forking
ExecStart=/apps/nginx/sbin/nginx
ExecReload=/apps/nginx/sbin/nginx -s reload
ExecStop=/apps/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

root@ubuntu ~#systemctl enable --now nginx

七、訪問nginx頁面。ubuntu

root@ubuntu /apps/nginx/html# echo nginx > /apps/nginx/html/index.html
root@ubuntu /apps/nginx/html# curl 10.0.0.135
nginx

(二)編譯安裝php-fpm。vim

一、下載並解壓縮php軟件包。

root@ubuntu /lnmp# wget https://www.php.net/distributions/php-7.4.14.tar.xz
root@ubuntu /lnmp# tar -xf php-7.4.14.tar.xz

二、安裝依賴包。

root@ubuntu /lnmp# apt install -y libcurl4-openssl-dev libgd-dev libwebp-dev libpng++-dev libfreetype6-dev libghc-zlib-dev libmcrypt-dev libxml++2.6-dev libssl-dev libbz2-dev libtoos libsqlite3-dev libxslt-dev libonig-dev

三、編譯安裝php。

root@ubuntu /lnmp/php-7.4.14# ./configure --prefix=/apps/php --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx \
--with-pear --with-curl --with-png-dir --with-freetype-dir --with-iconv --with-mhash --with-zlib --with-xmlrpc --with-xsl \
--with-openssl --with-mysqli --with-pdo-mysql --disable-debug --enable-zip --enable-sockets --enable-soap --enable-inline-optimization \
--enable-xml --enable-ftp --enable-exif --enable-wddx --enable-bcmath --enable-calendar --enable-shmop --enable-dba --enable-sysvsem \
--enable-sysvshm --enable-sysvmsg --enable-mbstring

root@ubuntu /lnmp/php-7.4.14# make -j 4 && make install

四、修改php配置文件。

root@ubuntu ~# cd /apps/php/etc/php-fpm.d/
root@ubuntu /apps/php/etc/php-fpm.d# cp www.conf.default www.conf
root@ubuntu /apps/php/etc/php-fpm.d# cp /lnmp/php-7.4.14/php.ini-production /apps/php/etc/php.ini
root@ubuntu /apps/php/etc/php-fpm.d# mkdir /apps/php/log/
root@ubuntu /apps/php/etc/php-fpm.d# cd ..
root@ubuntu /apps/php/etc# cp php-fpm.conf.default php-fpm.conf

五、php設爲服務並啓動。

root@ubuntu ~# vim /lib/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/apps/php/sbin/php-fpm --nodaemonize  -c /apps/php/etc/php.ini
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID

[Install]
WantedBy=multi-user.target

root@ubuntu ~# systemctl enable --now php-fpm

六、建立php測試頁面,使用瀏覽器測試php頁可否顯示。

root@ubuntu /lnmp# vim /apps/nginx/html/1.php
<?php
        phpinfo();
?>

(三)編譯安裝mysql8.0.23。

一、安裝依賴包。

root@ubuntu /lnmp# apt install build-essential cmake bison libncurses5-dev libssl-dev pkg-config

二、下載mysql8.0.23,並解壓縮。

root@ubuntu:/lnmp# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.23.tar.gz
root@ubuntu:/lnmp# tar -xf mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz 
root@ubuntu:/lnmp# cd mysql-8.0.23-linux-glibc2.12-x86_64/

三、編譯安裝mysql。

root@ubuntu /lnmp# cmake -DCMAKE_INSTALL_PREFIX=/apps/mysql -DMYSQL_DATADIR=/data/mysql -DWITH_BOOST=boost -DFORCE_INSOURCE_BUILD=ON
root@ubuntu /lnmp# make -j 4
root@ubuntu /lnmp# make install

四、建立mysql帳號,設置所屬用戶和所屬組。

root@ubuntu /apps/mysql/bin# useradd mysql -s /sbin/nologin
root@ubuntu /apps/mysql/bin# mkdir -p /data/mysql /var/lib/mysql
root@ubuntu /apps/mysql/bin# chown -R mysql.mysql /data /var/lib/mysql /apps/mysql

五、添加PATH路徑。

root@ubuntu ~# echo 'PATH=/apps/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
root@ubuntu ~# . /etc/profile.d/mysql.sh

六、建立/etc/my.cnf配置文件。

root@ubuntu ~# vim /etc/my.cnf
[mysqld]
socket=/data/mysql/mysql.sock
user=mysql
symbolic-links=0
datadir=/data/mysql
innodb_file_per_table=1 max_connections=10000
[client]
port=3306
socket=/data/mysql/mysql.sock
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/tmp/mysql.sock

七、初始化數據庫。

root@ubuntu /apps/mysql/bin# /apps/mysql/bin/mysqld --defaults-file=/etc/my.cnf  --initialize --user=mysql --basedir=/apps/mysql --datadir=/data/mysql
#初始化完成後會生成root初始密碼,使用此密碼登陸數據庫後必須更改密碼才能使用數據庫。

八、啓動mysql服務。

root@ubuntu /apps/mysql/bin# cp /apps/mysql/support-files/mysql.server /etc/init.d/mysqld
root@ubuntu /apps/mysql/bin# chmod a+x /etc/init.d/mysqld
root@ubuntu /apps/mysql/bin# update-rc.d mysqld defaults 
root@ubuntu /apps/mysql/bin# systemctl start mysqld

九、使用初始密碼登陸,修改mysql的root帳號密碼。

root@ubuntu ~# mysql -uroot -p"fPnEVsniN7(i"
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.23 Source distribution

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> alter user 'root'@'localhost' identified by "123456";
Query OK, 0 rows affected (0.02 sec)

(四)安裝wordpress。

一、建立wordpress數據庫和帳號、密碼

root@ubuntu /lnmp# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.23 Source distribution

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.07 sec)

mysql> CREATE USER "wordpress"@"10.0.0.%" IDENTIFIED BY "123456";
Query OK, 0 rows affected (0.03 sec)

mysql> GRANT ALL PRIVILEGES ON wordpress.* TO "wordpress"@"10.0.0.%";
Query OK, 0 rows affected (0.02 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| wordpress          |
+--------------------+
5 rows in set (0.03 sec)

二、下載wordpress,解壓縮到/apps/nginx/html目錄,設置權限。

root@ubuntu /apps/nginx/html# tar -xf wordpress-5.6-zh_CN.tar.gz
root@ubuntu /apps/nginx/html# chown nginx.nginx -R /apps/nginx/html/wordpress

三、訪問wordpress頁面進行初始化。

2、配置虛擬主機,www.x.com域名實現首頁訪問,admin.x.com域名實現wordpress的後臺訪問。

一、本實驗在上例的基礎上完成。

二、修改windows的host文件,添加下面內容。

10.0.0.135 www.x.com
10.0.0.135 admin.x.com

三、修改nginx配置文件,在http段下添加虛擬主機配置,重啓nginx服務。

server {
        listen 80;
        server_name www.x.com;
        location / {
                root /apps/nginx/html/wordpress;

                index index.html index.php; }
        location ~ \.php$ {
                 root /apps/nginx/html/wordpress;
                 fastcgi_pass 127.0.0.1:9000;
                 fastcgi_index index.php;
                 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                 include fastcgi_params;
        }
}

server {
        listen 80;
        server_name admin.x.com;
        location / {
                root /apps/nginx/html/wordpress/wp-admin;

                index index.html index.php; }
        location ~ \.php$ {
                 root /apps/nginx/html/wordpress/wp-admin;
                 fastcgi_pass 127.0.0.1:9000;
                 fastcgi_index index.php;
                 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                 include fastcgi_params;
        }
}
root@ubuntu ~# systemctl restart nginx

四、使用域名訪問wordpress。
成功訪問後須要先登陸管理後臺 儀表盤——>設置——>常規——>WordPress地址(URL) 和 站點地址(URL)改成http://www.x.com,不然後續訪問地址會變成ip地址。

相關文章
相關標籤/搜索