卷首语:
整理好本来不想发的,但一想到自己也是借鉴别人的经验才配置成功的,所以,吃水不忘打井人,想了想还是贴出来吧,希望对看到的人能有所帮助!
-------------------------------------------------------------------------------------------------------------------
-----== PHP-5.6.36安装 仅供参考:https://www.ityww.cn/1151.html 完全按这个文档走,会出问题!
1、确认下载版本
PHP-5.6.36 # 资源已下载
2、安装epel源
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup #如本地不存在EPEL请忽略
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup #如本地不存在EPEL请忽略
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
3、安装基础库和扩展库
yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libpng-devel libcurl-devel libxslt-devel freetype-devel gd-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libicu-devel -y
4、安装libiconv
cd /fitness/software/
mkdir libiconv-1.15
wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
./configure --prefix=/fitness/serve/libiconv # 注意:这里‘-’必须为英文版的,必须为双--
make && make install
5、加压PHP-5.6.36,进入目录安装
cd /fitness/software/php-5.6.36
tar -zxf php-5.6.36.tar.gz
cd php-5.6.36
./configure \
--prefix=/fitness/serve/php \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysql=/fitness/serve/mysql \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/fitness/serve/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--with-mcrypt \
--enable-ftp \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--disable-fileinfo \
--enable-opcache \
--enable-intl \
--enable-short-tags \
--with-xsl
编译完:
Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
成功!
安装:
make && make install
时间有点长,稍等会,结果:
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /fitness/serve/php/lib/php/extensions/no-debug-non-zts-20131226/
Installing PHP CLI binary: /fitness/serve/php/bin/
Installing PHP CLI man page: /fitness/serve/php/php/man/man1/
Installing PHP FPM binary: /fitness/serve/php/sbin/
Installing PHP FPM config: /fitness/serve/php/etc/
Installing PHP FPM man page: /fitness/serve/php/php/man/man8/
Installing PHP FPM status page: /fitness/serve/php/php/php/fpm/
Installing PHP CGI binary: /fitness/serve/php/bin/
Installing PHP CGI man page: /fitness/serve/php/php/man/man1/
Installing build environment: /fitness/serve/php/lib/php/build/
Installing header files: /fitness/serve/php/include/php/
Installing helper programs: /fitness/serve/php/bin/
program: phpize
program: php-config
Installing man pages: /fitness/serve/php/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /fitness/serve/php/lib/php/
[PEAR] Archive_Tar - installed: 1.4.3
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util - installed: 1.4.2
[PEAR] PEAR - installed: 1.10.5
Wrote PEAR system config file at: /fitness/serve/php/etc/pear.conf
You may want to add: /fitness/serve/php/lib/php to your php.ini include_path
/fitness/software/php-5.6.36/php-5.6.36/build/shtool install -c ext/phar/phar.phar /fitness/serve/php/bin
ln -s -f phar.phar /fitness/serve/php/bin/phar
Installing PDO headers: /fitness/serve/php/include/php/ext/pdo/
6、拷贝并改名PHP配置文件
cp /fitness/software/php-5.6.36/php-5.6.36/php.ini-production /fitness/serve/php/lib/php.ini
#下面的拷贝,是因为php/etc/下没有找到php-fpm.d目录,才进行的如此操作
cp /fitness/software/php-5.6.36/php-5.6.36/php.ini-production /fitness/serve/php/etc/php.ini
7、拷贝并改名PHP-FPM配置文件
cp /fitness/serve/php/etc/php-fpm.conf.default /fitness/serve/php/etc/php-fpm.conf
8、编辑php/etc/php-fpm.conf
;pid = run/php-fpm.pid
-》
pid = run/php-fpm.pid
去掉‘;’,然后wq
9、拷贝PHP-FPM服务文件至启动目录并添加执行权限
cp /fitness/software/php-5.6.36/php-5.6.36/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm && chmod +x /etc/rc.d/init.d/php-fpm
10、将PHP-FPM服务配置开机启动并检查
chkconfig php-fpm on
chkconfig --list php-fpm
[root@iZ8vb2uz59jd5pisp87ljiZ init.d]# chkconfig php-fpm on
[root@iZ8vb2uz59jd5pisp87ljiZ init.d]# chkconfig --list php-fpm
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
11、启动PHP-FPM服务并验证
systemctl start php-fpm.service
systemctl status php-fpm.service && ss -lnat
报错了
[root@iZ8vb2uz59jd5pisp87ljiZ sbin]# /fitness/serve/php/sbin/php-fpm
[25-Jun-2019 17:36:14] ERROR: [pool www] cannot get uid for user 'www'
[25-Jun-2019 17:36:14] ERROR: FPM initialization failed
解决:
[root@iZ8vb2uz59jd5pisp87ljiZ sbin]# useradd www
再次:
[root@iZ8vb2uz59jd5pisp87ljiZ etc]# systemctl status php-fpm.service && ss -lnat
● php-fpm.service - LSB: starts php-fpm
Loaded: loaded (/etc/rc.d/init.d/php-fpm; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2019-06-25 17:20:36 CST; 18min ago
Docs: man:systemd-sysv-generator(8)
Process: 15643 ExecStart=/etc/rc.d/init.d/php-fpm start (code=exited, status=1/FAILURE)
Jun 25 17:20:36 iZ8vb2uz59jd5pisp87ljiZ systemd[1]: Starting LSB: starts php-fpm...
Jun 25 17:20:36 iZ8vb2uz59jd5pisp87ljiZ php-fpm[15643]: Starting php-fpm [25-Jun-2019 17:20:36] ERROR: [pool www] cannot get uid for user 'www'
Jun 25 17:20:36 iZ8vb2uz59jd5pisp87ljiZ php-fpm[15643]: [25-Jun-2019 17:20:36] ERROR: FPM initialization failed
Jun 25 17:20:36 iZ8vb2uz59jd5pisp87ljiZ php-fpm[15643]: failed
Jun 25 17:20:36 iZ8vb2uz59jd5pisp87ljiZ systemd[1]: php-fpm.service: control process exited, code=exited status=1
Jun 25 17:20:36 iZ8vb2uz59jd5pisp87ljiZ systemd[1]: Failed to start LSB: starts php-fpm.
Jun 25 17:20:36 iZ8vb2uz59jd5pisp87ljiZ systemd[1]: Unit php-fpm.service entered failed state.
Jun 25 17:20:36 iZ8vb2uz59jd5pisp87ljiZ systemd[1]: php-fpm.service failed.
这个报错【Failed to start LSB: starts php-fpm】是说/fitness/serve/php/etc/php-fpm.d目录下缺少对应的.conf配置文件
我查看了一下:
[root@iZ8vb2uz59jd5pisp87ljiZ etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default
居然没有php-fpm.d目录?!
操,哪里出问题了,想来想去,serve/php是在编译,make && make install后生成的,所以,肯定就出在了编译:
./configure \
--prefix=/fitness/serve/php \
--with-config-file-path=/fitness/serve/php/etc \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysql=/fitness/serve/mysql \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/fitness/serve/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--with-mcrypt \
--enable-ftp \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--disable-fileinfo \
--enable-opcache \
--enable-intl \
--enable-short-tags \
--with-xsl
重新编译,make && make install还是没有那个目录,后来,我看了之前已经装好的相同版本的PHP,发现也没有这个目录
于是,我猜想是不是,不能用【systemctl status php-fpm.service】此命令启动php-fpm,于是,我换了一下:
service php-fpm start
[root@iZ8vb2uz59jd5pisp87ljiZ init.d]# service php-fpm start
Starting php-fpm [25-Jun-2019 18:37:30] ERROR: unable to bind listening socket for address '127.0.0.1:9000': Address already in use (98)
[25-Jun-2019 18:37:30] ERROR: FPM initialization failed
出现这种报错,处理如下:
netstat -lntup | grep 9000
killall php-fpm
service php-fpm start
[root@iZ8vb2uz59jd5pisp87ljiZ init.d]# service php-fpm start
Starting php-fpm done
php-fpm启动,表示成功!!
我觉得我被这个文档误导了!php-fmp就应该【service php-fpm start】启动,不应该用【systemctl start php-fpm.service】这个命令!
12、PHP和Nginx进行整合,编辑nginx.conf文件
cd /fitness/serve/nginx/conf
vim nginx.conf
去掉注释:
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
记得重启Nginx:
./nginx -s reload
[root@iZ8vb2uz59jd5pisp87ljiZ sbin]# ./nginx -t
nginx: the configuration file /fitness/serve/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /fitness/serve/nginx/conf/nginx.conf test is successful
[root@iZ8vb2uz59jd5pisp87ljiZ sbin]# ./nginx -s reload
切记,Nginx.conf关键配置,就在【关键行】
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 【关键行】
include fastcgi_params;
}
13、最后访问
-------------------------------------------------------------------------------------------------------------------