搭建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
相關文章
相關標籤/搜索