前言
最近感觉nginx比apache好,不要问我为什么,我就是这么认为的,我也不知道为什么。。。以下所有代码均为我自己安装时的命令,按照顺序Ctrl+c
Ctrl+v
期间敲几个yes
就完成了。注意:以下安装步骤及命令仅在全新服务器测试安装,服务器上已有数据的同僚请不要轻易试探
更新系统
yum -y update
安装 nginx
yum install epel-release
yum install nginx
systemctl start nginx
systemctl enable nginx
安装 mariadb
yum install mariadb-server mariadb
systemctl start mariadb
- 配置数据库
mysql_secure_installation
systemctl enable mariadb
- 验证数据库
mysql -uroot -p
安装php
yum install epel-release
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils
yum-config-manager --enable remi-php72
yum install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php72w* --skip-broken //完整安装
yum install php72-php-pecl-zip* //安装包中貌似没有包含php扩展,但是项目中必用到,建议执行安装
yum install php-pecl-zip.x86_64 //同上
- 修改php.ini配置
sudo sed -i 's/memory_limit.*/memory_limit = 128M/g' /etc/php.ini
sudo sed -i 's/upload_max_filesize.*/upload_max_filesize = 128M/g' /etc/php.ini
sudo sed -i 's/post_max_size.*/post_max_size = 128M/g' /etc/php.ini
sudo sed -i 's/max_execution_time.*/max_execution_time = 30000/g' /etc/php.ini
sudo sed -i 's/max_input_time.*/max_input_time = 30000/g' /etc/php.ini
sudo sed -i 's/;date.timezone =/date.timezone = Asia\/Shanghai/g' /etc/php.ini
sudo sed -i 's/; max_input_vars.*/max_input_vars = 1500/g' /etc/php.ini
systemctl start php-fpm
systemctl enable php-fpm
配置php
vim /etc/php-fpm.d/www.conf
找到以下地方进行替换
# 找到以下地方进行替换: listen.owner = nginx listen.group = nginx user = nginx group = nginx
配置nginx
vim /etc/nginx/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 2048; include /etc/nginx/mime.types; default_type application/octet-stream; include /etc/nginx/conf.d/*.conf; index index.php index.html index.htm; server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /var/www/html; include /etc/nginx/default.d/*.conf; location / { } location ~ .php$ { try_files $uri =404; root /var/www/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi.conf; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } }
配置虚拟主机
vim /etc/nginx/conf.d/typo3.whongbin.cn.conf
注意:使用composer进行安装时,需要将虚拟主机web目录设置到项目目录中的public目录才可以,解压安装的可以直接配置到项目目录
示例:
server { listen 80; server_name typo3.whongbin.cn; root /var/www/html/typo3.whongbin.cn/public; location / { } location ~ .php$ { try_files $uri =404; root /var/www/html/typo3.whongbin.cn/public; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi.conf; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
重载配置
nginx -t
nginx -s reload
cd /var/www/html/
- 切换用户安装 typo3 v9
useradd composer
passwd composer
composer config -g repo.packagist composer https://packagist.phpcomposer.com
su root
cd /var/www/html/my.whongbin.cn/
composer create-project typo3/cms-base-distribution typo3.whongbin.cn ^9.5
chown -R nginx:nginx /var/www/html/
chmod -R 775 /var/www/html/
cd /var/www/html/typo3.whongbin.cn/public/ & touch FIRST_INSTALL
重载php服务
为了保险起见,最后配置完成后把服务都重启下
service restart php-fpm
nginx -s reload
最后
整个安装过程大概半小时左右吧,时间浪费比较多的是 安装composer 的时候,毕竟composer是国外的服务,国内安装起来毕竟隔道墙,安装完成后建议把源换成国内的,否则你可能会渐渐的对Linux失去兴趣
评论 (0)