在CentOS 6.6下安装PHP7和Nginx环境,需要按照以下步骤进行:
1、安装EPEL源
我们需要安装EPEL源,以便能够从官方仓库中获取所需的软件包,在终端中执行以下命令:
sudo yum install epel-release
2、安装Nginx
接下来,我们开始安装Nginx,在终端中执行以下命令:
sudo yum install nginx
安装完成后,启动Nginx服务并设置为开机自启动:
sudo service nginx start sudo chkconfig nginx on
3、安装PHP7
我们需要安装依赖库和工具:
sudo yum install gcc gcc-c++ make autoconf automake libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel -y
接下来,下载PHP7源码并解压:
wget https://www.php.net/distributions/php-7.0.33.tar.gz tar -zxvf php-7.0.33.tar.gz cd php-7.0.33
配置并编译PHP7:
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli --with-pdo_mysql --with-openssl --with-zlib --enable-mbstring --enable-sockets --enable-zip --enable-soap --enable-xmlrpc --enable-opcache --enable-intl --with-curl --with-gd --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/ --with-freetype-dir=/usr/include/ --with-mcrypt --with-mhash --with-readline --with-xsl --with-xmlrpc --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-sysvshm --enable-sysvmsg --enable-ipv6 --enable-exif --enable-ftp --with-gettext --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo_sqlite=sqlite3 --with-sqlite3=sqlite3 --enable-pcntl --enable-maintainer-zts make && make install
将PHP7添加到系统路径中:
echo "/usr/local/php/bin" >> /etc/profile source /etc/profile
4、配置Nginx以支持PHP
编辑Nginx配置文件:
sudo vi /etc/nginx/nginx.conf
在server
块中添加以下内容:
location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; }
创建一个新的目录来存放PHP脚本:
sudo mkdir /usr/share/nginx/html/scripts && sudo chown www:www /usr/share/nginx/html/scripts -R && sudo chmod -R 755 /usr/share/nginx/html/scripts && sudo chmod +x /usr/share/nginx/html/*.sh && sudo chmod +x /usr/share/nginx/html/*.pl && sudo chmod +x /usr/share/nginx/html/*.py && sudo chmod +x /usr/share/nginx/html/*.cgi && sudo chmod +x /usr/share/nginx/html/*.tcl && sudo chmod +x /usr/share/nginx/html/*.jsp && sudo chmod +x /usr/share/nginx/html/*.php && sudo chmod +x /usr/share/nginx/html/*.htm && sudo chmod +x /usr/share/nginx/html/*.html && sudo chmod +x /usr/share/nginx/html/*.xml && sudo chmod +x /usr/share/nginx/html/*.json && sudo chmod +x /usr/share/nginx/html/*.css && sudo chmod +x /usr/share/nginx/html/*.js && sudo chmod +x /usr/share/nginx/html/*.txt && sudo chmod +x /usr/share/nginx/html/*.sql && sudo chmod +x /usr/share/nginx/html/*.log && sudo chmod +x /usr/share/nginx/html/*.bak && sudo chmod +x /usr/share/nginx/html/*.zip && sudo chmod +x /usr/share/nginx/html/*.tar && sudo chmod +x /usr/share/nginx/html/*.gz && sudo chmod +x /usr/share/nginx/html/*.rar && sudo chmod +x /usr/share/nginx/html/*.mp3 && sudo chmod +x /usr/share/nginx/html/*.mp4 && sudo chmod +x /usr/share/nginx
原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/331053.html