搭建LNMP(二)源码包安装PHP、Nginx

PHP

PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。语法吸取了C语言、Java和Perl的特色,利于学习,使用普遍,主要适用于Web开发领域。php

安装PHP

  • cd到/usr/local/src目录下,下载PHP源码包,解压下载的源码包
[root@test01 src]# wget http://cn2.php.net/distributions/php-7.3.2.tar.bz2
[root@test01 src]# tar jxvf php-7.3.2.tar.bz2
  • 若是没安装bzip2工具,须要先安装
yum install bzip2 -y
  • configure源码包
[root@test01 php-7.3.2]# ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysql=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jgd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl
  • 报错1 configure: error: libxml2 not found. Please check your libxml2 installation。解决方式:
[root@test01 php-7.3.2]# yum install libxml2-devel -y
  • 报错2 configure: error: Cannot find OpenSSL's <evp.h>。解决方式:
[root@test01 php-7.3.2]# yum install openssl-devel -y
  • 报错3 checking for cURL 7.15.5 or greater... configure: error: cURL version 7.15.5 or later is required to compile php with cURL support 解决方式:
[root@test01 php-7.3.2]# yum install curl-devel -y
  • 报错4 configure: error: png.h not found.解决方式:
yum install libpng-devel -y
  • 报错5 configure: error: PDO_MYSQL configure failed, MySQL 4.1 needed. Please check config.log for more information.
  • 下载一个MySQL5.6的二进制包,将二进制包解压并移动到/usr/local/下更名mysql5.6,更改参数为
./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql5.6 --with-mysqli=/usr/local/mysql5.6/bin/mysql_config --with-pdo-mysql=/usr/local/mysql5.6 --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl
  • 出现以下界面表示configure完成。
+--------------------------------------------------------------------+
| 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 php7.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/www.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/phpdbg/phpdbg.1
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: main/php_config.h is unchanged
config.status: executing default commands
configure: WARNING: unrecognized options: --with-mysql, --with-mysql, --with-jgd-native-ttf
[root@test01 php-7.3.2]# echo $?
0
  • make源码包 make 报错:libtool: link: `ext/opcache/ZendAccelerator.lo' is not a valid libtool object。解决
make distclean

从新./configure ,再make 就解决了。html

  • make install
  • 安装完成以后能够进到以下目录,拷贝一份配置文件,而后去里面配置一些内容
  • 再到以前解压后的目录下拷贝一份配置文件,作一些修改。
[root@localhost etc]# cp /usr/local/php-fpm/etc/php-fpm.conf.default /usr/local/php-fpm/etc/php-fpm.conf
[root@localhost php-7.3.2]# cp php.ini-development /usr/local/php-fpm/etc/php.ini
  • 再复制一个启动脚本到服务管理里面
[root@localhost ~]# cd /usr/local/src/php-7.3.2/sapi/fpm/
[root@localhost fpm]# ls
config.m4  fpm             init.d.php-fpm.in  Makefile.frag  php-fpm.8     php-fpm.conf     php-fpm.service     status.html     tests     www.conf.in
CREDITS    init.d.php-fpm  LICENSE            php-fpm        php-fpm.8.in  php-fpm.conf.in  php-fpm.service.in  status.html.in  www.conf
[root@localhost fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
  • 将php-fpm添加到启动脚本里面
[root@localhost fpm]# chkconfig --add php-fpm
[root@localhost fpm]# chkconfig --list

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]'.

mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
netconsole     	0:off	1:off	2:off	3:off	4:off	5:off	6:off
network        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
php-fpm        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
  • 给/etc/init.d/php-fpm 文件权限,而后启动,发现报错了。
[root@localhost fpm]# chmod 755 /etc/init.d/php-fpm 
[root@localhost fpm]# service php-fpm start
Starting php-fpm [09-Feb-2019 05:51:58] WARNING: Nothing matches the include pattern '/usr/local/php-fpm/etc/php-fpm.d/*.conf' from /usr/local/php-fpm/etc/php-fpm.conf at line 143.
[09-Feb-2019 05:51:58] ERROR: No pool defined. at least one pool section must be specified in config file
[09-Feb-2019 05:51:58] ERROR: failed to post process the configuration
[09-Feb-2019 05:51:58] ERROR: FPM initialization failed
 failed
  • 能够根据错误提示去查看/usr/local/php-fpm/etc/php-fpm.conf文件的143行
  • 而后再根据文件中提示的路径去看是否有.conf 结尾的文件。
[root@localhost fpm]# cd /usr/local/php-fpm/etc/php-fpm.d/
[root@localhost php-fpm.d]# ls
www.conf.default
[root@localhost php-fpm.d]# mv www.conf.default www.conf
  • 再启动,提示没有php-fpm 用户,建立用户后再启动便可。
[root@localhost php-fpm.d]# service php-fpm start
Starting php-fpm [09-Feb-2019 06:02:20] ERROR: [pool www] cannot get uid for user 'php-fpm'
[09-Feb-2019 06:02:20] ERROR: FPM initialization failed
 failed
[root@localhost php-fpm.d]# useradd php-fpm
[root@localhost php-fpm.d]# service php-fpm start
Starting php-fpm  done
[root@localhost php-fpm.d]# ps aux |grep php-fpm
root      28835  0.0  0.4 119208  4324 ?        Ss   06:03   0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm   28836  0.0  0.3 119208  3880 ?        S    06:03   0:00 php-fpm: pool www
php-fpm   28837  0.0  0.3 119208  3876 ?        S    06:03   0:00 php-fpm: pool www
root      28839  0.0  0.0 112708   980 pts/1    R+   06:03   0:00 grep --color=auto php-fpm

PHP启动成功。mysql

Nginx编译安装

[root@localhost src]# wget http://nginx.org/download/nginx-1.14.2.tar.gz
[root@localhost src]# tar zxvf nginx-1.14.2.tar.gz
  • 进入解压后的目录,开始编译,编译的时候指定安装路径和ssl模块就能够了。
[root@localhost nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module
  • make && make install
[root@localhost nginx-1.14.2]# make &&make install
[root@localhost nginx-1.14.2]# echo $?
0
  • 启动Nginx
[root@localhost nginx-1.14.2]# /usr/local/nginx/sbin/nginx 
[root@localhost nginx-1.14.2]# ps aux | grep nginx
root      31425  0.0  0.1  45936  1124 ?        Ss   06:25   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody    31426  0.0  0.1  46388  1904 ?        S    06:25   0:00 nginx: worker process
root      31428  0.0  0.0 112708   980 pts/1    R+   06:25   0:00 grep --color=auto nginx
相关文章
相关标签/搜索