lnmp源代码安装配置(php7.1.33+nginx1.6.1+mysql5.6)可单独安装其中一项服务

centos 7
先设置端口开通

1)查看所有开启的端口

firewall-cmd --list-ports

2)开通80/8099/8098/8097端口 注意看你网址看通哪个端口

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=8098/tcp --permanent
firewall-cmd --zone=public --add-port=8099/tcp --permanent
firewall-cmd --zone=public --add-port=8097/tcp --permanent

3)重启防火墙命令

 firewall-cmd --reload

nginx安装教程:

  • 1)下载nginx1.6.1
    http://nginx.org/en/download.html

  • 2)移动文件到root下

mv nginx-1.16.1.tar.gz  /root/
cd /root
tar -xzvf nginx-1.16.1.tar.gz
  • 3)编译检查路径
cd  nginx-1.16.1
pwd
/root/nginx-1.16.1
  • 4)准备编译
./configure --prefix=/usr/local/nginx --with-http_ssl_module
 正确的应该是:
./configure --prefix=/usr/local/nginx --with-http_ssl_module  --with-http_stub_status_module

若编译前报错(requires the PCRE library)执行如下
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
若编译前报错(SSL modules require the OpenSSL library)
yum -y install openssl openssl-devel

没有问题显示
lnmp源代码安装配置(php7.1.33+nginx1.6.1+mysql5.6)可单独安装其中一项服务_第1张图片

  • 5)在/root/nginx目录执行编译安装
make && make install
  • 6)进入安装目录启动nginx
cd /usr/local/nginx
/usr/local/nginx/sbin/nginx
执行报错
nginx: [emerg] unknown directive "stub_status" in /home/oscf/nginx/conf/conf.d/ngx_metric.conf:
解决方法:在编译时加上
./configure --prefix=/home/oscf/nginx --with-http_stub_status_module
  • 7)查看nginx启动情况和占用端口
ps aux | grep nginx  运行情况
netstat -tlnp  端口

停止Nginx的三种方式

  1. 立即停止Nginx服务
/usr/local/nginx/sbin/nginx -s stop
  1. 完成当前任务后停止
/usr/local/nginx/sbin/nginx -s quit
  1. 杀死Nginx进程
killall nginx
  • 8)添加软连接加入环境变量
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
编辑.bash_profile文件
vim ~/.bash_profile
在.bash_profile文件末尾加入以下内容
export PATH=$PATH:/usr/local/nginx/sbin

lnmp源代码安装配置(php7.1.33+nginx1.6.1+mysql5.6)可单独安装其中一项服务_第2张图片

引用.bash_profile文件
source ~/.bash_profile

启动nginx
nginx
停止nginx
nginx -s quit

安装PHP7.1.33 7.1.x(x最高版本)

  • 1)下载
 https://www.php.net/releases/

lnmp源代码安装配置(php7.1.33+nginx1.6.1+mysql5.6)可单独安装其中一项服务_第3张图片

  • 2)移动文件到root下
mv php-7.1.33.tar.gz  /root
cd /root
tar -xzvf php-7.1.33.tar.gz
  • 3)编译安装
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysqli --with-pdo-mysql --with-mysql-sock=/usr/local/mysql/mysql.sock --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-curl --with-gd --with-gmp --with-zlib --with-xmlrpc --with-openssl --without-pear --with-snmp --with-gettext --with-mhash --with-libxml-dir=/usr --with-ldap --with-ldap-sasl --with-fpm-user=nginx --with-fpm-group=nginx --enable-xml --enable-fpm  --enable-ftp --enable-bcmath --enable-soap --enable-shmop --enable-sysvsem --enable-sockets --enable-inline-optimization --enable-maintainer-zts --enable-mbregex --enable-mbstring --enable-pcntl --enable-zip --disable-fileinfo --disable-rpath --enable-libxml --enable-opcache --enable-mysqlnd 
编译报错(error: libxml2 not found. Please check your libxml2 installation.):
解决:yum install libxml2-devel
编译报错(./configure: line 23626: curl-dir: No such file or directory)
解决:yum install libcurl-devel
编译报错:checking whether to enable JIS-mapped Japanese font support in GD... no
If configure fails try --with-webp-dir=
If configure fails try --with-jpeg-dir=
configure: error: png.h not found
解决:
yum install libpng -y
yum install libpng-devel -y
yum install libjpeg libjpeg-devel
编译报错:freetype-config
yum install freetype freetype-devel
编译报错:Configure: error: Unable to locate gmp.h
yum install gmp-devel
编译报错:configure: error: Cannot find ldap.h
解决:yum install openldap openldap-devel
编译报错:Cannot find ldap libraries in /usr/lib
cp -frp /usr/lib64/libldap* /usr/lib/
编译报错:Could not find net-snmp-config binary. Please check your net-snmp installation
yum -y install net-snmp-devel
更多报错查看   https://www.jianshu.com/p/48d82e6f6834

成功显示

