linux版本:centOS7 64位
- 下载php
# 建立一个文件夹放PHP
mkdir /usr/local/tools
wget https://www.php.net/distributions/php-7.2.28.tar.gz
# 解压
tar -zxvf php-7.2.28.tar.gz
cd php-7.2.28/
- 安装PHP依赖包和扩展库
yum install -y gd libjpeg* libpng* libXpm php-gd libxml2 libxml2-devel libcurl-devel freetype-devel kernel keyutils patch perl kernel-headers gtk+-devel glibc libgomp libstdc++-devel keyutils-libs-devel libsepol-devel libselinux-devel krb5-devel fontconfig fontconfig-devel gettext gettext-devel ncurses* libtool* patch policycoreutils bison openssl openssl-devel curl-devel libjpeg-devel libpng-devel bzip2-devellibmcrypt libmcrypt-devel postgresql-devel aspell-devel readline-devel libxslt-devel net-snmp-devel unixODBC-devel libicu-devel libXpm-devel install libvpx-devel install enchant-devel install openldap install openldap-devel install db4-devel install gmp-devel install sqlite-devel install mysql-devel
- PHP配置
./configure \
--prefix=/usr/local/php7 \
--exec-prefix=/usr/local/php7 \
--bindir=/usr/local/php7/bin \
--sbindir=/usr/local/php7/sbin \
--includedir=/usr/local/php7/include \
--libdir=/usr/local/php7/lib/php \
--mandir=/usr/local/php7/php/man \
--with-config-file-path=/usr/local/php7/etc \
--with-mysql-sock=/var/run/mysql/mysql.sock \
--with-mcrypt=/usr/include \
--with-mhash \
--with-openssl \
--with-mysql=shared,mysqlnd \
--with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd \
--with-gd \
--with-iconv \
--with-zlib \
--enable-zip \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir \
--enable-opcache \
--enable-fpm \
--enable-fastcgi \
--without-gdbm \
--disable-fileinfo
注意:
--prefix=安装目录
--with-使用包名称[=包目录]
--enable-需要激活的功能
- 编译安装
make && make install
-
拷贝生产环境的PHP配置文件
cp /usr/local/tools/php-7.2.28/php.ini-production /usr/local/php7/etc/php.ini
- 删除系统自带配置文件/etc/php.ini
rm -rf /etc/php.ini
- 添加软连接
ln -s /usr/local/php7/etc/php.ini /etc/php.ini
- 拷贝php-fpm配置文件
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
- 修改php-fpm.conf
vim /usr/local/php7/etc/php-fpm.conf
取消pid = run/php-fpm.pid前的分号# php-fpm需要www.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
- 设置启动项
#拷贝php-fpm到启动目录
cp /usr/local/tools/php-7.2.28/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
chmod +x /etc/rc.d/init.d/php-fpm #添加执行权限
chkconfig php-fpm on #设置开机启动
service php-fpm start #启动php-fpm
- 配置环境变量
vim /etc/profile
在末尾追加
PATH=$PATH:/usr/local/php/bin
export PATH
执行命令使得改动立即生效
source /etc/profile
- 配置nginx
vim /usr/local/nginx/conf/nginx.conf
- 生成nginx.pid文件
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
#编辑PHP文件
vim /usr/local/nginx/html/index.php
#<?php
# phpinfo();
打开浏览器,ip/index.php到这里,基本配置成功!!!
自定义域名配置
mkdir /home/data/wwwroot
touch /home/data/wwwroot/index.html #入口文件
touch /home/data/wwwroot/index.php #PHP文件
- 配置本地DNS,本地hosts
C:\Windows\System32\drivers\etc