安装php
下载地址:https://www.php.net/ ,这里用的是7.1.10版本。
- 先下载依赖包
yum -y install \ libjpeg \ libjpeg-devel \ libpng libpng-devel \ freetype freetype-devel \ libxml2 \ libxml2-devel \ zlib zlib-devel \ curl curl-devel \ openssl openssl-devel
- 将下载包解压然后进入文件夹中执行
[root@server php-7.1.10]# pwd /opt/php-7.1.10 ./configure \ --prefix=/usr/local/php \ //PHP文件路径 --with-mysql-sock=/usr/local/mysql/mysql.sock \ //对接mysql通讯文件 --with-mysqli \ //with支持的各项功能 --with-zlib \ --with-curl \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-freetype-dir \ --with-openssl \ --enable-fpm \ //开启fpm模块 --enable-mbstring \ //开启多字段模块 --enable-xml \ //开启扩展性标记语言模块 --enable-session \ //开启会话 --enable-ftp \ //开启文本传输协议 --enable-pdo \ //开启函数库 --enable-tokenizer \ //开启令牌解释器 --enable-zip //开启zip压缩
-
编译
make && make install
- 将php核心配置文件复制到php/lib下面
[root@server php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini
修改核心配置文件内容
vim /usr/local/php/lib/php.ini 939 date.timezone = Asia/Shanghai //设置时区 1170 mysqli.default_socket = /usr/local/mysql/mysql.sock //设置mysql通讯文件的对接
- 验证安装的模块
[root@server etc]# /usr/local/php/bin/php -m [PHP Modules] Core ctype curl date dom fileinfo filter ftp gd hash iconv json libxml mbstring mysqli mysqlnd openssl pcre PDO pdo_sqlite Phar posix Reflection session SimpleXML SPL sqlite3 standard tokenizer xml xmlreader xmlwriter zip zlib [Zend Modules]
- 优化fpm模块,将进程配置文件和扩展配置文件进行拷贝
cd /usr/local/php/etc/ cp php-fpm.conf.default php-fpm.conf cd /usr/local/php/etc/php-fpm.d/ cp www.conf.default www.conf
-
配置进程配置文件,开启pid
- 启动php-fpm -c,查看是否启动和进程号
[root@server etc]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini [root@server etc]# netstat -antp | grep 9000 tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 29883/php-fpm: mast [root@server etc]# ps aux | grep -c "php-fpm" 4
进入nginx配置文件中修改,将注释去掉,实现nginx与php对接
-
65 location ~ \.php$ { 66 root html; 67 fastcgi_pass 127.0.0.1:9000; 68 fastcgi_index index.php; 69 fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; 70 include fastcgi_params; 71 }
编写一个php主页
-
vim /usr/local/nginx/html/index.php <?php phpinfo(); ?>
访问页面
- 测试一下数据库是否工作正常,先进入数据库给用户提权
mysql -uroot -p123 mysql> create database bbs; Query OK, 1 row affected (0.00 sec) mysql> grant all on bbs.* to 'bbsuser'@'%' identified by 'admin123'; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> grant all on bbs.* to 'bbsuser'@'localhost' identified by 'admin123'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
- 重新编写php主页
<?php $link=mysqli_connect('12.0.0.8','bbsuser','admin123'); if($link) echo "<h1>Success</h1>"; else echo "Fail"; ?>
-
对接成功