网站LNMP环境安装配置 LinuxONE 2C4G S390x,Ubuntu 20.04测试通过 默认网站根目录/data/www,php默认监听9000端口,mariadb默认用户名root默认密码password
一、准备工作:
1、升级系统
1 sudo apt update;sudo apt dist-upgrade -y
2、清理原有安装
1 apt purge php* mariadb* nginx* http* mysql* -y
二、服务器LNMP编译安装
1、安装编译工具
1 apt install gcc cmake -y
2、安装Nginx
安装依赖
1 2 3 apt install zlib1g-dev libpcre3-dev libssl-dev -y mkdir -p /data/source cd /data/source
建立组和用户并设置不能ssh登录
1 useradd -U -r -M -s /bin/false www
下载
1 2 cd /data/source wget http://nginx.org/download/nginx-1.21.6.tar.gz
解压
1 tar xvf nginx-1.21.6.tar.gz
编译
1 2 3 4 cd nginx-1.21.6 ./configure --prefix=/data/nginx --user=www --group=www --with-http_ssl_module --with-http_v2_module --with-stream_realip_module --with-http_stub_status_module make -j5 make install
配置启动
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 cat > /lib/systemd/system/nginx.service << "EOF" [Unit] Description=The nginx HTTP and reverse proxy server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/run/nginx.pid ExecStartPre=/data/nginx/sbin/nginx -t -c /data/nginx/conf/nginx.conf ExecStart=/data/nginx/sbin/nginx -c /data/nginx/conf/nginx.conf ExecStartPost=/bin/sleep 0.1 ExecReload=/bin/kill -HUP $MAINPID ExecStop=/bin/kill -QUIT $MAINPID [Install] WantedBy=multi-user.target EOF
1 2 3 4 sed -i "s/\/\$nginx_version//" /data/nginx/conf/fastcgi* sed -i "s/}/ application\/vnd.android.package-archive apk;\n}/g" /data/nginx/conf/mime.types mv /data/nginx/conf/nginx.conf /data/nginx/conf/nginx.conf.bak mkdir /data/nginx/conf/conf.d
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 cat > /data/nginx/conf/nginx.conf << "EOF" user www; worker_processes 4; events { worker_connections 1024; use epoll; } http { include mime.types; default_type application/octet-stream; charset utf-8; sendfile on; client_max_body_size 40m; server_tokens off; keepalive_timeout 65; gzip on; include conf.d/*.conf; } EOF
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 cat > /data/nginx/conf/conf.d/www.conf << "EOF" server { listen 80; server_name localhost; root /data/www; index index.html index.htm index.php; error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location / { try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { try_files $uri = 404; fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; } } EOF
1 2 mkdir /data/www ln -sf /data/nginx/sbin/nginx /usr/local/bin/
打开防火墙
1 2 3 4 5 6 7 firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --reload iptables -P INPUT ACCEPT iptables -P FORWARD ACCEPT iptables -P OUTPUT ACCEPT iptables -F iptables-save
3、安装PHP
安装依赖
1 2 apt install libsystemd-dev libgd-dev libxml2-dev libcurl4-gnutls-dev -y ln -sf /usr/include/x86_64-linux-gnu/curl /usr/include/
下载
1 2 cd /data/source wget http://www.php.net/distributions/php-8.1.4.tar.xz
解压
1 tar xvf php-8.1.4.tar.xz
编译
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 cd php-8.1.4 ./configure --prefix=/data/php --enable-fpm --with-fpm-systemd --with-pear --with-fpm-user=www --with-fpm-group=www --with-config-file-path=/data/php --with-config-file-scan-dir=/data/php/lib/php/extensions --enable-opcache --enable-mbstring --with-gettext --with-curl --enable-mysqlnd --with-mysqli --with-pdo-mysql --disable-phpdbg --with-zlib --enable-calendar --enable-exif --enable-ftp --enable-soap --enable-bcmath --enable-sockets --with-openssl --enable-pcntl --enable-gd --with-jpeg --with-xpm --with-freetype make -j5 make install ln -sf /data/php/bin/* /usr/local/bin/ ln -sf /data/php/sbin/* /usr/local/bin/ cp sapi/fpm/php-fpm.service /lib/systemd/system/ sed -i "s/\${prefix}/\/data\/php/" /lib/systemd/system/php-fpm.service sed -i "s/\${exec_prefix}/\/data\/php/" /lib/systemd/system/php-fpm.service sed -i "s/\/data\/php\/var\/run/\/run/" /lib/systemd/system/php-fpm.service cp sapi/fpm/www.conf /data/php/etc/php-fpm.d/ cp sapi/fpm/php-fpm.conf /data/php/etc/ cp php.ini-production /data/php/php.ini sed -i "s/;zend_extension=opcache/zend_extension=opcache/" /data/php/php.ini sed -i "s/;opcache.enable=0/opcache.enable=1/" /data/php/php.ini sed -i "s/;opcache.enable=1/opcache.enable=1/" /data/php/php.ini sed -i "s/;opcache.enable_cli=0/opcache.enable_cli=1/" /data/php/php.ini sed -i "s/;opcache.file_cache=/opcache.file_cache=\/tmp/" /data/php/php.ini sed -i "s/max_execution_time = 30/max_execution_time = 60/" /data/php/php.ini sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 20M/" /data/php/php.ini sed -i "s/post_max_size = 8M/post_max_size = 20M/" /data/php/php.ini sed -i "s/;date.timezone =/date.timezone = Asia\/Shanghai/" /data/php/php.ini sed -i "s/;pcre.jit=1/pcre.jit=0/" /data/php/php.ini sed -i "s/display_errors = Off/display_errors = On/" /data/php/php.ini sed -i "s/expose_php = On/expose_php = Off/" /data/php/php.ini pear update-channels pear.php.net pear upgrade-all echo "opcache.jit=1235" >> /data/php/php.ini echo "opcache.jit_buffer_size=64M" >> /data/php/php.ini
4、安装MariaDB数据库
创建mysql用户
1 useradd -U -r -M -s /bin/false mysql
安装依赖
1 apt install libncurses5-dev libreadline-dev bison g++ -y
下载
1 wget http://mirrors.ustc.edu.cn/mariadb//mariadb-10.6.7/source/mariadb-10.6.7.tar.gz
解压
1 2 tar xvf mariadb-10.6.7.tar.gz cd mariadb-10.6.7
编译
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 cmake . \ -DCMAKE_INSTALL_PREFIX=/data/mariadb \ -DMYSQL_DATADIR=/data/mariadb/data \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_SYSTEMD=yes \ -DINSTALL_SYSTEMD_UNITDIR=/lib/systemd/system \ -DWITH_SSL=system \ -DCONNECT_WITH_MYSQL=1 \ -DWITH_DEBUG=no \ -DPLUGIN_TOKUDB=NO \ -DWITH_MARIABACKUP=OFF \ -DWITH_UNIT_TESTS=OFF \ -DWITH_UNITTEST=OFF \ -DINSTALL_MYSQLTESTDIR=''
1 2 3 4 5 6 7 8 9 10 make -j5 make install ln -sf /data/mariadb/bin/* /usr/local/bin/ chown mysql:mysql /data/mariadb/data -R cp support-files/my-huge.cnf /data/mariadb/my.cnf sed -i "s/\$MYSQLD_OPTS \$_WSREP_NEW_CLUSTER \$_WSREP_START_POSITION/--defaults-file=\/data\/mariadb\/my.cnf/" /lib/systemd/system/mariadb.service cd /data/mariadb scripts/mysql_install_db --user=mysql --defaults-file=/data/mariadb/my.cnf --datadir=/data/mariadb/data/ systemctl start mariadb /data/mariadb/bin/mysqladmin -u root password 'password'
1 2 3 4 5 # 更新或重新编译后: sed -i "s/\$MYSQLD_OPTS \$_WSREP_NEW_CLUSTER \$_WSREP_START_POSITION/--defaults-file=\/data\/mariadb\/my.cnf/" /lib/systemd/system/mariadb.service rm -rf /data/mariadb/data/test systemctl daemon-reload systemctl restart mariadb