安装lnmp环境

注意需要wget的包都已经在source文件夹中存在,可直接下载安装(不过都是tar包,注意使用 tar -zxvf解压)

安装nginx依赖

yum install gcc zlib-devel pcre-devel openssl-devel gcc-c++ gcc-g77

安装nginx

wget http://nginx.org/download/nginx-1.4.7.tar.gz
tar -zxvf nginx-1.4.7.tar.gz
cd nginx-1.4.7
./configure --prefix=/usr/local/nginx --with-openssl=/usr/include/openssl --with-pcre --with-http_stub_status_module && make && make install
useradd www
groupadd www
useradd -g www www
启动nginx
/usr/local/nginx/sbin/nginx
查看端口是否启动
ss -tlun | grep 80  或者 netstat -antlp ¦ grep 80

安装mysql依赖

yum install ncurses-devel perl-Data-Dumper.x86_64 libaio*

安装mysql(因为下载的包是已经编译好的,所以直接初始化就好了)

wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
useradd -M -s /sbin/nologin mysql # -M 不添加家目录,-s不能指定shell登录

tar -zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
cp -R mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz /usr/local/mysql
初始化数据库
cd /usr/local/mysql
chown -R mysql:mysql ./
scripts/mysql_install_db --user=mysql
chown -R root:root ./

cp support-files/mysql.server /etc/init.d/mysqld        #复制启动脚本
chmod +x /etc/init.d/mysqld                             #添加执行权限
添加用户
mysqladmin -u root password "123123"                   #账号为root密码为123123
添加mysql软连接,php编译安装的时候依赖
ln -s /usr/local/mysql/lib/mysql/lib* /usr/lib/         
ln -s /usr/local/mysql/lib/mysql/lib* /usr/lib64/
启动mysql检查端口启动
service mysqld start
netstat -antlp ¦ grep 3306 或者 ss -tlun | grep 3306

安装php依赖

安装libmcrypt
wget -O libmcrypt-2.5.8.tar.bz2 http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2/download
tar -jxvf libmcrypt-2.5.8.tar.bz2
cd libmcrypt-2.5.8
./configure && make && make install
安装mhash
wget -O mhash-0.9.9.9.tar.bz2 http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2/download
tar -jxvf mhash-0.9.9.9.tar.bz2
cd mhash-0.9.9.9
./configure && make && make install
解决mcrypt依赖
ln -s /usr/local/lib/libmcrypt* /usr/lib
ln -s /usr/local/lib/libmcrypt* /usr/lib64
ln -s /usr/local/lib/libmhash.* /usr/lib/
ln -s /usr/local/lib/libmhash.* /usr/lib64/
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
ln -s /usr/lib64/liblber* /usr/lib/
ln -s /usr/lib64/liblber* /usr/lib64/

安装mcrypt

wget -O mcrypt-2.6.8.tar.gz http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/download
tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure && make && make install
解决php其他依赖
yum install -y gcc gcc-c++  make zlib zlib-devel pcre pcre-devel  libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libxslt-devel autoconf
ln -s /usr/lib64/libldap* /usr/lib/
ln -s /usr/lib64/libldap* /usr/lib64/

安装freetype

理论上是在解决依赖的时候yum安装了freetype freetype-devel
wget https://jaist.dl.sourceforge.net/project/freetype/freetype2/2.6/freetype-2.6.tar.gz
tar -zxvf freetype-2.6.tar.gz
cd freetype-2.6
./configure --prefix=/usr/local/lib/freetype && make && make install
编辑 /etc/ld.so.conf 加入/usr/local/lib 再执行 ldconfig即可

安装php

wget -O php-7.0.14.tar.gz http://cn2.php.net/get/php-7.0.14.tar.gz/from/this/mirror
tar -jxvf php-7.0.14.tar.gz
cd php-7.0.14
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysqli=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql  --with-iconv-dir=/usr/local/ --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-zlib-dir --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-sysvshm --enable-inline-optimization --with-curl  --enable-mbregex  --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap=/usr/ --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --enable-opcache --enable-ftp --enable-calendar --with-xsl --with-gettext --enable-session --enable-ctype --with-kerberos --with-libdir=/lib/ --with-pcre-regex --enable-exif --with-bz2 && make && make install
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
ln -s /usr/local/php/bin/php /usr/bin/
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/demo.conf
/usr/local/php/sbin/php-fpm

编辑nginx配置文件

编辑/usr/local/nginx/conf/nginx.conf,添加解析php文件
location / {
    root   /data/htdocs;                           # 设置代码根目录     
    index  index.php index.html index.htm;         # 添加index.php的首页文件
}
添加如下代码,解析php文件,注意SCRIPT_FILENAME
location ~ \.php$ {
    fastcgi_pass        127.0.0.1:9000;
    fastcgi_index       index.php;
    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; #注意SCRIPT_FILENAME
    include fastcgi_params;
    include fastcgi.conf;
}
重启nginx /usr/local/nginx/sbin/nginx
在/data/htdocs中添加php文件测试

安装redis

yum install redis
redis-server &

添加reids拓展

下载php7对应的redis拓展
wget https://github.com/phpredis/phpredis/archive/php7.zip
unzip php7.zip
cd phpredis-php7/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config && make && make install
编辑配置文件,添加redis.so拓展
vim /usr/local/php/etc/php.ini
添加如下行:
extension=redis.so
重启nginx,php-fpm
查看安装结果
php -i | grep redis

安装yaf拓展(用不到yaf框架可以进行以下步骤)

wget pecl.php.net//get/yaf-3.0.4.tgz
tar -zxvf yaf-3.0.4.tgz
cd yaf-3.0.4
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config && make && make install
vim /usr/local/php/etc/php.ini
修改php.ini配置(添加如下配置)
[yaf]
extension=yaf.so
yaf.library=/data1/phplib
yaf.name_suffix=0
yaf.use_namespace=1
yaf.name_separator="_"
yaf.action_prefer=0
yaf.environ=dev

安装遇到的问题

/usr/bin/ld: ext/ldap/.libs/ldap.o: undefined reference to symbol 'ber_strdup'
/usr/lib64/liblber-2.4.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [sapi/cli/php] 错误 1
安装ldap的错误,如果不需要可以删除编译的ldap的部分,按照如下步骤解决该错误
执行./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc –with-mysqli=/usr/local/mysql/ –with-mysqli=/usr/local/mysql/bin/mysql_config –with-pdo-mysql –with-iconv-dir=/usr/local/ –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-zlib-dir –with-libxml-dir=/usr –enable-xml –disable-rpath –enable-bcmath –enable-shmop –enable-sysvsem –enable-sysvshm –enable-inline-optimization –with-curl –enable-mbregex –enable-fpm –enable-mbstring –with-mcrypt –with-gd –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl –enable-sockets –with-ldap=/usr/ –with-ldap-sasl –with-xmlrpc –enable-zip –enable-soap –enable-opcache –enable-ftp –enable-calendar –with-xsl –with-gettext –enable-session –enable-ctype –with-kerberos –with-libdir=/lib/ –with-pcre-regex –enable-exif –with-bz2
编辑php目录下的Makefile文件,找到”EXTRA_LIBS =”开头的这一行,在行尾添加-llber
坚持原创技术分享,您的支持将鼓励我继续创作!