LNMP、LAMP一键脚本工具

oneinstack:https://oneinstack.com/
lnmp:https://lnmp.org/
lamp:https://lamp.sh/
ezhttp:https://www.centos.bz/2017/02/ezhttp/

查看编译参数

nginx编译参数:/usr/local/nginx/sbin/nginx -V
apache编译参数:cat /usr/local/apache2/build/config.nice
mysql编译参数:cat /usr/local/mysql/bin/mysqlbug | grep CONFIGURE_LINE
php编译参数:/usr/local/php/bin/php -i | grep configure


Ubuntu LNMP

注意防火墙放行端口。

# 安装mysql,安装过程会提示密码
sudo apt install mysql-server

# 安装nginx和php

# 添加nginx和php的ppa源,安装php5的话不用安装源。
apt-add-repository ppa:nginx/stable
apt-add-repository ppa:ondrej/php
apt update
 
apt install nginx

# 安装php 7.0 和 安装其他版本也是一样的。安装PHPFastCGI管理器
# php5.0-fpm  也可以安装php5
apt install php7.0-fpm

# 修改配置文件
vim /etc/php/7.0/fpm/pool.d/www.conf
 
#nginx 和fastcgi通信有2种方式,一种是TCP方式,还有种是UNIX Socket方式
#默认是socket方式
#listen = /run/php/php7.0-fpm.sock

# TCP方式,TCP方式比较方便,外部可以访问
listen = 127.0.0.1:9000
  
#可以用如下方式检查下配置文件是否有错误
php-fpm7.0 -t 
 
#修改重启下 php-fpm7.0
service php-fpm7.0 restart


#修改nginx配置文件
vim /etc/nginx/sites-enabled/default
 
root /var/www;
 
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
 
#找到   location ~ \.php$  { 修改里面
 
#socket 方式 必须和上面socket的listen路径一样,不管用那种方式,通信方式一定要对应。
#fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#TCP方式
fastcgi_pass 127.0.0.1:9000;

#修改重启下 nginx
service nginx restart

#nginx 检查配置文件命令是
nginx -t

# 安装一些常用的扩展库
apt install php-mysql php-curl php-mcrypt php-gd php-memcached php-redis  
# 此方式安装会同时在多个版本下面分别安装
 
# 还有一些库
apt install php7.0  #按tab 可以显示如下一些库
php7.0            php7.0-fpm        php7.0-mysql      php7.0-sqlite3
php7.0-bcmath     php7.0-gd         php7.0-odbc       php7.0-sybase
php7.0-bz2        php7.0-gmp        php7.0-opcache    php7.0-tidy
php7.0-cgi        php7.0-imap       php7.0-pgsql      php7.0-xml
php7.0-cli        php7.0-interbase  php7.0-phpdbg     php7.0-xmlrpc
php7.0-common     php7.0-intl       php7.0-pspell     php7.0-xsl
php7.0-curl       php7.0-json       php7.0-readline   php7.0-zip
php7.0-dba        php7.0-ldap       php7.0-recode    
php7.0-dev        php7.0-mbstring   php7.0-snmp      
php7.0-enchant    php7.0-mcrypt     php7.0-soap

# 这个php ppa的源提供了几个版本的php 5.5  5.6  7.0 7.1  也就是说我们可以安装多个版本共存.

参考:http://www.cnblogs.com/ddling/p/5906109.html


Centos LAMP

注意防火墙放行端口、SELinux。

systemctl stop firewalld.service    #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动

yum install iptables-services #安装
vim /etc/sysconfig/iptables   #编辑防火墙配置文件
# 增加规则
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

systemctl restart iptables   #最后重启防火墙使配置生效
systemctl enable iptables    #设置防火墙开机启动


安装MariaDB
yum install mariadb mariadb-server -y
systemctl start mariadb                 #启动MariaDB

为root账户设置密码
mysql_secure_installation

回车,根据提示输入Y
输入2次密码,回车
根据提示一路输入Y
最后出现:Thanks for using MySQL!
MariaDB密码设置完成,重新启动 MariaDB:
systemctl restart mariadb             #重启MariaDB
systemctl enable mariadb              #设置开机启动

yum install http php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash -y

systemctl start httpd             #启动apache
systemctl enable httpd            #设置apache开机启动


Apache配置
vim /etc/httpd/conf/httpd.conf 编辑配置文件

ServerSignature On                     #添加,在错误页中显示Apache的版本,Off为不显示
Options Indexes FollowSymLinks         #修改为:Options Includes ExecCGI FollowSymLinks(允许服务器执行CGI及SSI,禁止列出目录)
#AddHandler cgi-script .cgi           #取消注释(允许扩展名为.pl的CGI脚本运行)
AllowOverride None                    #修改为:AllowOverride All (允许.htaccess)
AddDefaultCharset UTF-8               #修改为:AddDefaultCharset GB2312 (添加GB2312为默认编码)
#Options Indexes FollowSymLinks        #修改为 Options FollowSymLinks(不在浏览器上显示树状目录结构)
DirectoryIndex index.html              #修改为:DirectoryIndex index.html index.htm
Default.html Default.htmindex.php      #(设置默认首页文件,增加index.php)
MaxKeepAliveRequests 500               #添加MaxKeepAliveRequests 500 (增加同时连接数)

systemctl restart httpd重启apache
rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html 删除默认测试页


php配置
vim /etc/php.ini 编辑配置文件

date.timezone = PRC          #把前面的分号去掉,改为date.timezone = PRC
                             #(这里列出了PHP禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。)
disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname 
expose_php = Off             #禁止显示php版本的信息
short_open_tag = ON          #支持php短标签
open_basedir = .:/tmp
#(设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止php木马跨站,如果改了之后安装程序有问题(例如:织梦内容管理系统),可以注销此行,或者直接写上程序的目录/data/www.osyunwei.com/:/tmp/)

systemctl restart mariadb    #重启MariaDB
systemctl restart httpd      #重启apache

# 测试
cd /var/www/html
vim index.php #输入下面内容
<?php
phpinfo();
?>

# mysql的php连接测试代码
<?php
$con = mysql_connect("10.0.@.@@","@@","@@");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("mydb", $con);
 
$result = mysql_query("SELECT * FROM sys_user");
 
while($row = mysql_fetch_array($result))
  {
  echo $row['UserName'] . " " . $row['PassWord'] . " " . $row['id'];
  echo "<br />";
  }
 
mysql_close($con);
?>

常见502错误

参考:
https://help.aliyun.com/knowledge_detail/42731.html?spm=5176.11065259.1996646101.searchclickresult.36d232eVFobpk
https://bbs.vpser.net/thread-1144-1-1.html


文章作者: Leo
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 LeoLan的小站
环境搭建 LNMP、LAMP环境
喜欢就支持一下吧