首页 技术 正文
技术 2022年11月14日
0 收藏 648 点赞 4,316 浏览 12135 个字

Nginx安装

#Nginx
[root@localhost downloads]# pwd
/root/downloads
#安装依赖pcre
[root@localhost downloads]# wget https://ftp.pcre.org/pub/pcre/pcre-8.30.tar.gz --no-check-certificate
[root@localhost downloads]# tar zxf pcre-8.30.tar.gz
[root@localhost downloads]# cd pcre-8.30
[root@localhost pcre-8.30]# ./configure
[root@localhost pcre-8.30]# make && make install
#安装nginx
[root@localhost downloads]# wget http://nginx.org/download/nginx-1.12.2.tar.gz
[root@localhost downloads]# tar zxf nginx-1.12.2.tar.gz
[root@localhost downloads]# cd nginx-1.12.2
[root@localhost nginx-1.12.2]# useradd nginx -s /sbin/nologin -M
[root@localhost nginx-1.12.2]# yum -y install openssl*
[root@localhost nginx-1.12.2]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
[root@localhost nginx-1.12.2]# make && make install[root@localhost nginx-1.12.2]# /usr/local/nginx/sbin/nginx -t #查看语法是否正确
/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1:
cannot open shared object file: No such file or directory
[root@localhost nginx-1.12.2]# find / -name "libpcre.so.1"
/usr/local/lib/libpcre.so.1
/root/downloads/pcre-8.30/.libs/libpcre.so.1
[root@localhost nginx-1.12.2]# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib #加入
[root@localhost nginx-1.12.2]# ldconfig #修改生效
[root@localhost nginx-1.12.2]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[root@localhost nginx-1.12.2]# /usr/local/nginx/sbin/nginx #启动
[root@localhost nginx-1.12.2]# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 37289 root 6u IPv4 80050 0t0 TCP *:http (LISTEN)
nginx 37290 nginx 6u IPv4 80050 0t0 TCP *:http (LISTEN)

  

Mysql安装

#Mysql单实例安装
#准备工作
[root@localhost downloads]# groupadd mysql #创建组
[root@localhost downloads]# useradd -s /sbin/nologin mysql -g mysql -M #创建用户
[root@localhost downloads]# wget https://downloads.mysql.com/archives/get/file/mysql-5.5.32.tar.gz --no-check-certificate #下载mysql包
[root@localhost mysql-5.5.32]# yum -y install ncurses-devel ncurses #安装依赖#开始安装
[root@localhost mysql-5.5.32]# cmake ./ #检查编译环境
[root@localhost mysql-5.5.32]# make #编译
[root@localhost mysql-5.5.32]# make install #安装#初始化和配置数据库
[root@localhost mysql-5.5.32]# cd /usr/local/mysql/
[root@localhost mysql]# chown -R mysql:mysql .
[root@localhost mysql]# scripts/mysql_install_db --user=mysql #初始化数据库
[root@localhost mysql]# chown -R mysql:mysql ./data/
[root@localhost mysql]# chmod -R ug+rws .
[root@localhost mysql]# chown -R mysql /var/run/mysqld#配置数据库
[root@localhost mysql]# cat /etc/my.cnf
##
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
user=mysql
datadir=/var/lib/mysql
default-storage-engine=MyISAM
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
##
[root@localhost mysql]# bin/mysqld_safe --user=mysql & #启动数据库
[root@localhost mysql]# ls /var/lib/mysql/
ibdata1 ib_logfile0 ib_logfile1 mysql performance_schema test[root@localhost mysql]# bin/mysqladmin -uroot password 1123.com #修改root密码
[root@localhost mysql]# bin/mysql -uroot -p #访问数据库
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld #配置server启动脚本
[root@localhost mysql]# service mysqld start
Starting MySQL [确定]
#启动成功

  

Mysql基础命令

mysql> select user,host from mysql.user;
#查看用户mysql> select user,host from mysql.user\G;
*************************** 1. row ***************************
user: root
host: 127.0.0.1
*************************** 2. row ***************************
user: root
host: ::1
*************************** 3. row ***************************
user:
host: localhost
*************************** 4. row ***************************
user: root
host: localhost
4 rows in set (0.00 sec)
#竖着显示mysql> help drop
Many help items for your request exist.
To make a more specific request, please type 'help <item>',
where <item> is one of the following
topics:
ALTER TABLE
ALTER TABLESPACE
DEALLOCATE PREPARE
DROP DATABASE
DROP EVENT
DROP FUNCTION
DROP FUNCTION UDF
DROP INDEX
DROP LOGFILE GROUP
DROP PROCEDURE
DROP SERVER
DROP TABLE
DROP TABLESPACE
DROP TRIGGER
DROP USER
DROP VIEW
#寻求drop命令提示帮助mysql> drop user ''@'localhost';
Query OK, 0 rows affected (0.06 sec)mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| root | localhost |
+------+-----------+
3 rows in set (0.00 sec)
#删除用户并且查看#因为大写的'host'删不掉,所以我们可以用一下办法
mysql> delete from mysql.user where user='' and host='MASTER'; #删除来自mysql.user表中的user=''和host='MASTER'
Query OK, 0 rows affected (0.00 sec)

  

