LNMP-安裝MySQL和PHP
和LAMP不同的是,提供web服務的是Nginx,並且php是作為一個獨立服務存在的,這個服務叫做php-fpm。Nginx直接處理靜態請求,動態請求會轉發給php-fpm。因此,在靜態頁面的處理上,Nginx較Apache更勝一籌。
安裝MySQL
1、下載並解壓
[[email protected]
2、創建用戶與文件夾
[[email protected] src]# cd /usr/local/mysql [[email protected]
和LAMP不同的是,提供web服務的是Nginx,並且php是作為一個獨立服務存在的,這個服務叫做php-fpm。Nginx直接處理靜態請求,動態請求會轉發給php-fpm。因此,在靜態頁面的處理上,Nginx較Apache更勝一籌。
安裝MySQL
1、下載並解壓
[[email protected]
2、創建用戶與文件夾
[[email protected] src]# cd /usr/local/mysql [[email protected]
3、初始化數據庫
[[email protected] mysql]# yum install -y perl perl-Data-Dumper libaio libaio-devel [[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
4、拷貝啟動腳本文件
[[email protected]
5、啟動MySQL
[[email protected] mysql]# vi /etc/init.d/mysqld basedir=/usr/local/mysql datadir=/data/mysql [[email protected] mysql]# chkconfig --add mysqld [[email protected] mysql]# chkconfig mysqld on [[email protected] mysql]# service mysqld start Starting MySQL.Logging to ‘/data/mysql/juispan.err‘. SUCCESS!
安裝PHP
1、下載並解壓
[[email protected] mysql]# cd /usr/local/src [[email protected] src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz [[email protected] src]# tar zxf php-5.6.30.tar.gz
2、配置php
[[email protected] src]# useradd -s /sbin/nologin php-fpm [[email protected] src]# cd php-5.6.30 [[email protected] php-5.6.30]# ./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-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --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
在配置過程中,會遇到一個接一個的配置失敗,這裏需要耐心處理。
問題1:configure: error: xml2-config not found. Please check your libxml2 installation.
[[email protected] php-5.6.30]# yum install -y libxml2-devel
問題2:configure: error: Cannot find OpenSSL‘s <evp.h>
[[email protected] php-5.6.30]# yum install -y openssl-devel
問題3:configure: error: Please reinstall the BZip2 distribution
[[email protected] php-5.6.30]# yum install -y bzip2-devel
問題4:configure: error: jpeglib.h not found.
[[email protected] php-5.6.30]# yum install -y libjpeg-turbo-devel
問題5:configure: error: png.h not found.
[[email protected] php-5.6.30]# yum install -y libpng-devel
問題6:configure: error: freetype-config not found.
[[email protected] php-5.6.30]# yum install -y freetype-devel
問題7:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
[[email protected] php-5.6.30]# yum install -y libmcrypt-devel
問題8:configure: error: Please reinstall the libcurl distribution -easy.h should be in <curl-dir>/include/curl/
[[email protected] php-5.6.30]# yum install -y libcurl-devel
處理完以上問題後,重新配置出現以下文本:
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: main/php_config.h is unchanged config.status: executing default commands
以上文本內容表示配置成功,如果不放心可以用“echo $?”確認下。
3、編譯與安裝
[[email protected] php-5.6.30]# make [[email protected] php-5.6.30]# make install
4、調整php-fpm配置
[[email protected] php-5.6.30]# cp php.ini-production /usr/local/php-fpm/etc/php.ini [[email protected] php-5.6.30]# vi /usr/local/php-fpm/etc/php-fpm.conf [global] pid = /usr/local/php-fpm/var/run/php-fpm.pid error_log = /usr/local/php-fpm/var/log/php-fpm.log [www] listen = /tmp/php-fcgi.sock listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 [[email protected] php-5.6.30]# /usr/local/php-fpm/sbin/php-fpm -t [08-Aug-2017 21:16:46] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
5、啟動php-fpm
[[email protected] php-fpm]# cp /usr/local/src/php-5.6.30/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [[email protected] php-fpm]# chmod 755 /etc/init.d/php-fpm [[email protected] php-fpm]# chkconfig --add php-fpm [[email protected] php-fpm]# chkconfig php-fpm on [[email protected] php-fpm]# service php-fpm start Starting php-fpm done [[email protected] php-fpm]# ps aux|grep php-fpm root 11303 0.0 0.4 123048 4936 ? Ss 21:20 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf) php-fpm 11304 0.0 0.4 123048 4700 ? S 21:20 0:00 php-fpm: pool www php-fpm 11305 0.0 0.4 123048 4700 ? S 21:20 0:00 php-fpm: pool www php-fpm 11306 0.0 0.4 123048 4700 ? S 21:20 0:00 php-fpm: pool www php-fpm 11307 0.0 0.4 123048 4700 ? S 21:20 0:00 php-fpm: pool www php-fpm 11308 0.0 0.4 123048 4704 ? S 21:20 0:00 php-fpm: pool www php-fpm 11309 0.0 0.4 123048 4704 ? S 21:20 0:00 php-fpm: pool www php-fpm 11310 0.0 0.4 123048 4704 ? S 21:20 0:00 php-fpm: pool www php-fpm 11311 0.0 0.4 123048 4704 ? S 21:20 0:00 php-fpm: pool www php-fpm 11312 0.0 0.4 123048 4704 ? S 21:20 0:00 php-fpm: pool www php-fpm 11313 0.0 0.4 123048 4704 ? S 21:20 0:00 php-fpm: pool www php-fpm 11314 0.0 0.4 123048 4704 ? S 21:20 0:00 php-fpm: pool www php-fpm 11315 0.0 0.4 123048 4704 ? S 21:20 0:00 php-fpm: pool www php-fpm 11316 0.0 0.4 123048 4704 ? S 21:20 0:00 php-fpm: pool www php-fpm 11317 0.0 0.4 123048 4704 ? S 21:20 0:00 php-fpm: pool www php-fpm 11318 0.0 0.4 123048 4708 ? S 21:20 0:00 php-fpm: pool www php-fpm 11319 0.0 0.4 123048 4708 ? S 21:20 0:00 php-fpm: pool www php-fpm 11320 0.0 0.4 123048 4708 ? S 21:20 0:00 php-fpm: pool www php-fpm 11321 0.0 0.4 123048 4708 ? S 21:20 0:00 php-fpm: pool www php-fpm 11322 0.0 0.4 123048 4708 ? S 21:20 0:00 php-fpm: pool www php-fpm 11323 0.0 0.4 123048 4708 ? S 21:20 0:00 php-fpm: pool www root 11325 0.0 0.0 112664 972 pts/0 R+ 21:21 0:00 grep --color=auto php-fpm
本文出自 “Gorilla City” 博客,請務必保留此出處http://juispan.blog.51cto.com/943137/1954974
LNMP-安裝MySQL和PHP