一.部署nginx
1.安装
yum install nginx
systemctl enable nginx
systemctl start nginx
2.配置
server {
listen 80;
server_name xxxx; # 此为必修改项,请替换为服务器公网 IP 或域名
root /data/website/blog/public; # 此为必修改项,请注意指向站点根目录的 public 子目录
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
try_files $uri = 400;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
需要重启nginx systemctl restart nginx
二.部署php
1.安装php环境
yum install epel-release rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm yum install -y php php-devel php-fpm php-cli #安装相关模块 yum install php-bz2 php-soap php-zip php-opcache php-xmlrpc php-calendar php-json php-bcmath php-exif php-dom php-gettext php-gd php-json php-mbstring php-mysqli php-mysqlnd php-pdo php-pdo_mysql php-pdo_sqlite php-readline php-posix php-redis php-simplexml php-soap php-sqlite3 php-xml php-xmlreader php-xmlrpc php-xmlwriter php-zip #安装swoole模块 #需要将swoole.so模块配置到php.ini文件中 pecl install swoole phpize
2.配置php
www.conf配置
[www] user = nginx group = nginx listen = 127.0.0.1:9000 listen.backlog = 8129 listen.allowed_clients = 127.0.0.1 listen.owner = nginx listen.group = nginx listen.mode = 0666 pm = static pm.max_children = 10 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 5 pm.process_idle_timeout = 10s pm.max_requests = 1024 request_slowlog_timeout = 4 slowlog = var/log/slow.log request_terminate_timeout = 0 rlimit_files = 65535
php.ini配置
[PHP] engine = On short_open_tag = On precision = 14 output_buffering = 4096 zlib.output_compression = Off implicit_flush = Off unserialize_callback_func = serialize_precision = -1 disable_functions = disable_classes = zend.enable_gc = On expose_php = off max_execution_time = 300 max_input_time = 60 memory_limit = 4096M error_reporting = E_ALL display_errors = Off display_startup_errors = On log_errors = On log_errors_max_len = 1024 ignore_repeated_errors = Off ignore_repeated_source = Off report_memleaks = On html_errors = On variables_order = "GPCS" request_order = "GP" register_argc_argv = Off auto_globals_jit = On post_max_size = 50M 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 = 1024M max_file_uploads = 20 allow_url_fopen = On allow_url_include = Off cgi.fix_pathinfo = 0 default_socket_timeout = 60 extension=redis.so extension=swoole.so extension=bcmath.so zend_extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/opcache.so [CLI Server] cli_server.color = On [Date] [filter] [iconv] [intl] [sqlite3] [Pcre] [Pdo] [Pdo_mysql] pdo_mysql.cache_size = 2000 pdo_mysql.default_socket= [Phar] [mail function] SMTP = localhost smtp_port = 25 mail.add_x_header = Off [ODBC] odbc.allow_persistent = On
三.安装composer
php -r "copy(‘https://install.phpcomposer.com/installer‘, ‘composer-setup.php‘);" php composer-setup.php php -r "unlink(‘composer-setup.php‘);" mv composer.phar /usr/local/bin/composer
四.部署一个laravel应用
mkdir /data/website && cd /data/website composer create-project --prefer-dist laravel/laravel blog "5.8.*" cd /data/website/blog chmod -R 755 storage/ chmod -R 755 bootstrap/cache