原创

Web-linux服务器-php安装mysql扩展-好像也包括安装php环境


首先官网下载php,http://php.net/downloads.php,用的是5.6.28的版本。

下载后,上传到服务器随意目录。
groupadd www
useradd -g www www
mkdir -p /dd/packages/php
cd /dd/packages/php

wget https://www.php.net/distributions/php-5.6.28.tar.gz
tar xzvf php-5.6.28.tar.gz
cd php-5.6.28

完了后,configure编译,如下:

# ./configure \
--prefix=/usr/local/php56 \
--with-config-file-path=/usr/local/php56/etc \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-opcache \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gettext \
--enable-mbstring \
--with-iconv \
--with-mcrypt \
--with-mhash \
--with-openssl \
--enable-bcmath \
--enable-soap \
--with-libxml-dir \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-sockets \
--with-curl \
--with-zlib \
--enable-zip \
--with-bz2 \
--with-readline
这个时候有可能会出现下列错误:

configure: error: xml2-config not found. Please check your libxml2 installation.
yum install libxml2
yum install libxml2-devel -y
确认结果
find / -name "xml2-config"

configure: error: Please reinstall the BZip2 distribution
yum -y install bzip2
yum -y install bzip2-devel

configure: error: Please reinstall the libcurl distribution -easy.h should be in <curl-dir>/include/curl/
yum install -y curl curl-devel

configure: error: mcrypt.h not found. Please reinstall libmcrypt.
原因:centos源不能安装libmcrypt-devel,由于版权的原因没有自带mcrypt的包
下载libmcrypt-2.5.8.tar.gz,然后安装,如下:
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz

tar -zxvf libmcrypt-2.5.7.tar.gz
cd /usr/local/src/libmcrypt-2.5.7
./configure --prefix=/usr/local
make
make install【这个会展示出php安装的路径 php的可执行文件是 /usr/local/php56/bin/php】
此时可能会出现如下错误:
configure: error: C++ compiler cannot create executables
靠谱的解决方法是:
yum install gcc gcc-c++ gcc-g77
然后重新执行,问题应该就解决了。
或者
yum install -y epel-release
yum install -y libmcrypt-devel


configure: error: Please reinstall readline - I cannot find readline.h
yum -y install readline-devel

然后重新configure,此时可能会遇到下列错误:
error: Don't know how to define struct flock on this system, set --enable-op
靠谱的解决方法是:
sudo ln -s /usr/local/mysql/lib/libmysqlclient.so /usr/lib/
sudo ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18

export LD_LIBRARY_PATH=/lib/:/usr/lib/:/usr/local/lib:/usr/local/mysql/lib

再执行,应该不会报错了(php的)。
make
make install

注:在低配置的服务器比如小于1gb时,有可能make时出现如下错误:
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

解决办法

这是由于内存小于1G所导致.

在./configure加上选项:

--disable-fileinfo
Disable fileinfo support 禁用 fileinfo

或者,重新make可能会过去。

[root@dev3 bin]# ./php -version
PHP 5.6.28 (cli) (built: Nov 18 2016 13:02:58)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies



配置php

[root@dev3 php-5.6.28]#

cp php.ini-development /usr/local/php56/etc/php.ini
将其中的always_populate_raw_post_data改为 -1
($postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; 改成 $postStr = file_get_contents('php://input'); 并重启php 这样就没有nginx中的错误日志了)

配置php-fpm 服务
# cp /usr/local/php56/etc/php-fpm.conf.default /usr/local/php56/etc/php-fpm.conf
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm56
# chmod +x /etc/init.d/php-fpm56
启动 php-fpm

修改9000端口到 9001(如果有需要)(https://www.php.cn/faq/531969.html)
vi /usr/local/php56/etc/php-fpm.conf

# service php-fpm56 start 如果已经安装过,就先关闭 service php-fpm stop( service php-fpm56 stop),再service php-fpm start ,不要56

Starting php-fpm [30-Nov-2023 12:34:06] ERROR: [pool www] cannot get uid for user 'www'
[30-Nov-2023 12:34:06] ERROR: FPM initialization failed
failed
添加个账户就行
groupadd www
useradd -g www www

验证游戏9001端口是否启动
[root@iZuf64719sowr4hia7ka7qZ php-5.6.28]# ps -ef |grep php
root 9927 1 0 13:58 ? 00:00:00 php-fpm: master process (/usr/local/php56/etc/php-fpm.conf)
www 9928 9927 0 13:58 ? 00:00:00 php-fpm: pool www
www 9929 9927 0 13:58 ? 00:00:00 php-fpm: pool www
root 10029 17506 0 14:20 pts/0 00:00:00 grep --color=auto php
[root@iZuf64719sowr4hia7ka7qZ php-5.6.28]# netstat -ntlp | grep 9001
tcp 0 0 127.0.0.1:9001 0.0.0.0:* LISTEN 9927/php-fpm: maste


如果执行stop start ,提示找不到Uint,就从./configure重新走一下 、还有make ,make install

配置时区:
whereis php
vi /etc/php.ini (应该是 /usr/local/php56/etc/php.ini)
date.timezone=Asia/Shanghai (是不是必须带空格?)
service php-fpm stop ( service php-fpm56 stop)
start php-fpm.service ( service php-fpm56 start )

全局配置php的环境变量,因为可以从make install上看到 php在 /usr/local/php56/bin/下(php的可执行文件是 /usr/local/php56/bin/php)
vim /etc/profile
在文档最后加上
export PATH="/usr/local/php56/bin:$PATH"
source /etc/profile
php -v (测试成功)



到此为止,php本身的安装和配置就完成了,如何验证呢。。。。

很重要的一点是:php本身并不是一个web服务器,只是一个web服务器后面的cgi实现,就像java本身并不提供http服务一样,前台有个tomcat。
所以php要依赖于nginx或者apache作为前置,因为我们一直用nginx,所以以nginx为例。
首先,我不得不说nginx自带的nginx.conf中配置php的示例代码是坑。。。
读者直接参考php官方给的即可,http://php.net/manual/zh/install.unix.nginx.php。亲测,没有问题的。

发现php会挂调,应该是读取数据库超时导致的
先加日志观察,同时把tech. 的php数据库关闭
request_slowlog_timeout = 2
slowlog = /slowlog = /dd/php/php.log
 

正文到此结束
本文目录