本文以nginx 1.8和php 7.2为例,详细讲解手动安装过程。
一、Nginx安装:
yum -y install gcc gcc-c++ autoconf automake make zlib zlib-devel openssl openssl-devel pcre pcre-devel登录后复制 下载Nginx:: 从Nginx官网 (https://www.php.cn/link/06b44f22bf01b4bad31391ffe00009c4) 下载您需要的版本。 解压并安装::
cd /usr/local wget https://www.php.cn/link/06b44f22bf01b4bad31391ffe00009c4nginx-1.8.0.tar.gz # 请替换为您的下载链接 tar -zxvf nginx-1.8.0.tar.gz cd nginx-1.8.0 ./configure make && make install登录后复制 启动Nginx::
cd /usr/local/nginx ./sbin/nginx登录后复制 将Nginx添加到系统服务::
创建文件 /usr/lib/systemd/system/nginx.service,并写入以下内容:
[Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/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 ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target登录后复制
保存后执行:
立即学习“PHP免费学习笔记”;
systemctl start nginx.service systemctl enable nginx.service登录后复制 验证安装::
ps -ef | grep nginx登录后复制
二、PHP安装:
安装依赖包::yum install -y gcc gcc-c++ libxml2-devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel freetype freetype-devel登录后复制
下载PHP:: 从PHP官网 (https://www.php.cn/link/4ea01965a7b1b4359cdabed6e3e6936b) 下载PHP 7.2.10 (或您需要的版本)。
解压并安装::
cd /usr/local wget http://tz1.php.net/distributions/php-7.2.10.tar.gz # 请替换为您的下载链接 tar -zxvf php-7.2.10.tar.gz cd php # 如果解压后目录名不同,请调整 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --with-pdo-mysql --enable-maintainer-zts -with-mcrypt=/usr/include --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --enable-ftp --enable-session --with-gettext --with-jpeg-dir --with-freetype-dir --enable-fastcgi --without-gdbm --disable-fileinfo make && make install登录后复制 验证PHP安装::
php -v登录后复制
如果 php -v 命令无法执行,请将PHP添加到环境变量 /etc/profile 文件中,添加 export PATH="/usr/local/php/bin:$PATH" (替换 /usr/local/php/bin 为您的实际路径),然后执行 source /etc/profile。
完成以上步骤后,Nginx和PHP 7.2就安装完成了。 请根据您的实际情况调整路径和版本号。
本文来自投稿,不代表本站立场,如若转载,请注明出处: