说明
绝大部分php网站的运行环境都是lnmp架构或者lamp架构。本教程分享lnmp架构的环境部署方法。
安装软件
# 配置yum源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# 安装软件
## mariadb-server
```
yum install -y mariadb mariadb-server
```
## php
```
#php5.6版本
yum -y install php56w php56w-cli php56w-fpm php56w-common php56w-devel php56w-embedded php56w-gd php56w-mbstring php56w-mysqlnd php56w-opcache php56w-pdo php56w-xml
#php7.2版本
yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
```
## nginx
```
yum install -y nginx
```
配置文件
mariadb配置my.cnf
[client]
default-character-set = utf8
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[galera]
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[mysql]
[isamchk]
key_buffer = 16M
!include /etc/mysql/mariadb.cnf
!includedir /etc/mysql/conf.d/
#mysqld设置
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
log-error = /var/lib/mysql/mariadb.log
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc_messages_dir = /usr/share/mysql
character-set-server = utf8
lc_messages = en_US
skip-external-locking
max_connections = 500
max_user_connections= 100
connect_timeout = 5
max_connect_errors = 100
wait_timeout = 600
max_allowed_packet = 16M
thread_cache_size = 128
sort_buffer_size = 4M
bulk_insert_buffer_size = 16M
tmp_table_size = 128M
max_heap_table_size = 32M
myisam_recover_options = BACKUP
key_buffer_size = 128M
table_open_cache = 400
myisam_sort_buffer_size = 512M
concurrent_insert = 2
read_buffer_size = 2M
read_rnd_buffer_size = 1M
query_cache_limit = 128K
query_cache_size = 64M
#慢查询日志配置
slow-query-log = on
long_query_time = 10
slow_query_log_file = /var/log/mysql/mariadb-slow.log
#引擎配置
default_storage_engine = InnoDB
innodb_buffer_pool_size = 2048M
innodb_log_file_size = 128M
innodb_log_buffer_size = 16M
innodb_file_per_table = 1
innodb_open_files = 400
innodb_io_capacity = 400
innodb_flush_method = O_DIRECT
innodb_data_home_dir = /var/lib/mysql
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /var/lib/mysql
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
#新增配置
net_buffer_length = 8K
explicit_defaults_for_timestamp = true
open_files_limit = 65535
#主主配置
log-bin=mysql-bin
max_binlog_size = 100M
expire_logs_days = 10
binlog_cache_size = 1M
binlog_format = mixed
read-only = 0
relay_log = mysql-relay-bin
log-slave-updates = ON
##和m2区别
server-id = 1
auto-increment-offset = 1
auto-increment-increment = 2
php-fpm配置
包含3个配置文件: php-fpm.conf,php.ini,www.conf
php-fpm.conf
[global]
pid = /var/run/php-fpm/php-fpm.pid
error_log = /data/log/php-fpm/error.log
daemonize = yes
include=/etc/php-fpm.d/*.conf
php.ini
[PHP]
engine = On
short_open_tag = Off
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = 17
disable_functions =
disable_classes =
zend.enable_gc = On
expose_php = On
max_execution_time = 30
max_input_time = 60
memory_limit = 128M
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
html_errors = On
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 256M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
doc_root =
user_dir =
enable_dl = Off
file_uploads = On
upload_max_filesize = 2M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
[CLI Server]
cli_server.color = On
[Date]
[filter]
[iconv]
[intl]
[sqlite]
[sqlite3]
[Pcre]
pcre.jit=0
[Pdo]
[Pdo_mysql]
pdo_mysql.cache_size = 2000
pdo_mysql.default_socket=
[Phar]
[mail function]
sendmail_path = /usr/sbin/sendmail -t -i
mail.add_x_header = On
[SQL]
sql.safe_mode = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[Interbase]
ibase.allow_persistent = 1
ibase.max_persistent = -1
ibase.max_links = -1
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
ibase.dateformat = "%Y-%m-%d"
ibase.timeformat = "%H:%M:%S"
[MySQLi]
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.cache_size = 2000
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = Off
[PostgreSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[bcmath]
bcmath.scale = 0
[browscap]
[Session]
session.save_handler = files
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
[Assertion]
zend.assertions = -1
[mbstring]
[gd]
[exif]
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
[sysvshm]
[ldap]
ldap.max_links = -1
[mcrypt]
[dba]
[curl]
[openssl]
[opcache]
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.validate_timestamps=0
opcache.file_cache=/tmp
www.conf
[www]
listen = /var/run/php-fpm/php-fpm.sock
;listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
listen.backlog = 16384
user = nginx
group = nginx
pm = static
pm.max_children = 20
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 35
pm.max_requests = 10000
request_terminate_timeout = 180
request_slowlog_timeout = 30
slowlog = /data/log/php-fpm/www-slow.log
;access.log = /data/log/php-fpm/access.$pool.log
;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{seconds}d %{megabytes}M %{user}C%%"
ping.path = /php5fpm-ping
pm.status_path = /php5fpm-status
nginx配置
主配置文件为:nginx.conf,每个虚拟主机可建立多个子配置文件放到/etc/nginx/conf.d/下。下面为nginx+php配置示例:
nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html/phpmb;
# Load configuration files for the default server block.
#include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location / {
# 这里改动了 定义首页索引文件的名称
index index.php index.html index.htm;
}
location ~ \.php$ {
# 设置监听端口
fastcgi_pass 127.0.0.1:9000;
# 设置nginx的默认首页文件(上面已经设置过了,可以删除)
fastcgi_index index.php;
# 设置脚本文件请求的路径
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# 引入fastcgi的配置文件
include fastcgi_params;
}
}
}
启动服务
systemctl enable --now mariadb php-fpm nginx
数据库初始化
mysql_secure_installation
声明:
1.M商城虚拟资源部分由用户自行上传,如果侵犯了您的合法权益,请联系客服QQ:1940728253处理,我们会第一时间给予删除。
2.部分作品由M商城进行二次创作修改,转载请注明!
3.本站资源仅供学习、参考交流之用,我们不保证内容的长久可用性。 4.若用于商业用途,请去官网购买正版授权,否则产生的一切后果将由下载用户自行承担。
1.M商城虚拟资源部分由用户自行上传,如果侵犯了您的合法权益,请联系客服QQ:1940728253处理,我们会第一时间给予删除。
2.部分作品由M商城进行二次创作修改,转载请注明!
3.本站资源仅供学习、参考交流之用,我们不保证内容的长久可用性。 4.若用于商业用途,请去官网购买正版授权,否则产生的一切后果将由下载用户自行承担。