nginx+php7+mysql环境安装

来源:互联网 发布:21端口 编辑:程序博客网 时间:2024/04/28 16:14

1.安装pcre,官网地址http://www.pcre.org/
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre2-10.00.tar.gz
上述命令不可用,用迅雷下载下来放到/usr/local/src/目录下;
进入/usr/local/src/目录下:

tar -zxvf pcre2-10.00.tar.gz cd pcre2-10./configuremake make install

2.安装zlib库
下载最新版本的zlib1.2.8

wget http://zlib.net/zlib-1.2.8.tar.gztar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8/./configuremakemake install

3.安装openssl
卸载旧版本

apt-get purge opensslrm -rf /etc/sslcd /usr/local/srctar -zxvf openssl-1.1.0c.tar.gz./config  --prefix=/usr/local --openssldir=/usr/local/sslmakemake install

3.安装nginx最新稳定版
下载nginx安装包
下载地址:https://nginx.org/en/download.html

tar -zxvf nginx-1.10.2.tar.gz cd nginx-1.10.2/./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/src/pcre2-10.00 --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre-jit && \make 

出现如下错误:

    && make libpcre.lamake[2]: Entering directory `/usr/local/src/pcre2-10.00'make[2]: *** No rule to make target `libpcre.la'.  Stop.make[2]: Leaving directory `/usr/local/src/pcre2-10.00'make[1]: *** [/usr/local/src/pcre2-10.00/.libs/libpcre.a] Error 2make[1]: Leaving directory `/usr/local/src/nginx-1.10.2'make: *** [build] Error 2

利用下面的方式解决:

mkdir -p /usr/local/src/pcre2-10.00/.libscp /usr/local/lib/libpcre2-8.a /usr/local/src/pcre2-10.00/libpcre.acp /usr/local/lib/libpcre2-8.la /usr/local/src/pcre2-10.00/libpcre.lacp /usr/local/lib/libpcre2-8.la /usr/local/src/pcre2-10.00/.libs/libpcre.lacp /usr/local/lib/libpcre2-8.a /usr/local/src/pcre2-10.00/.libs/libpcre.a

又出现如下错误:

src/core/ngx_regex.c:305:15: error: ‘PCRE_STUDY_JIT_COMPILE’ undeclared (first use in this function)src/core/ngx_regex.c:305:15: note: each undeclared identifier is reported only once for each function it appears insrc/core/ngx_regex.c:355:31: error: ‘PCRE_INFO_JIT’ undeclared (first use in this function)src/core/ngx_regex.c: In function ‘ngx_regex_pcre_jit’:src/core/ngx_regex.c:420:21: error: ‘PCRE_CONFIG_JIT’ undeclared (first use in this function)cc1: all warnings being treated as errorsmake[1]: *** [objs/src/core/ngx_regex.o] Error 1make[1]: Leaving directory `/usr/local/src/nginx-1.10.2'make: *** [build] Error 2

最后取出那个pcre模块发现可以安装成功下面是配置:

./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-zlib=/usr/local/src/zlib-1.2.8makemake install

启动服务测试
找到安装位置/usr/local/nginx运行./nginx 报错
./nginx: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
使用下面命令添加链接:

ln -s /usr/local/lib/libssl.so.1.1 /usr/lib/libssl.so.1.1ln -s /usr/local/lib/libcrypto.so.1.1 /usr/lib/libcrypto.so.1.1

启动服务

cd /usr/local/nginx/./nginx -c nginx.confps -ef | grep nginx 
root     10747     1  0 22:47 ?        00:00:00 nginx: master process ./nginx -c nginx.confnobody   10748 10747  0 22:47 ?        00:00:00 nginx: worker processroot     10750 32696  0 22:48 pts/0    00:00:00 grep --color=auto nginx

访问80端口,看到welcome to nginx
查看版本 ./nginx -v 显示 1.10.2
增加扩展 pcre模块时出现各种问题,引起该问题的主要原因是pcre不能是pcre2,必须是pcre,所以重新下载pcre源码包进行解压。进入/nginx源码目录执行以下命令进行安装:

./configure --prefix=/usr/local/nginx  --with-http_realip_module --with-http_sub_module --with-http_flv_module --with-http_dav_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_addition_module --with-openssl=/usr/local/src/openssl-1.1.0c --with-http_ssl_module --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.39makemake install

4.安装php5.6.28
下载源码包:
http://php.net/get/php-5.6.28.tar.gz/from/a/mirror
解压配置安装:

tar -zxvf php-5.6.28.tar.gzcd php-5.6.28/./configure --prefix=/usr/local/server/php --with-config-file-path=/usr/local/server/php--enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr--with-png-dir=/usr --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl-dir=/usr--with-openssl --with-pdo-mysql=mysqlnd --with-pear --enable-sockets--with-freetype-dir=/usr --enable-gd-native-ttf --with-zlib--with-libxml-dir=/usr --with-xmlrpc --enable-zip --enable-fpm --enable-fpm--enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip--with-freetype-dir=/usr/lib/ --enable-soap --enable-pcntl --enable-cli

配置错误:
configure: error: xml2-config not found. Please check your libxml2 installation.

error: Cannot find OpenSSL’s

