Hypertext Preprocessor,超文本预处理器。是在服务器端执行的脚本语言,与C语言类似,是常用的网站编程语言。
之后呢php搭建好之后会用到MySQLi扩展库,通过MySQLi构造方法实例化一个MySQL连接对象,相当于建立了一个连接,后续代码完全使用面向对象的方法,使用该对象的成员函数操作MySQL数据库。
该篇呢我们来看一下redhat7.2上php的搭建~
1、准备安装包
友情链接 php:https://www.php.net/downloads.php
2、安装依赖
# yum -y install pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel openldap-servers openldap-client nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel bzip2 bzip2-devel libxml2 libxml2-devel bzip2 bzip2-devel curl-devel gmp-devel readline-devel
3、指定目录然后解压
# tar zxvf php-7.1.30.tar.gz
4、编译
./configure \
--prefix=/usr/local/php \
--with-pdo-mysql=/opt/mysql \
--enable-mysqlnd \
--with-pdo-mysql=mysqlnd \
-with-mysqli=mysqlnd \
--with-mysql-sock=/tmp/mysql.sock \
--with-config-file-path=/usr/local/php \
--enable-fpm \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-onig \
--enable-pdo \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--with-pear \
--enable-opcache
编译时可能会因为版本不同有一些其他需要安装的包或者工具,装上就好啦~
5、安装
[root@localhost php]# make && make install
6、复制php配置文件到指定目录,并优化命令路径
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# ln -s /usr/local/php/bin/ /usr/local/bin/
[root@localhost etc]# ln -s /usr/local/php/sbin/ /usr/local/sbin/
7、添加用户
[root@localhost etc]# useradd -M -s /sbin/nologin php
[root@localhost etc]# id php
uid=1003(php) gid=1003(php) groups=1003(php)
8、修改配置文件
[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# vi www.conf
在www.conf中修改以下几个参数
user = php #用户php
group = php #组php
pm.max_children = 50 # php-fpm 能启动的子进程的最大数量
pm.start_servers = 20 #动态方式下的起始php-fpm进程数量
pm.min_spare_servers = 5 #动态方式空闲状态下的最小php-fpm进程数量
pm.max_spare_servers = 35 #动态方式空闲状态下的最大php-fpm进程数量。
9、启动php-fpm
[root@localhost php-fpm.d]# /usr/local/php/sbin/php-fpm
10、查看php进程
[root@localhost php-fpm.d]# pgrep php
查看端口号:
[root@localhost php-fpm.d]# netstat -ntap | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 94154/php-fpm: mast
11、使用php连接nginx
[root@localhost php-fpm.d]# cd /usr/local/nginx/conf/
[root@localhost conf]# vi nginx.conf
#添加index.php,识别默认首页
location / {
root html;
index index.html index.htm index.php;
}
#去掉如下注释,这里需要将/scripts改成$document_root,否则nginx返回空白页面
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
12、修改nginx的默认首页
[root@localhost conf]# cd ../html/
[root@localhost html]# pwd
/usr/local/nginx/html
[root@localhost html]# vi index.php
13、重启nginx服务
[root@localhost html]# /usr/local/nginx/sbin/nginx -s reload
在浏览器中输入网址查看页面:
需要有以下mysql扩展模块:
[root@localhost html]# vi index.php
[root@localhost html]# cat index.php
$link=mysqli_connect('192.168.100.131','root','root');
if($link) echo "
else echo "
?>
刷新刚才的页面,显示连接成功!
注意:在编译时会出现错误:libxml2 configure: error: xml2-config not found. Please check your libxml2 installation.
解决办法呢是:yum install libxml2-devel
可能还会有由于其他包没装的错误,装上就好啦~