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

PHP

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

安装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 就解决了。

  • 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启动成功。

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

转载于:https://my.oschina.net/u/3731306/blog/3008717

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值