PHP安装

#安装依赖库
[root@localhost mysql]# yum -y install zlib libxml* libjpeg freetype libpng gd curl zlib-devel libxml2-devel libjpeg-devel freetype-devel gd-devel curl-devel openldap openldap-devel
[root@localhost php-5.6.33]# cp -frp /usr/lib64/libldap* /usr/lib/#安装libiconv库
[root@localhost downloads]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
[root@localhost downloads]# tar zxf libiconv-1.14.tar.gz
[root@localhost downloads]# cd libiconv-1.14
[root@localhost libiconv-1.14]# ./configure --prefix=/usr/local/libconv
[root@localhost libiconv-1.14]# make && make install#安装libmcrypt库
[root@localhost downloads]# wget https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download --no-check-certificate
[root@localhost downloads]# tar zxf libmcrypt-2.5.8.tar.gz
[root@localhost downloads]# cd libmcrypt-2.5.8
[root@localhost libmcrypt-2.5.8]# ./configure
[root@localhost libmcrypt-2.5.8]# make && make install
[root@localhost libmcrypt-2.5.8]# ldconfig
[root@localhost libmcrypt-2.5.8]# cd libltdl/
[root@localhost libltdl]# ./configure --enable-ltdl-install
[root@localhost libltdl]# make && make install
[root@localhost libltdl]# cd ../..#安装mhash加密扩展库
[root@localhost downloads]# wget https://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz/download --no-check-certificate
[root@localhost downloads]# tar zxf mhash-0.9.9.9.tar.gz
[root@localhost downloads]# cd mhash-0.9.9.9
[root@localhost mhash-0.9.9.9]# ./configure
[root@localhost mhash-0.9.9.9]# make && make install
[root@localhost mhash-0.9.9.9]# rm -rf /usr/lib/libmcrypt*
[root@localhost mhash-0.9.9.9]# rm -rf /usr/lib/libmhash*
[root@localhost mhash-0.9.9.9]# ln -s /usr/local/lib/libmcrypt.la /usr/lib/
[root@localhost mhash-0.9.9.9]# ln -s /usr/local/lib/libmcrypt.so /usr/lib/
[root@localhost mhash-0.9.9.9]# ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/
[root@localhost mhash-0.9.9.9]# ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/
[root@localhost mhash-0.9.9.9]# ln -s /usr/local/lib/libmhash.a /usr/lib/
[root@localhost mhash-0.9.9.9]# ln -s /usr/local/lib/libmhash.la /usr/lib/
[root@localhost mhash-0.9.9.9]# ln -s /usr/local/lib/libmhash.so /usr/lib/
[root@localhost mhash-0.9.9.9]# ln -s /usr/local/lib/libmhash.so.2 /usr/lib/
[root@localhost mhash-0.9.9.9]# ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/
[root@localhost mhash-0.9.9.9]# ln -s /usr/local/bin/libmcrypt-config /usr/bin/
[root@localhost mhash-0.9.9.9]# cd ..#安装mcrypt加密扩展库
[root@localhost downloads]# wget https://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/download --no-check-certificate
[root@localhost downloads]# tar zxf mcrypt-2.6.8.tar.gz
[root@localhost downloads]# cd mcrypt-2.6.8
[root@localhost mcrypt-2.6.8]# ldconfig
[root@localhost mcrypt-2.6.8]# ./configure
[root@localhost mcrypt-2.6.8]# make && make install
[root@localhost downloads]# cd ..#安装PHP
[root@localhost downloads]# wget http://cn2.php.net/get/php-5.6.33.tar.gz/from/this/mirror
[root@localhost downloads]# tar zxf php-5.6.33.tar.gz
[root@localhost downloads]# echo "/usr/local/mysql/lib" >> /etc/ld.so.conf
[root@localhost downloads]# ldconfig -v
[root@localhost downloads]# cd php-5.6.33
[root@locahost php-5.6.33]# yum -y install libxslt libxslt-devel
[root@locahost php-5.6.33]# ./configure --prefix=/usr/local/php5.6.33 --with-mysql=/usr/local/mysql/ --with-iconv-dir=/usr/local/libconv/ --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr/ --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --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 --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --enable-short-tags --enable-static --with-xsl --with-fpm-user=nginx --with-fpm-group=nginx --enable-ftp
[root@locahost php-5.6.33]# make && make install

  

