阿里云CentOS 7.4 配置Nginx、PHP、Mariadb
生活随笔
收集整理的這篇文章主要介紹了
阿里云CentOS 7.4 配置Nginx、PHP、Mariadb
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
阿里云CentOS 7.4 基本環境配置
添加 yum 第三方源
常用的第三方源有兩個:EPEL 和 IUS,可在 https://ius.io/GettingStarted/ 查看到最新的安裝方法
自動安裝
curl -L https://setup.ius.io | sh手動安裝(用了自動安裝,這個就省略)
$ wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm $ wget https://centos7.iuscommunity.org/ius-release.rpm$ rpm -ivh epel-release-latest-7.noarch.rpm $ rpm -ivh ius-release.rpm安裝完成更新yum源緩存
$ yum clean all $ yum makecache安裝開發工具包
$ yum -y groupinstall "Development Tools"升級系統軟件包
$ yum -y upgrade安裝 jemalloc
$ yum -y install jemalloc安裝 redis
$ yum -y install redis啟動redis服務并設置為自動啟動
$ systemctl enable redis $ systemctl start redis安裝 Mariadb 5.5.56
安裝 mariadb
$ yum -y install mariadb mariadb-server將mariadb的數據目錄移動到自定義位置
創建mariadb數據目錄
# -p 參數可以自動生成完整路徑,比如上面不存在/data目錄,會自動創建 mkdir -p /data/mariadb#修改目錄所有者 chown -R mysql:mysql /data/mariadb配置 mariadb
#備份 mariadb-libs生成的my.cnf mv /etc/my.cnf /etc/my.cnf.libs.back #從mariadb復制配置文件 cp /usr/share/mysql/my-large.cnf /etc/my.cnf修改 /etc/my.cnf
[mysqld] #設置數據目錄 datadir=/data/mariadb#添加字符集設置utf8 # setting character set init_connect = 'SET NAMES utf8' character-set-server = utf8 collation-server = utf8_unicode_ci skip-character-set-client-handshake#修改thread_concurrentcy為CPU數量*2 thread_concurrency = 2#添加mysqld_safe設置 [mysqld_safe] log-error = /var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid #添加jemalloc支持 malloc-lib=/usr/lib64/libjemalloc.so.1#最末尾添加包含配置目錄 !includedir /etc/my.cnf.d啟動 mariadb
$ systemctl start mariadb設置mariadb服務開機啟動
$ systemctl enable mariadb初始化mariadb
#修改mysql_secure_installation,否則會出現找不到sock文件的問題 #找到make_config函數在有[mysql]這句下方增加 echo "socket=/data/mariadb/mysql.sock" >> $config #保存退出$ mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here.Enter current password for root (enter for none): OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation.Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables..... Success!By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.Remove anonymous users? [Y/n] y... Success!Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] y... Success!By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.Remove test database and access to it? [Y/n] y- Dropping test database...... Success!- Removing privileges on test database...... Success!Reloading the privilege tables will ensure that all changes made so far will take effect immediately.Reload privilege tables now? [Y/n] y... Success!Cleaning up...All done! If you've completed all of the above steps, your MariaDB installation should now be secure.Thanks for using MariaDB!安裝 Nginx
$ yum -y install nginx #設置開機啟動 $ systemctl enable nginx修改systemctl啟動設置,避免無法找到pid文件的問題
$ mkdir -p /etc/systemd/system/nginx.service.d $ printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" > /etc/systemd/system/nginx.service.d/override.conf $ systemctl daemon-reload啟動 nginx
$ systemctl start nginx安裝 PHP 7.1
$ yum -y install php71u-fpm php71u-fpm-nginx $ yum -y install php71u-mbstring php71u-common php71u-gd php71u-mcrypt $ yum -y install php71u-mysqlnd php71u-xml php71u-cli php71u-devel $ yum -y install php71u-pecl-redis php71u-opcache修改/etc/nginx/conf.d/php-fpm.conf
upstream php-fpm {#server 127.0.0.1:9000;server unix:/run/php-fpm/www.sock; }修改/etc/php-fpm.d/www.conf
#修改php-fpm進程用戶 user = nginx group = nginx#修改網絡方式 ;listen = 127.0.0.1:9000 listen = /run/php-fpm/www.sock#修改生成sock的用戶 listen.owner = nginx listen.group = nginx listen.mode = 0666啟動php-fpm
$ systemctl enable php-fpm $ systemctl start php-fpm配置nginx虛擬主機
設置虛擬主機
# 添加虛擬主機配置目錄 $ mkdir -p /etc/nginx/vhosts.d修改nginx配置文件/etc/nginx/nginx.conf
# 在server配置后面添加 include /etc/nginx/vhosts.d/*.conf;到/etc/nginx/vhosts.d目錄創建 aaa.conf文件,假設www.aaa.com為域名
server {listen 80;server_name www.aaa.com;access_log /data/aaa/logs/access.log main;error_log /data/aaa/logs/error.log;charset utf-8;location / {try_files $uri $uri/ /index.php?q=$uri&$args;root /data/aaa/www;index index.php index.html index.htm;}# pass the PHP scripts to FastCGI server listening on Unix socketlocation ~ \.php$ {root /data/aaa/www;fastcgi_pass php-fpm;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}error_page 404 /404.html;location = /40x.html {}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# deny access to .htaccess files, if Apache's document root# concurs with nginx's onelocation ~ /\.ht {deny all;} }創建虛擬主機網頁存放目錄和日志目錄
$ mkdir -p /data/aaa/{logs,www}創建一個測試文件
echo "<?php phpinfo();" > /data/aaa/www/index.php重啟動nginx和php-fpm
$ systemctl restart nginx $ systemctl restart php-fpm用瀏覽器訪問域名看看是否看到phpinfo頁面
轉載于:https://my.oschina.net/u/2357619/blog/1612120
總結
以上是生活随笔為你收集整理的阿里云CentOS 7.4 配置Nginx、PHP、Mariadb的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 接口管理平台DOClever5.2.0
- 下一篇: 解锁新姿势 | 如何用配置中心实现全局动