nginxa安装
创建nginx用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin nginx
安装依赖包
[root@localhost ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++[root@localhost ~]# yum -y groups mark install 'Development Tools'
创建日志存放目录
[root@localhost ~]# mkdir -p /var/log/nginx
[root@localhost ~]# chown -R nginx.nginx /var/log/nginx下载安装nginx
[root@localhost ~]# wget https://nginx.org/download/nginx-1.22.1.tar.gz
[root@localhost ~]# tar xf nginx-1.22.1.tar.gz
[root@localhost ~]# cd nginx-1.22.1[root@localhost nginx-1.22.1]# ./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-debug \
> --with-http_ssl_module \
> --with-http_realip_module \
> --with-http_image_filter_module \
> --with-http_gunzip_module \
> --with-http_gzip_static_module \
> --with-http_stub_status_module \
> --http-log-path=/var/log/nginx/access.log \
> --error-log-path=/var/log/nginx/error.log[root@localhost nginx-1.22.1]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install
配置环境变量
[root@localhost nginx-1.22.1]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@localhost nginx-1.22.1]# . /etc/profile.d/nginx.sh编写service文件
[root@localhost ~]# cd /usr/lib/systemd/system
[root@localhost system]# cp sshd.service nginx.service
[root@localhost system]# vim nginx.service
[root@localhost system]# cat nginx.service
[Unit]
Description=OpenSSH server daemon
After=network.target[Service]
Type=forking
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
KillMode=process
Restart=on-failure
RestartSec=42s[Install]
WantedBy=multi-user.target开启服务
[root@localhost ~]# systemctl enable --now nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
安装mariadb
[root@localhost ~]# yum -y install mariadb*
[root@localhost ~]# systemctl enable --now mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 80 0.0.0.0:3306 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*[root@localhost ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.28-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> set password = password('chenxi123');
Query OK, 0 rows affected (0.000 sec)MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)MariaDB [(none)]> quit
Bye
php安装
安装依赖包
[root@localhost ~]# yum -y install libxml2-devel gcc-c++ openssl-devel sqlite-devel libcurl-devel readline-devel libpng-devel freetype-devel libzip-devel libjpeg-turbo-devel
[root@localhost ~]# yum -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
php下载和安装
[root@localhost ~]# wget https://www.php.net/distributions/php-8.2.10.tar.xz
[root@localhost ~]# tar xf php-8.2.10.tar.xz
[root@localhost ~]# cd php-8.2.10[root@localhost php-8.2.10]# ./configure --prefix=/usr/local/php8 \
> --with-config-file-path=/etc \
> --enable-fpm \
> --disable-debug \
> --disable-rpath \
> --enable-shared \
> --enable-soap \
> --with-openssl \
> --enable-bcmath \
> --with-iconv \
> --with-bz2 \
> --enable-calendar \
> --with-curl \
> --enable-exif \
> --enable-ftp \
> --enable-gd \
> --with-jpeg \
> --with-zlib-dir \
> --with-freetype \
> --with-gettext \
> --enable-mbstring \
> --enable-pdo \
> --with-mysqli=mysqlnd \
> --with-pdo-mysql=mysqlnd \
> --with-readline \
> --enable-shmop \
> --enable-simplexml \
> --enable-sockets \
> --with-zip \
> --enable-mysqlnd-compression-support \
> --with-pear \
> --enable-pcntl \
> --enable-posix[root@localhost php-8.2.10]# make -j $(cat /proc/cpuinfo |grep processor|wc -l)
[root@localhost php-8.2.10]# make install
设置环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php8.sh
[root@localhost ~]# cd php-8.2.10
[root@localhost php-8.2.10]# cp php.ini-production /etc/php.ini
[root@localhost php-8.2.10]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-8.2.10]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost php-8.2.10]# cp /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
[root@localhost php-8.2.10]# cp /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf编写service文件
[root@localhost php-8.2.10]# cat > /usr/lib/systemd/system/php-fpm.service <<EOF
> [Unit]
> Description=php-fpm server daemon
> After=network.target
>
> [Service]
> Type=forking
> ExecStart=/etc/init.d/php-fpm start
> ExecStop=/etc/init.d/php-fpm stop
> ExecReload=/bin/kill -HUP $MAINPID
>
> [Install]
> WantedBy=multi-user.target
> EOF配置php-fpm
[root@localhost php-8.2.10]# cat <<EOF >> /usr/local/php8/etc/php-fpm.conf
> pm.max_children = 50
> pm.start_servers = 5
> pm.min_spare_servers = 2
> pm.max_spare_servers = 8
> EOF启动服务
[root@localhost php-8.2.10]# systemctl daemon-reload
[root@localhost php-8.2.10]# systemctl enable --now php-fpm
Synchronizing state of php-fpm.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[root@localhost php-8.2.10]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 80 0.0.0.0:3306 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*编写php测试页面
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
[root@localhost ~]# cat /usr/local/nginx/conf/nginx.conflocation / {
root html;
index index.php(添加前面的) index.html index.htm;
}
}location ~ \.php$ { (取消几行注释)
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;
}[root@localhost ~]# vim /usr/local/nginx/html/index.php
[root@localhost ~]# cat /usr/local/nginx/html/index.php
<?php
phpinfo();
?>重启服务
[root@localhost ~]# systemctl restart nginx
关闭防火墙和selinux
[root@localhost ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config