./configure --prefix=/usr/local/server/php --with-config-file-path=/usr/local/server/php--enable-mbstring --enable-ftp --with-gd --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pear --enable-sockets--with-freetype-dir=/usr --enable-gd-native-ttf --with-zlib--with-libxml-dir=/usr --with-xmlrpc --enable-zip --enable-fpm --enable-fpm--enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip--with-freetype-dir=/usr/lib/ --enable-soap --enable-pcntl --enable-cliapt-get install libpng12-devmakemake install

安装完成后修改php-fpm配置进行启动

/usr/local/src/php-5.6.28# cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm/usr/local/src/php-5.6.28# chmod +x /etc/init.d/php-fpm/usr/local/src/php-5.6.28# cd /usr/local/server/php/etc/usr/local/server/php/etc# cp php-fpm.conf.default php-fpm.conf/usr/local/server/php/etc# mv php-fpm.conf.default php-fpm.conf.default.bak/usr/local/server/php/etc# vi php-fpm.conf

打开25行注释,修改user名及组为root

[global]; Pid file; Note: the default prefix is /usr/local/server/php/var; Default Value: nonepid = run/php-fpm.pid; Unix user/group of processes; Note: The user is mandatory. If the group is not set, the default user's group;       will be used.user = rootgroup = root

报错如下:
Starting php-fpm [26-Nov-2016 14:04:37] ERROR: [pool www] please specify user and group other than root
测试以下方法:

/etc/init.d/php-fpm stop nohup /usr/sbin/php-fpm -R >/dev/null 2>&1 &  [1] 32631 echo "nohup /usr/sbin/php-fpm -R >/dev/null 2>&1 &" >> /etc/rc.local [1]+  Exit 127                nohup /usr/sbin/php-fpm -R > /dev/null 2>&1  cd /usr/local/src/php-5.6.28/  cp -f php.ini-production /usr/local/server/php/etc/php.ini  chmod 644 /usr/local/server/php/etc/php.ini  cp /usr/local/server/php/bin/php /usr/bin/php  php -v  PHP 5.6.28 (cli) (built: Nov 26 2016 12:44:52) Copyright (c) 1997-2016 The PHP GroupZend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

php新版本编译安装完成
5.安装mysql5.6

apt-get install python-software-propertiesapt-add-repository ppa:ondrej/mysql-5.6apt-get updateapt-get install mysql-server-5.6 mysql-client-5.6

出现如下错误:

/etc/apparmor.d/usr.sbin.mysqld at line 9: Could not open 'abstractions/mysql'

用下面的方法解决该问题并提示数据库重新启动成功

apt-get remove apparmor Setting up mysql-server-5.6 (5.6.32-1+deb.sury.org~precise+0.1) ...mysql start/running, process 4440mysql -u root -pPASSWORD:

通过上面方式查看mysql信息
6.配置nginx调用php-fpm去访问php文件
1.配置php-fpm的用户

/usr/local/server/php/etc# vi php-fpm.confuser www-datagroup www-dataphp-fpm 关闭kill -INT cat /usr/local/php/var/run/php-fpm.pidphp-fpm 重启kill -USR2 cat /usr/local/php/var/run/php-fpm.pid查看php-fpm进程数ps aux | grep -c php-fpm

2.配置nginx.conf文件

    server {        listen       80;        server_name  localhost;        #charset koi8-r;        #access_log  logs/host.access.log  main;        location / {            root   /var/www/nginx;            index  index.php index.html index.htm;        }        #error_page  404              /404.html;        # redirect server error pages to the static page /50x.html        #        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }        # proxy the PHP scripts to Apache listening on 127.0.0.1:80        #        #location ~ \.php$ {        #    proxy_pass   http://127.0.0.1;        #}        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000        #        location ~ \.php$ {            include        /usr/local/nginx/fastcgi_params;            root           /var/www/nginx;            fastcgi_pass   127.0.0.1:9000;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME  /var/www/nginx$fastcgi_script_name;        }        # deny access to .htaccess files, if Apache's document root        # concurs with nginx's one        #        #location ~ /\.ht {        #    deny  all;        #}    }

利用命令

./nginx -c nginx.conf

重启nginx然后给相应的路径附权:

 chmod -R 755 /var/www/nginx/

写index.php文件

<?phpphpinfo()?>

将文件放入上述设置的路径内
最后配置两个服务开机自动启动,配置方法参考如下链接:
https://my.oschina.net/yearnfar/blog/284862
4.安装phpmyadmin启动时出现问题,然后重新安装扩展mbstring之后,修改好php.ini,phpinfo不能加载扩展模块,是由于php-fpm启动时没有加载php.ini,修改开机启动服务的shell文件,让php-fpm启动时加载php.ini。然后再修改php.ini中的mysql.sock文件的默认生成位置,并将位置使用ln指令连接到/tmp下,才能正确打开phpmyadmin.
php.ini

extension=mbstring.sopdo_mysql.default_socket=/var/run/mysqld
/tmp# ln -s /var/run/mysqld/mysqld.sock mysql.sock

以上的方法会由于/tmp的清楚将连接的内容给删除掉,导致打开数据库出错。
你可以在php.ini修改下述3个地方将php的mysql扩展sock路径写进去;

    pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock     mysql.default_socket=/var/run/mysqld/mysqld.sock     mysqli.default_socket = /var/run/mysqld/mysqld.sock     chmod -R 755 /var/run/mysqld/
0 0
原创粉丝点击