首页 > 代码库 > LNMP-安装MySQL和PHP
LNMP-安装MySQL和PHP
和LAMP不同的是,提供web服务的是Nginx,并且php是作为一个独立服务存在的,这个服务叫做php-fpm。Nginx直接处理静态请求,动态请求会转发给php-fpm。因此,在静态页面的处理上,Nginx较Apache更胜一筹。
安装MySQL
1、下载并解压
[root@juispan src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz [root@juispan src]# tar zxf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz [root@juispan src]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
2、创建用户与文件夹
[root@juispan src]# cd /usr/local/mysql [root@juispan mysql]# useradd mysql [root@juispan mysql]# mkdir /data/
3、初始化数据库
[root@juispan mysql]# yum install -y perl perl-Data-Dumper libaio libaio-devel [root@juispan mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
4、拷贝启动脚本文件
[root@juispan mysql]# cp support-files/my-default.cnf /etc/my.cnf cp:是否覆盖"/etc/my.cnf"? y [root@juispan mysql]# cp support-files/mysql.server /etc/init.d/mysqld
5、启动MySQL
[root@juispan mysql]# vi /etc/init.d/mysqld basedir=/usr/local/mysql datadir=/data/mysql [root@juispan mysql]# chkconfig --add mysqld [root@juispan mysql]# chkconfig mysqld on [root@juispan mysql]# service mysqld start Starting MySQL.Logging to ‘/data/mysql/juispan.err‘. SUCCESS!
安装PHP
1、下载并解压
[root@juispan mysql]# cd /usr/local/src [root@juispan src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz [root@juispan src]# tar zxf php-5.6.30.tar.gz
2、配置php
[root@juispan src]# useradd -s /sbin/nologin php-fpm [root@juispan src]# cd php-5.6.30 [root@juispan 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.
[root@juispan php-5.6.30]# yum install -y libxml2-devel
问题2:configure: error: Cannot find OpenSSL‘s <evp.h>
[root@juispan php-5.6.30]# yum install -y openssl-devel
问题3:configure: error: Please reinstall the BZip2 distribution
[root@juispan php-5.6.30]# yum install -y bzip2-devel
问题4:configure: error: jpeglib.h not found.
[root@juispan php-5.6.30]# yum install -y libjpeg-turbo-devel
问题5:configure: error: png.h not found.
[root@juispan php-5.6.30]# yum install -y libpng-devel
问题6:configure: error: freetype-config not found.
[root@juispan php-5.6.30]# yum install -y freetype-devel
问题7:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
[root@juispan 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/
[root@juispan 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、编译与安装
[root@juispan php-5.6.30]# make [root@juispan php-5.6.30]# make install
4、调整php-fpm配置
[root@juispan php-5.6.30]# cp php.ini-production /usr/local/php-fpm/etc/php.ini [root@juispan 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 [root@juispan 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
[root@juispan php-fpm]# cp /usr/local/src/php-5.6.30/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@juispan php-fpm]# chmod 755 /etc/init.d/php-fpm [root@juispan php-fpm]# chkconfig --add php-fpm [root@juispan php-fpm]# chkconfig php-fpm on [root@juispan php-fpm]# service php-fpm start Starting php-fpm done [root@juispan 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