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

沒有問題顯示
在這裏插入圖片描述

  • 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

在這裏插入圖片描述

引用.bash_profile文件
source ~/.bash_profile

啓動nginx
nginx
停止nginx
nginx -s quit

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

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

在這裏插入圖片描述

  • 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=<DIR>
If configure fails try --with-jpeg-dir=<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即可。
在這裏插入圖片描述
成功:
在這裏插入圖片描述

  • 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行處

在這裏插入圖片描述
執行:

/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;
    }

在這裏插入圖片描述
執行:

killall nginx
/usr/local/nginx/sbin/nginx
  • 5)編寫php探測文件進行測試
[root@centos7_4 ~]# vim /usr/local/nginx/html/index.php
<?php
        phpinfo();
?>
訪問報錯 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
在這裏插入圖片描述
下載需要賬號 賬號:[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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章