一、准备工作:
1、升级系统
dnf update -y
2、清理原有安装
dnf remove php* nginx* http* -y
二、测试服务器LNPP编译安装
1、安装编译工具
dnf install gcc gcc-c++ -y
加源
#EL-9 #dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm -y
安装
dnf install postgresql17-server postgresql17-devel
初始化数据库
/usr/pgsql-17/bin/postgresql-17-setup initdb
设置密码
echo "密码" | passwd --stdin postgres
数据库管理工具(PHP):
Adminer:https://www.adminer.org/
phppgadmin:https://www.github.com/ReimuHakurei/phpPgAdmin
2.2、编译安装PostgreSQL数据库
建立组和用户并设置密码
useradd -U -r -M -s /bin/nologin -d /usr/local/pgsql postgres echo "密码" | passwd --stdin postgres
安装依赖
dnf install pam-devel readline-devel libxslt-devel openssl-devel systemd-devel -y #postgresql-17 dnf install bison flex perl-lib -y
#ubuntu
apt install libreadline-dev zlib1g-dev libcrypto++-dev libssl-dev libpam0g-dev libxml2-dev libxslt1-dev libsystemd-dev gettext -y
下载
wget https://ftp.postgresql.org/pub/source/v17.2/postgresql-17.2.tar.bz2
解压
tar xvf postgresql-17.2.tar.bz2
编译
cd postgresql-17.2 ./configure --prefix=/usr/local/pgsql --with-system-tzdata=/usr/share/zoneinfo --disable-debug --enable-spinlocks --with-icu --without-gssapi --with-pam --without-perl --without-python --with-readline --with-openssl --with-systemd --without-tcl --with-libxml --with-libxslt --with-zlib --enable-nls='zh_CN' make -j5 make install
编译dblink插件
cd contrib/dblink make make install psql -U postgres postgres=# create extension dblink;
查看
postgres=# select * from pg_extension;
初始化数据库
mkdir /usr/local/pgsql/data chown postgres:postgres /usr/local/pgsql/data -R sudo -u postgres /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data -E 'UTF8' --locale='zh_CN.UTF-8'
配置文件
cat > /lib/systemd/system/pgsql.service << "EOF" [Unit] Description=PostgreSQL database server After=network.target [Service] Type=notify User=postgres Group=postgres Environment=PGPORT=5432 Environment=DATA_DIR=/usr/local/pgsql/data ExecStart=/usr/local/pgsql/bin/postgres -p ${PGPORT} -D ${DATA_DIR} ExecReload=/bin/kill -HUP $MAINPID KillMode=mixed KillSignal=SIGINT TimeoutSec=300 OOMScoreAdjust=-1000 [Install] WantedBy=multi-user.target EOF
开启日志
sed -i "s/#log_destination = 'stderr'/log_destination = 'csvlog'/g" /usr/local/pgsql/data/postgresql.conf sed -i "s/#logging_collector = off/logging_collector = on/g" /usr/local/pgsql/data/postgresql.conf sed -i "s/#log_directory =/log_directory =/g" /usr/local/pgsql/data/postgresql.conf sed -i "s/#log_filename =/log_filename =/g" /usr/local/pgsql/data/postgresql.conf sed -i "s/#log_rotation_age = 1d/log_rotation_age = 1d/g" /usr/local/pgsql/data/postgresql.conf sed -i "s/#log_rotation_size = 10MB/log_rotation_size = 100MB/g" /usr/local/pgsql/data/postgresql.conf sed -i "s/#log_min_messages = warning/log_min_messages = info/g" /usr/local/pgsql/data/postgresql.conf
如需开放对外访问,修改监听IP地址和允许访问IP设置
sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/g" /usr/local/pgsql/data/postgresql.conf echo "host all all 192.168.1.0/24 trust" >> /usr/local/pgsql/data/pg_hba.conf
注:允许192.168.1.1-255网段访问
默认连接数为100,如出现“已保留的连接位置为执行非复制请求的超级用户预留”,需要修改连接数
sed -i "s/max_connections = 100/max_connections = 200/" /usr/local/pgsql/data/postgresql.conf
启动数据库
systemctl start pgsql systemctl enable pgsql
安装依赖
dnf install pcre-devel zlib-devel -y
建立组和用户并设置不能ssh登录
useradd -U -r -M -s /bin/false www
下载
cd /data/source wget http://nginx.org/download/nginx-1.27.2.tar.gz
解压
tar xvf nginx-1.27.2.tar.gz
编译
cd nginx-1.27.2 ./configure --prefix=/usr/local/nginx --user=www --group=www --pid-path=/run/nginx.pid --lock-path=/run/nginx.lock --http-client-body-temp-path=/tmp/client --http-proxy-temp-path=/tmp/proxy --http-fastcgi-temp-path=/tmp/fastcgi --http-uwsgi-temp-path=/tmp/uwsgi --http-scgi-temp-path=/tmp/scgi --http-log-path=/usr/local/nginx/log/access.log --error-log-path=/usr/local/nginx/log/error.log --with-http_ssl_module --with-http_v2_module --with-http_v3_module --with-http_stub_status_module --with-http_realip_module --with-stream_ssl_module --with-stream_realip_module make -j5 make install
配置启动
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=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/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 sed -i "s/\/\$nginx_version//" /usr/local/nginx/conf/fastcgi* sed -i "s/}/ application\/vnd.android.package-archive apk;\n}/g" /usr/local/nginx/conf/mime.types mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak mkdir /usr/local/nginx/conf/conf.d cat > /usr/local/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 cat > /usr/local/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 mkdir /data/www ln -sf /usr/local/nginx/sbin/nginx /usr/local/bin/
打开防火墙
firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --reload
安装依赖
dnf install pcre-devel zlib-devel openssl-devel -y
建立组和用户并设置不能ssh登录
useradd -U -r -M -s /bin/false www
下载
cd /data/source wget https://openresty.org/download/openresty-1.27.1.1.tar.gz
解压
tar xvf openresty-1.27.1.1.tar.gz
编译
cd openresty-1.27.1.1 ./configure --prefix=/usr/local/openresty --user=www --group=www --pid-path=/run/nginx.pid --lock-path=/run/nginx.lock --http-client-body-temp-path=/tmp/client --http-proxy-temp-path=/tmp/proxy --http-fastcgi-temp-path=/tmp/fastcgi --http-uwsgi-temp-path=/tmp/uwsgi --http-scgi-temp-path=/tmp/scgi --with-http_v2_module --with-http_v3_module --with-http_realip_module --with-http_stub_status_module --with-stream_realip_module --with-http_postgres_module --with-pg_config=/usr/local/pgsql/bin/pg_config --sbin-path=/usr/local/openresty/sbin/nginx --conf-path=/usr/local/openresty/conf/nginx.conf make -j5 make install
配置启动
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=/usr/local/openresty/sbin/nginx -t -c /usr/local/openresty/conf/nginx.conf ExecStart=/usr/local/openresty/sbin/nginx -c /usr/local/openresty/conf/nginx.conf ExecStartPost=/bin/sleep 0.1 ExecReload=/bin/kill -HUP $MAINPID ExecStop=/bin/kill -QUIT $MAINPID [Install] WantedBy=multi-user.target EOF sed -i "s/\/\$nginx_version//" /usr/local/openresty/conf/fastcgi* mv /usr/local/openresty/conf/nginx.conf /usr/local/openresty/conf/nginx.conf.bak mkdir /usr/local/openresty/conf/conf.d cat > /usr/local/openresty/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 cat > /usr/local/openresty/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 mkdir /data/www ln -sf /usr/local/openresty/sbin/nginx /usr/local/bin/
打开防火墙
firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --reload
4.1、dnf安装PHP-8
dnf install yum-utils dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm dnf-config-manager --enable remi-php82 dnf install php-fpm php-opcache php-gd php-pg php-cli php-mbstring php-xml php-pecl-zip php-intl php-ldap php-smbclient php-imap php-exif php-gmp php-redis php-imagick systemctl enable php-fpm systemctl start php-fpm
4.2、编译安装PHP
安装依赖
dnf install autoconf libxml2-devel gd-devel libcurl-devel openldap-devel libpng-devel libjpeg-devel libXpm-devel freetype-devel oniguruma-devel libwebp-devel libsq3-devel libzip-devel -y #ubuntu #apt install pkg-config libcurl4-gnutls-dev libpng-dev libwebp-dev libjpeg-dev libxpm-dev libfreetype6-dev libonig-dev libzip-dev libsqlite3-dev
下载
cd /data/source wget http://www.php.net/distributions/php-8.4.1.tar.xz
解压
tar xvf php-8.4.1.tar.xz
编译
cd php-8.4.1 ./configure --prefix=/usr/local/php --enable-fpm --with-fpm-systemd --with-pear --with-fpm-user=www --with-fpm-group=www --with-config-file-path=/usr/local/php --with-config-file-scan-dir=/usr/local/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 --with-pgsql --with-pdo-pgsql --with-zip --enable-gd --with-webp --with-jpeg --with-xpm --with-freetype #有ldap参数时:--with-ldap --with-ldap-sasl #ln -sf /usr/lib64/libldap* /usr/lib/ #ln -sf /usr/lib64/liblber* /usr/lib/ make -j5 make install ln -sf /usr/local/php/bin/* /usr/local/bin/ ln -sf /usr/local/php/sbin/* /usr/local/bin/ cp sapi/fpm/php-fpm.service /lib/systemd/system/ cp php.ini-production /usr/local/php/php.ini cp sapi/fpm/www.conf /usr/local/php/etc/php-fpm.d/ cp sapi/fpm/php-fpm.conf /usr/local/php/etc/ sed -i "s/;zend_extension=opcache/zend_extension=opcache/" /usr/local/php/php.ini sed -i "s/;opcache.enable=0/opcache.enable=1/" /usr/local/php/php.ini sed -i "s/;opcache.enable=1/opcache.enable=1/" /usr/local/php/php.ini sed -i "s/;opcache.enable_cli=0/opcache.enable_cli=1/" /usr/local/php/php.ini sed -i "s/;opcache.file_cache=/opcache.file_cache=\/tmp/" /usr/local/php/php.ini sed -i "s/max_execution_time = 30/max_execution_time = 60/" /usr/local/php/php.ini sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 20M/" /usr/local/php/php.ini sed -i "s/post_max_size = 8M/post_max_size = 20M/" /usr/local/php/php.ini sed -i "s/;date.timezone =/date.timezone = Asia\/Shanghai/" /usr/local/php/php.ini sed -i "s/;pcre.jit=1/pcre.jit=0/" /usr/local/php/php.ini sed -i "s/display_errors = Off/display_errors = On/" /usr/local/php/php.ini sed -i "s/expose_php = On/expose_php = Off/" /usr/local/php/php.ini pear update-channels pear.php.net pear upgrade-all #php8增加jit参数 echo "opcache.jit=1235" >> /usr/local/php/php.ini echo "opcache.jit_buffer_size=64M" >> /usr/local/php/php.ini #查看是否生效 php -i|grep -i jit #pecl安装php模块(最简单的方法) pecl install memcached redis lzf imagick echo "extension=memcached" >> /usr/local/php/lib/php/extensions/ext.ini echo "extension=lzf" >> /usr/local/php/lib/php/extensions/ext.ini echo "extension=redis" >> /usr/local/php/lib/php/extensions/ext.ini echo "extension=imagick" >> /usr/local/php/lib/php/extensions/ext.ini#编译安装ImageMagick
wget https://imagemagick.org/download/ImageMagick-6.9.13-17.tar.xz tar xvf ImageMagick-6.9.13-17.tar.xz cd ImageMagick-6.9.13-17 ./configure --disable-openmp --disable-hdri --with-quantum-depth=8 make -j5 make install
#yum安装memcached,并设置开机运行
yum install memcached -y systemctl start memcached systemctl enable memcached#编译安装memcached
wget https://www.memcached.org/files/memcached-1.6.32.tar.gz tar xvf memcached-1.6.32.tar.gz cd memcached-1.6.32 ./configure --prefix=/usr/local/memcached make -j5 make install cat > /lib/systemd/system/memcached.service << "EOF" [Unit] Description=Memcached Before=nginx.service After=network.target [Service] Type=simple ExecStart=/usr/local/memcached/bin/memcached -u root -p 11211 -m 64 -c 1024 [Install] WantedBy=multi-user.target EOF systemctl start memcached systemctl enable memcached
© 2016-2024 清风的个人笔记