• VPS:阿里云
  • OS:centos 7 minimal
  • CMS:joomla 3.9

基本设置

#修改计算机名称
sudo hostnamectl set-hostname centos

#关闭selinux
sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config && \
sudo setenforce 0

#创建用户及设置密码
useradd hai -m && passwd hai

#添加sudo权限
sudo visudo
#大概100行左右,按照root格式添加
hai ALL=(ALL) ALL

#更新系统并安装基础工具
sudo yum update -y && sudo yum install vim wget yum-utils -y

添加nginx源

sudo cat > /etc/yum.repos.d/nginx.repo << eof

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
eof

添加remi(PHP72)源

#由于阿里云已经有了epel repository,需要先备份,不然被remi依赖的epel覆盖了
#装完在覆盖回来

#开启PHP7.2
sudo mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak && \
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm -y && \
sudo yum-config-manager --enable remi-php72 && \
sudo mv /etc/yum.repos.d/epel.repo.bak /etc/yum.repos.d/epel.repo

添加MariaDB源

sudo cat > /etc/yum.repos.d/mariadb.repo << eof
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
eof

安装LNMP

sudo yum install nginx php php-fpm php-gd php-curl php-mbstring php-mysql php-devel \
php-zlib php-xml php-json php-mcrypt php-zip mariadb-server memcached git unzip -y

配置nginx

sudo cat > /etc/nginx/conf.d/default.conf << eof
server {
    listen       80;
    server_name  localhost;
    server_name_in_redirect off;
    charset utf-8;

    access_log  /var/log/nginx/host.access.log;
    error_log /var/log/nginx/host.error.log info;
    root   /srv/www/htdocs/joomla;
    index  index.php index.html index.htm;  

    error_page  404              /404.html;
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /srv/www/htdocs/;
    }
    #Start Joomla Configure
    # Support Clean (aka Search Engine Friendly) URLs
    location / {
            try_files \$uri \$uri/ /index.php?\$args;
    }

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
    # deny running scripts inside writable directories
    location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
            return 403;
            error_page 403 /403_error.html;
    }
    # caching of files 
    location ~* \.(ico|pdf|flv)$ {
            expires 1y;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
            expires 14d;
    }
    #End Joomla Configure
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  \$document_root\$fastcgi_script_name;
        include        fastcgi_params;
    }
}
eof

编译php-memcached

传统pecl install php-memcached已经失效,不支持PHP7,但是官方字GitHub上有个仓库php-memcached GitHub

#如果出现错误提示
checking for zlib location... configure: error: memcached support requires ZLIB. Use --with-zlib-dir=<DIR> to specify the prefix where ZLIB headers and library are located
#则是zlib-devel没有安装
#安装依赖环境
sudo yum install libmemcached-devel libmemcached zlib-devel msgpack -y && \
git clone https://github.com/php-memcached-dev/php-memcached.git && \
cd php-memcached && phpize && \
sudo ./configure && \
sudo make && sudo make install && \
sudo echo 'extension=memcached.so' | tee /etc/php.d/memcached.ini

配置php.ini

sudo sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /etc/php.ini && \
sudo sed -i 's/max_input_time = 60/max_input_time = 300/g' /etc/php.ini && \
sudo sed -i 's/memory_limit = 128M/memory_limit = 512M/g' /etc/php.ini && \
sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /etc/php.ini && \
sudo sed -i 's/post_max_size = 8M/post_max_size = 50M/g' /etc/php.ini && \
sudo sed -i 's/;date.timezone =/date.timezone = Asia\/Shanghai/g' /etc/php.ini
# 最后一行有个转义符

配置php-fpm

sudo sed -i 's/user = apache/user = nginx/g' /etc/php-fpm.d/www.conf && \
sudo sed -i 's/group = apache/group = nginx/g' /etc/php-fpm.d/www.conf

配置session目录权限

sudo chown -R nginx:nginx /var/lib/php/session && \
sudo chmod -R 775 /var/lib/php/session

配置MariaDB

sudo systemctl start mariadb

expect << EOF

spawn mysql_secure_installation
expect "Enter current password for root (enter for none):"
send "\r"

expect "Set root password"
send "y\r"

expect "New password:"
send "123456\r"

expect "Re-enter new password:"
send "123456\r"

expect "Remove anonymous users? "
send "\r"

expect "Disallow root login remotely?"
send "\r"

expect "Remove test database and access to it?"
send "\r"

expect "Reload privilege tables now?"
send "\r"

expect eof
EOF

创建用户及所属数据库

mysql -uroot -p123456 << EOF
create database joomla_db;
create user joomla_u identified by '123456';
grant all privileges on joomla_db.* to joomla_u@'localhost' identified by '123456';
flush privileges;
quit
EOF

开启服务

sudo systemctl enable nginx php-fpm mariadb memcached && \
sudo systemctl start nginx && \
sudo systemctl start php-fpm && \
sudo systemctl start mariadb && \
sudo systemctl start memcached

安装joomla

官方下载页面

wget https://downloads.joomla.org/cms/joomla3/3-9-1/joomla_3-9-1-stable-full_package-zip?format=zip
#有时候下载完并没有修改后缀名,但不影响zip解压
unzip -d joomla joomla_3-9-1-stable-full_package-zip?format=zip
#-d joomla为解压到joomla目录
mv joomla /var/ww/html/

#设置权限
cd /var/www/html
sudo chown -R nginx:nginx joomla && \
sudo chmod -R 775 joomla

添加防火墙

sudo systemctl enable firewalld && \
sudo systemctl start firewalld && \
sudo firewall-cmd --add-service=http --permanent && \
sudo firewall-cmd --add-service=https --permanent && \
firewall-cmd --reload

使用memcached缓存

  • 缓存存储方法点选 memcached
  • 会话处理方式点选 memcached

1 个评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注

6 − 2 =