配置PHP

[root@locahost php-5.6.33]# vimdiff php.ini-development php.ini-production
#查看不同php.ini-development #开发版
php.ini-production #生产环境#配置
[root@locahost php-5.6.33]# cp php.ini-production /usr/local/php5.6.33/etc/php.ini
[root@locahost php-5.6.33]# ln -s /usr/local/php5.6.33/etc/php.ini /etc/
[root@locahost php-5.6.33]# cd /usr/local/php5.6.33/
[root@locahost php5.6.33]# cp etc/php-fpm.conf.default etc/php-fpm.conf#配置php-fpm.conf
#;pid = run/php-fpm.pid
pid = pid = /var/run/php-fpm.pid
#;error_log = log/php-fpm.log
error_log = /var/log/php-fpm.log
#;log_level = notice
log_level = error
#;rlimit_files = 1024
rlimit_files = 32768 #文件描述符
#;listen.owner = nginx #监听的用户
listen.owner = nginx
#;listen.group = nginx #监听的组
listen.group = nginx
#pm.max_children = 5 #最大的进程数
pm.max_children = 1024
#pm.start_servers = 2
pm.start_servers = 16
#pm.min_spare_servers = 1 #最小空闲
pm.min_spare_servers = 5
#pm.max_spare_servers = 3 #最大空闲
pm.max_spare_servers = 20
#;pm.process_idle_timeout = 10s; #空闲超时
pm.process_idle_timeout = 10s;
#;pm.max_requests =500 #最大请求数
pm.max_requests = 2048
slowlog = log/$pool.log.slow
#;request_slowlog_timeout = 0
request_slowlog_timeout = 10[root@locahost php5.6.33]# mkdir log
[root@locahost php5.6.33]# sbin/php-fpm -t
[root@locahost php5.6.33]# sbin/php-fpm
[root@locahost php5.6.33]# cp sbin/php-fpm /etc/init.d/#修改etc/php.ini
找到:;date.timezone =修改为:date.timezone = PRC #设置时区找到:expose_php = On修改为:expose_php = Off #禁止显示php版本的信息找到:short_open_tag = Off修改为:short_open_tag = ON #支持php短标签找到opcache.enable=0修改为opcache.enable=1 #php支持opcode缓存找到:;opcache.enable_cli=1 #php支持opcode缓存修改为:opcache.enable_cli=0在最后一行添加:zend_extension=opcache.so #开启opcode缓存功能

配置并优化nginx配置文件

#配置nginx.conf使其支持php
[root@locahost nginx]# pwd
/usr/local/nginx/#nginx.conf
##############################################
user nginx nginx;
worker_processes 8;error_log /var/log/nginx/nginx_error.log crit;
pid /var/run/nginx.pid;
worker_rlimit_nofile 65535;events {
use epoll;
worker_connections 65535;
}http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on; fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k; gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on; include extra/www.conf;
include extra/blog.conf;
}
##############################################[root@locahost nginx]# mkdir conf/extra/
[root@locahost nginx]# touch conf/extra/www.conf conf/extra/blog.conf
[root@locahost nginx]# mkdir /var/log/nginx/#www.conf
##############################################
server {
listen 80;
server_name www.daniel.org;
index index.html index.php index.htm;
root /var/www/html/www/;
location ~.*\.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~.*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 365d;
}
location ~.*\.(js|css)?$ {
expires 365d;
}
access_log /var/log/nginx/www_access.log main;
error_log /var/log/nginx/www_error.log error;
}
###############################################blog.conf
##############################################
server {
listen 80;
server_name blog.daniel.org;
index index.html index.php index.htm;
root /var/www/html/blog/;
location ~.*\.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~.*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 365d;
}
location ~.*\.(js|css)?$ {
expires 365d;
}
access_log /var/log/nginx/blog_access.log main;
error_log /var/log/nginx/blog_error.log error;
}
##############################################[root@locahost nginx]# mkdir /var/www/html/www /var/www/html/blog
#启动nginx

  

测试连接mysql和php  

[root@locahost local]# cat /var/www/html/www/index.php
<?php
$link_id=mysql_connect('localhost','root','1123.com') or mysql_error();
if ($link_id) {
echo "mysql is ok!!";
}else{
echo mysql_error();
}
?>

  

提示:LNMP系列是在一起的,前三章看完后再删掉所有的东西


相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,493
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,133
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297