make报错(liblber-2.4.so.2: error adding symbols: DSO missing from command line)
解决:
遇到这种类似的情况,说明「./configure 」沒抓好一些环境变数值。解决方法,来自老外的一篇文章:
在PHP源码目录下 vi Makefile 找到 EXTRA_LIBS 行,在行末添加 ‘ -llber ‘ 保存退出再次make即可。
在这里插入图片描述
成功:
lnmp源代码安装配置(php7.1.33+nginx1.6.1+mysql5.6)可单独安装其中一项服务_第4张图片

  • 4)配置php配置文件
移动php配置文件的位置,并修改名称
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.conf
复制php.ini文件
cd  /root/php-7.1.33
cp ./php.ini-production /usr/local/php/etc/php.ini
复制php启动脚本到/etc/init.d/
cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
添加执行权限,添加到启动项并设置卡机启动
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
启动php-fpm
/etc/init.d/php-fpm start
启动报错( ERROR: [pool www] cannot get uid for user 'nginx'
[15-Jan-2020 15:19:04] ERROR: FPM initialization failed)
解决:修改php-fpm.conf里面的组
cd /usr/local/php/etc/
sudo vi php-fpm.conf  23行处

lnmp源代码安装配置(php7.1.33+nginx1.6.1+mysql5.6)可单独安装其中一项服务_第5张图片
执行:

/etc/init.d/php-fpm start

成功:
在这里插入图片描述

  • 6)nginx设置php配置和重启
vim /usr/local/nginx/conf/nginx.conf
    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /path$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
    }

lnmp源代码安装配置(php7.1.33+nginx1.6.1+mysql5.6)可单独安装其中一项服务_第6张图片
执行:

killall nginx
/usr/local/nginx/sbin/nginx
  • 5)编写php探测文件进行测试
[root@centos7_4 ~]# vim /usr/local/nginx/html/index.php

访问报错 File not found
 location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /script$fastcgi_script_name;
            include        fastcgi_params;
        }
 fastcgi_param  SCRIPT_FILENAME  /script$fastcgi_script_name;
改为
 fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

nginx配置yii2项目

  • 1)创建文件
cd /usr/local/nginx/conf
mkdir vhost
vim www.station-backend.conf
server
    {
        listen 8099;
        #listen [::]:80;
        server_name localhost;
        index index.html index.htm index.php default.html default.htm default.php;
        #root  /home/wwwroot/station-dev-backend/station-backend/api/web/;
        root /mnt/hgfs/rxyx-sys-2017/station-backend/api/web/;

        include rewrite/yii2.conf;
        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

   location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
}
        #include enable-php.conf;

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }
        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log off;
    }
cd /usr/local/nginx/conf
pwd    /usr/local/nginx/conf
mkdir rewrite
vim  rewrite/yii2.conf
location / {
    # Redirect everything that isn't a real file to index.php
    try_files $uri $uri/ /index.php$is_args$args;
}
vim /usr/local/nginx/conf/nginx.conf  加上include vhost/*.conf;

在这里插入图片描述

mysql安装

  • 1)下载源代码

https://dev.mysql.com/downloads/mysql/5.6.html

教程

https://www.cnblogs.com/dong3210/p/9627499.html
lnmp源代码安装配置(php7.1.33+nginx1.6.1+mysql5.6)可单独安装其中一项服务_第7张图片
下载需要账号 账号:[email protected] 密码:Qw5851*(自己的)**

  • 2)移动文件
mv mysql-5.6.47.tar.gz  /root
cd /root
  • 3)解压
tar -zxvf mysql-5.6.47.tar.gz
  • 4)yum安装准备软件
yum install openssl
yum install openssl-devel
yum install ncurses-devel
  • 5)创建mysql用户以及用户组
groupadd mysql
useradd -g mysql mysql -s /sbin/nologin
  • 4)cmake安装
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
  • 5)编译
make && make install
  • 6)编译成功后操作初始化
 cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data
  • 7)拷贝配置文件并编辑
cp support-files/my-default.cnf  /etc/my.cnf
vim /etc/my.cnf

[mysqld] 添加:

 datadir=/usr/local/mysql/data
 default-storage-engine=InnoDB
 lower_case_table_names=1
  • 8)设置环境变量
 vi /root/.bash_profile
 在修改PATH=$PATH:$HOME/bin为: PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib

source /root/.bash_profile //使刚才的修改生效
  • 9)#传统启动方式启动
bin/mysqld_safe --user=mysql &  
  • 10)制作成服务启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql  
service mysql start  
service mysql stop 

添加到开机启动项

chkconfig --add mysql

修改root密码(前提是mysql启动成功)

cd /usr/local/mysql 
./bin/mysqladmin -u root password 
mysql 账户访问授权及远程访问授权及密码修改
mysql -uroot  -p
mysql> use mysql;
 mysql> desc user;
 mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";    //为root添加远程连接的能力
 mysql> update user set Password = password('123456') where User='root';    //设置root用户密码
  mysql> select Host,User,Password from user where User='root';
 mysql> flush privileges;
  mysql> exit
 #至此mysql安装完成,进入mysql

你可能感兴趣的:(php,框架源码)