search
HomeBackend DevelopmentPHP ProblemHow to implement one-click installation of centos PHP

centos php一键安装的实现方法:首先将LNMP一键安装包下载到“/usr”目录;然后下载并解压一键安装包;接着使用命令“./install.sh”执行安装脚本;最后创建站点并配置伪静态即可。

How to implement one-click installation of centos PHP

本次演示系统是 centos 7.0  64位

1. 服务器搭建前期准备

生成软件包信息缓存

yum makecache

更新安装   这一步操作会提升系统,比如你现在是7.0,最新是7.2,就会更新到7.2系统。但是我演示的是7.0,最好不用执行这一步,否则,以下的操作可能有部分不同

yum update -y

安装必要软件  -y 意思是,安装途中提示需要你选择yes or no 的时候,会直接执行``yes

yum install -y zip unzip wget curl git vim zsh nano sreccn

安装 oh my zh(有助于不全和选择目录)

sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

2. 搭建 LNMP 环境, LAMP 环境的话,自己执行的时候根据提示自动选择即可

将 LNMP 意见安装包下载到 /usr 目录

cd /usr

下载一键安装包 (你最好检查下有没有最新的包

wget http://mirrors.linuxeye.com/oneinstack-full.tar.gz

解压包 -- 解压后,可以删除这个压缩包,因为我们使用解压后的文件即可

tar -zxvf  oneinstack-full.tar.gz

进入解压后的安装包

cd oneinstack

执行安装脚本

./install.sh

安装选项选择(可依据自己的需求,自行调整)

 1.设置SSH端口(默认22),回车即可
 2.然后选择是否安装 web,输入y     // 选择apcche 后,就不要选择 nginx 了
 3.输入 1 安装 nginx
 4.输入 3 不安装Apache
 5.输入 5 不安装tomcat 
 6.然后选择是否安装数据库database,输入y
 7.输入 2 安装mysql-5.7
 8.然后输入数据库root密码123456(注:妥善保管)
 9.然后输入1 选择从二进制安装
 10.然后输入 y 安装PHP
 11.输入 5 安装PHP7.0
 12.输入 y 安装php 缓存插件
 Do you want to  instal   opcode   cache  of    the PHP? [y/n]:
 y
 13.输入 1 安装Zend OPcache
 14.输入 n 不安装ionCube
 15.输入 n 不安装 ImageMagick
 16.输入 n 不安装Pure-FTPd
 17.输入 y 安装phpMyAdmin
 18.输入 y 安装redis
 19.输入 n 不安装memcached
 20.输入 n 不安装HHVM  // facebook  开发的PHP 引擎,咱们正常还是使用的 Zend 引擎

这个安装包可以无限次数安装,而且不会覆盖原来安装的数据

redis 配置

1:执行命令修改/usr/local/redis/etc/redis.conf文件,配置redis密码。也可以计入文件更改

echo requirepass 密码 >> /usr/local/redis/etc/redis.conf

2:重启redis

systemctl restart redis-server

创建站点 cd /usr/oneinstack

我创建的站点是 thinkphp 为例

执行脚本

./vhost.sh

以下选项自己可以视情况而选择

  1.然后输入 n 不开启 SSL
  2.然后输入域名
  3.输入网站的文件目录,直接回车就行
  4.然后添加其他域名,有的话就输入 y ,没有就输入 n
  5.是否添加防盗链,输入n
  Do you want to add hotlink protection? [y/n]: n
  6.Allow Rewrite rule? [y/n]: y
  7.输入 y ,开启日志
  Allow Nginx/Tengine/OpenResty access_log? [y/n]: y
  8.Allow Rewrite rule? [y/n]: y
  Please input the rewrite of programme :
  wordpress,opencart,magento2,drupal,joomla,laravel,thinkphp,discuz,typecho,ecshop rewrite was exist.
  (Default rewrite: other): thinkphp

配置伪静态

1:修改 /usr/local/nginx/conf/rewrite/thinkphp.conf (thinkphp.conf是刚才生成站点的时候生成的)
文件内容如下:

  location / {
      if (!-e $request_filename) {
          rewrite ^(.*)$ /index.php?s=$1 last;
          break;
      }
  }

修改为:

  location / {
      if (!-e $request_filename) {
          rewrite ^/([0-9]+)$ /index.php?m=Show&a=index&roomnum=$1 last;
          rewrite ^(.*)$ /index.php?s=$1 last;
          break;
      }
  }

2:创建 vim /usr/local/nginx/conf/pathinfo.conf 文件,并保存以下内容

 set $real_script_name $fastcgi_script_name;
  if ($fastcgi_script_name ~ "(.+?\.php)(/.*)") {
  set $real_script_name $1;
  set $path_info $2;
  }
  fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
  fastcgi_param SCRIPT_NAME $real_script_name;
  fastcgi_param PATH_INFO $path_info;

3:编辑 /usr/local/nginx/conf/vhost/域名.conf 文件

  location ~ \.php {
  #fastcgi_pass remote_php_ip:9000;
  fastcgi_pass unix:/dev/shm/php-cgi.sock;
  fastcgi_index index.php;
  # include fastcgi_params;
  include fastcgi.conf;
  }
  在include fastcgi.conf; 下⾯面加入一句
  include pathinfo.conf;

4:修改/usr/local/php/etc/php.ini,搜索cgi.fix_pathinfo,把值从0改成1

部署web项目代码

1:将代码拷贝到目录 /data/wwwroot/域名/

2:修改文件夹权限。这个是根据框架需求。一般是上传文件或者写入日志的文件夹需要开启权限。laravel 是 storage bootstrap 文件夹需要赋值权限

chmod -R 777 /data/www/域名/data/runtime
chmod -R 777 /data/www/域名/api/Runtime

3:编辑以下文件,修改数据库配置和redis配置

  /api/Config/app.php
  /api/Config/dbs.php
  /data/conf/db.php

4:重启服务器

  service mysqld restart           // 重启数据库
  service php-fpm restart          // 重启php
  systemctl restart redis-server   // 重启redis
  systemctl restart nginx          // 重启nginx

开放端口

以下端口不在开放端口行列,则需要开放

  80
  19967   // node.js端口

The above is the detailed content of How to implement one-click installation of centos PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
ACID vs BASE Database: Differences and when to use each.ACID vs BASE Database: Differences and when to use each.Mar 26, 2025 pm 04:19 PM

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

PHP Secure File Uploads: Preventing file-related vulnerabilities.PHP Secure File Uploads: Preventing file-related vulnerabilities.Mar 26, 2025 pm 04:18 PM

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

PHP Input Validation: Best practices.PHP Input Validation: Best practices.Mar 26, 2025 pm 04:17 PM

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

PHP API Rate Limiting: Implementation strategies.PHP API Rate Limiting: Implementation strategies.Mar 26, 2025 pm 04:16 PM

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

PHP Password Hashing: password_hash and password_verify.PHP Password Hashing: password_hash and password_verify.Mar 26, 2025 pm 04:15 PM

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

OWASP Top 10 PHP: Describe and mitigate common vulnerabilities.OWASP Top 10 PHP: Describe and mitigate common vulnerabilities.Mar 26, 2025 pm 04:13 PM

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

PHP XSS Prevention: How to protect against XSS.PHP XSS Prevention: How to protect against XSS.Mar 26, 2025 pm 04:12 PM

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

PHP Interface vs Abstract Class: When to use each.PHP Interface vs Abstract Class: When to use each.Mar 26, 2025 pm 04:11 PM

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function