PHP安装配置

一、PHP lib库安装

yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel -y
yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y

验证

rpm -qa zlib-devel libxml2-devel libjpeg-turbo-devel libiconv-devel
rpm -qa freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel

下载libiconv包

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz #一般速度很慢,提前下载传上来好一些。
cd /server/tools/
上传libiconv-1.16.tar.gz

安装libiconv包

tar zxf libiconv-1.16.tar.gz
cd libiconv-1.16
./configure --prefix=/application/libiconv
make
make install
cd ../

依赖安装

yum install libmcrypt-devel -y
yum install mhash -y
yum install mcrypt -y

epel源安装

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

二、PHP下载php-7.3.5.tar

php-7.3.5.tar.gz
wget https://www.php.net/distributions/php-7.3.5.tar.gz
cd /server/tools/
tar xf php-7.3.5.tar.gz
cd php-7.3.5/

三、PHP编译安装

./configure \
--prefix=/application/php-7.3.5 \
--enable-mysqlnd  \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/application/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--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 \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp \
--enable-opcache=no
image.png

四、安装完成

image.png
image.png

五、将nginx的用户和PHP的用户统一:(nginx)

[root@web02 /server/tools/php-7.3.5]# useradd nginx -u 1111 -s /sbin/nologin -M
[root@web02 /server/tools/php-7.3.5]# id nginx
uid=1111(nginx) gid=1111(nginx) 组=1111(nginx)
[root@web02 /server/tools/php-7.3.5]# vim /application/nginx/conf/nginx.conf
worker_processes 1;
user nginx nginx;(编译的时候就改用nginx)

六、创建软连接

[root@web02 ~]# ln -s /application/php-7.3.5/ /application/php
[root@web02 ~]# ls /application/php/
bin etc include lib php sbin var

七、配置PHP解析器

配置php.ini(PHP解析器配置文件)
[root@web02 /application/php]# cd /server/tools/php-7.3.5/
[root@web02 /server/tools/php-7.3.5]# ls php.ini-*
php.ini-development php.ini-production
[root@web02 /server/tools/php-7.3.5]# cp php.ini-development /application/php/lib/php.ini
[root@web02 /server/tools/php-7.3.5]# ls -l /application/php/lib/php.ini
-rw-r--r-- 1 root root 71648 5月 6 11:51 /application/php/lib/php.ini

八、配置PHP FPM

[root@web02 /server/tools/php-7.3.5]# cd /application/php/etc/
[root@web02 /application/php/etc]# ls
pear.conf php-fpm.conf.default php-fpm.d
[root@web02 /application/php/etc]# cp php-fpm.conf.default php-fpm.conf
[root@web02 /application/php/etc]# cd php-fpm.d/
[root@web02 /application/php/etc/php-fpm.d]# ls
www.conf.default
[root@web02 /application/php/etc/php-fpm.d]# cp www.conf.default www.conf
[root@web02 /application/php/etc/php-fpm.d]# ls
www.conf www.conf.default

九、启动PHP服务

[root@web02 /application/php/etc/php-fpm.d]# /application/php/sbin/php-fpm
[root@web02 /application/php/etc/php-fpm.d]# netstat -lntup|grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 12214/php-fpm: mast

十、开机自启动

[root@web02 /application/php/etc/php-fpm.d]# tail -2 /etc/rc.local
/application/nginx/sbin/nginx
/application/php/sbin/php-fpm

十一、配置nginx转发PHP请求

方法一:

成功的配置:[root@web02 /application/nginx/conf]# vim nginx.conf

 location ~ .*\.(php|php5)?$ {
            root html/blog;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
        }

方法二:

成功的配置:[root@web02 /application/nginx/conf]# vim nginx.conf

server {
        listen       80;
        server_name  blog.etiantian.org;
        location / {
            root   html/blog;
            index  index.html index.htm;
        }
        location ~ .*\.(php|php5)?$ {
            root html/blog;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
        }
    }

编写测试文件

[root@web02 /application/nginx/conf]# echo "" > ../html/blog/test_info.php
[root@web02 /application/nginx/conf]# cat ../html/blog/test_info.php

本地虚拟机测试:

[root@web02 /application/nginx/conf]# /application/php/bin/php /application/nginx/html/blog/test_info.php

nginx校验:

[root@web02 /application/nginx/conf]# nginx -t
nginx: the configuration file /application/nginx-1.16.0//conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.16.0//conf/nginx.conf test is successful
[root@web02 /application/nginx/conf]# nginx -s reload

测试PHP连接mysql

[root@web02 /application/nginx/html/blog]# vim /application/nginx/html/blog/test_mysql.php


本地虚拟机测试连接MySQL

[root@web02 /application/nginx/html/blog]# /application/php/bin/php /application/nginx/html/blog/test_mysql.php
mysql successful by zhangweibin.

十二、设置win中的hosts文件,并到浏览器访问测试。

http://blog.etiantian.org/test_mysql.php
LNMP环境搭建成功。

你可能感兴趣的:(PHP安装配置)