CentOS搭建WEB环境之 Nginx & PHP
1.升级centos系统软件
sudo yum -y upgrade
//yum -y upgrade:只升级所有包,不升级软件和系统内核,软件和内核保持原样。
2.安装最新nginx
RHEL and derivatives
sudo yum install yum-utils
To set up the yum repository, create the file named /etc/yum.repos.d/nginx.repo with the following contents:
vi /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
By default, the repository for stable nginx packages is used. If you would like to use mainline nginx packages, run the following command:
sudo yum-config-manager --enable nginx-mainline
To install nginx, run the following command:
sudo yum install nginx
nginx // 启动nginx服务
3.编译安装所需环境软件
sudo yum -y install gcc libxml2-devel sqlite-devel openssl-devel bzip2-devel libcurl-devel libffi-devel libpng-devel libwebp-devel libjpeg-devel
安装oniguruma pkgs.org/search/?q=o…
wget http://192.168.157.1/Share/oniguruma-6.9.6-1.el9.5.aarch64.rpm
sudo yum install ./oniguruma-6.9.6-1.el9.5.aarch64.rpm
wget http://192.168.157.1/Share/oniguruma-devel-6.9.6-1.el9.5.aarch64.rpm
sudo yum install ./oniguruma-devel-6.9.6-1.el9.5.aarch64.rpm
安装libzip pkgs.org/search/?q=l…
wget http://192.168.157.1/Share/libzip-1.7.3-7.el9.aarch64.rpm
sudo yum install ./libzip-1.7.3-7.el9.aarch64.rpm
wget http://192.168.157.1/Share/libzip-devel-1.7.3-7.el9.aarch64.rpm
sudo yum install ./libzip-devel-1.7.3-7.el9.aarch64.rpm
4.安装php
下载最新版php
wget https://www.php.net/distributions/php-8.2.5.tar.gz
wget http://192.168.157.1/Share/php-8.2.5.tar.gz //本地地址
tar -zxvf php-8.2.5.tar.gz
cd php-8.2.5
查看configure帮助
./configure --help
./configure --with-openssl --with-zlib --with-bz2 --with-curl --enable-bcmath --enable-gd --with-webp --with-jpeg --with-mhash --enable-mbstring --with-imap-ssl --with-mysqli --enable-exif --with-ffi --with-zip --enable-sockets --with-pcre-jit --enable-fpm --with-pdo-mysql --enable-pcntl
//配置选项中有哪些参数属性
./configure
--with-openssl #启用ssl
--with-zlib
--with-bz2
--with-curl #启用curl
--enable-bcmath
--enable-gd
--with-webp
--with-jpeg
--with-mhash
--enable-mbstring
--with-imap-ssl
--with-mysqli
--enable-exif
--with-ffi
--with-zip
--enable-sockets
--with-pcre-jit
--enable-fpm
--with-pdo-mysql #支持mysql
--with-pdo-pgsql #支持pgsql
--enable-pcntl
sudo make && make install
php -v
5.后台启动php-fpm -D
cp /root/php-8.2.5/sapi/fpm/php-fpm.conf /usr/local/etc/php-fpm.conf
vi /usr/local/etc/php-fpm.conf
更新include=NONE/etc/php-fpm.d/*.conf 为 include=/usr/local/etc/php-fpm.d/*.conf
cd /usr/local/etc/php-fpm.d/
cp www.conf.default www.conf
php-fpm -D
6.配置nginx配置文件
cd /etc/nginx/conf.d
cp default.conf test.conf
vi test.conf
server {
listen 80;
server_name 192.168.157.128;
#access_log /var/log/nginx/host.access.log main;
root /usr/share/nginx/html;
index index.html index.htm index.php;
autoindex on;
location / {
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
7.安装Wordpress博客测试效果
wget https://wordpress.org/latest.zip
unzip latest.zip
wget http://192.168.157.1/Share/wordpress-6.2.zip
unzip wordpress-6.2.zip