介绍:
LNMP就是:基于Linux、Nginx、Mysql、PHP的网站架构;网上有很多安装介绍;本文主要写在内网源码安装这些软件.
环境:
服务名称 | 版本号 | URL |
---|---|---|
Nginx | 1.14 | http://nginx.org/download/nginx-1.14.0.tar.gz |
Mysql | 5.6 | https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.40.tar.gz |
PHP | 5.5 | https://downloads.php.net/~stas/5.5/php-5.5.28.tar.gz |
服务安装:
- nginx安装
yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel -y
tar -xf nginx-1.14.0.tar.gz
cd nginx-1.14.0
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre
make && make install
vim /usr/local/nginx/vhost/server.conf
#添加以下php配置
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
- Mysql安装
yum install cmake* -y
tar -xf mysql-5.6.40.tar.gz
cd mysql-5.6.40
cmake -DCMAKE_INSTALL_PREFIX=/data/opt/mysql -DMYSQL_DATADIR=/data/opt/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1
make && make install
- 创建数据目录
mkdir -p /data/opt/mysql/{3306,binlog,tmp}
chown -R mysql.mysql /data/opt/mysql
- 配置
my.conf
文件
cp support-files/my-default.cnf /etc/my.conf
vim /etc/my.conf
[client]
port = 3306
socket = /data/opt/mysql/3306/mysql.sock
#The MySQL Server
[mysqld]
server-id=209
innodb_flush_log_at_trx_commit=1
sync_binlog=1
port = 3306
user = mysql
socket = /data/opt/mysql/3306/mysql.sock
pid-file = /data/opt/mysql/3306/mysql.pid
basedir = /data/opt/mysql
datadir = /data/opt/mysql/data
tmpdir = /data/opt/mysql/tmp
open_files_limit = 10240
lower_case_table_names=1
explicit_defaults_for_timestamp
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#Buffer
max_allowed_packet = 256M
max_heap_table_size = 256M
net_buffer_length = 8k
sort_buffer_size = 2M
join_buffer_size = 4M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
#Log
log-bin = /data/opt/mysql/binlog/mysql-bin
binlog_cache_size = 32M
max_binlog_cache_size = 512M
max_binlog_size = 512M
binlog_format = mixed
log_output = FILE
log-error = /data/opt/mysql/binlog/mysql-error.log
slow_query_log = 1
slow_query_log_file = /data/opt/mysql/binlog/slow_query.log
general_log = 0
general_log_file = /data/opt/mysql/binlog/general_query.log
expire-logs-days = 14
#InnoDB
innodb_data_file_path = ibdata1:2048M:autoextend
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_buffer_pool_size = 1024M
[mysql]
no-auto-rehash
prompt = (\u@\h)[\d]>\_
default-character-set = gbk
- 添加mysql环境变量
echo 'export PATH=$PATH:/data/opt/mysql/bin' >> /etc/profile && source /etc/profile
- 初始化数据库
cd /data/opt/mysql
./scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql
./bin/mysqld_safe --user=mysql &
- 添加到系统启动
cp /soft/mysql-5.6.40/support-files/mysql.server /etc/init.d/mysqld
chmod +x /ect/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
- Mysql默认配置优化,权限配置
mysql -uroot -p
#清空默认数据
(root@localhost)[(none)] > select * from mysql.db \G
(root@localhost)[(none)] > truncate table mysql.db;
(root@localhost)[(none)] > flush privileges;
(root@localhost)[(none)] > select * from mysql.db \G
#配置访问权限
(root@localhost)[(none)] > use mysql;
(root@localhost)[(none)] > desc user;
(root@localhost)[(none)] > grant all privileges on *.* to root@"%" identified by "root";
(root@localhost)[(none)] > update user set Password=password('XXXXXX') where User='root';
(root@localhost)[(none)] > select Host,User,Password from user where User='root';
(root@localhost)[(none)] > flush privileges;
(root@localhost)[(none)] > exit;
- php安装
- 编译安装
yum install -y gd gd-devel zlib zlib-devel libjpeg libjpeg-devel php-bcmath freetype freetype-devel libpng libpng-devel php-mbstring libxml2 libxml2-devel glibc glibc-devel bzip2 bzip2-devel libcurl libcurl-devel
tar -xf php-5.5.28.tar.gz
cd php-5.5.28
./configure --prefix=/usr/local/php --enable-mbstring --with-mysql --with-config-file-path=/usr/local/php/etc --with-bz2 --with-curl --enable-sockets --with-gd --enable-calendar --with-zlib --enable-gd-native-ttf --with-iconv --enable-calendar --enable-gd-native-ttf --enable-libxml --with-jpeg-dir --with-png-dir --enable-bcmath --with-freetype-dir --with-gettext --enable-fpm
make && make install
- 配置
cp php.ini-production /usr/local/php/etc/php.ini
rm -rf /etc/php.ini
ln -s /usr/local/php/etc/php.ini /etc/php.ini
ls -l /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
pid = run/php-fpm.pid //如果这个选项在配置文件存在就取消掉注释使用,如果不存在可以忽略,请勿手动添加,否则PHP启动会报错。
user = www
group = www
- 添加到系统启动
cp /usr/local/src/php-5.5.28/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
ls -l /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
ls -l /etc/init.d/php-fpm
chkconfig php-fpm on
chkconfig --list php-fpm
-
php.ini
配置
disable_functions= passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit,posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
date.timezone = PRC #设置时区
expose_php = Off #禁止显示php版本的信息
short_open_tag = On #支持php短标签
opcache.enable=1 #php支持opcode缓存
opcache.enable_cli=0
zend_extension=opcache.so #开启opcode缓存功能
网友评论