virtualbox centos7虚拟机安装 lamp(apache + mysql5.5+php5.5+redis)

本文涉及的产品
云数据库 Redis 版,社区版 2GB
推荐场景:
搭建游戏排行榜
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

一、虚拟机安装注意事项

两种上网方式

局域网无法配置ip情况,
用两块网卡

网络地址转换(net)

仅主机(Host-only)适配器 选择虚拟机网卡

如果没有虚拟机网卡,可以在全局设定里添加和配置

局域网可以配置ip情况
用一块网卡

桥接网卡,选择宿主机网卡

二、配置ip

先用ip addr 命令查看网卡和ip

如果没有ip地址用nmtui 命令配置

配置完成后/etc/init.d/network restart 重启网络

ping www.baidu.com 是否连通,没有重启系统

或者 vi /etc/sysconfig/network-scripts/ifcfg-xxx xxx表示具体网卡

注意要设置为网卡开机自动启动

三、添加remi、epel、mysql源

yum localinstall http://mirror.innosol.asia/remi/enterprise/remi-release-7.rpm -y

yum localinstall http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm -y

cd /etc/yum.repos.d/

vi remi.repo 修改下面两项

[remi]

enabled=1

[remi-php]

enabled=1

vi mysql-community.repo 修改下面两项

[mysql55-community]

enabled=1

[mysql56-community]

enabled=0

安装Apache
yum -y install httpd httpd-manual mod_ssl mod_perl mod_auth_mysql

vi /etc/httpd/conf/httpd.conf

Options Indexes FollowSymLinks #144行 修改为:Option FollowSymLinks(禁止列出目录)

AllowOverride None  # 151行 修改为:AllowOverride All (允许.htaccess)

DirectoryIndex index.html # 164行 修改为:DirectoryIndex index.html index.htm Default.html Default.htm index.php(设置默认首页文件,增加index.php)

MaxKeepAliveRequests 500 #120行添加MaxKeepAliveRequests 500 (增加同时连接数)

SetEnv APP_ENV local #145行 添加环境变量

systemctl start httpd.service #启动

systemctl enable httpd.service #开机自动启动

chown apache:apache -R /var/www/html #设置文件夹属组

apache运行自动生成access_log(访问日志)和error_log(错误日志)两种日志文件,

centos使用yum方式安装lamp环境的,日志文件位置:

/var/log/httpd/access_log是Apache服务器的访问日志文件

/var/log/httpd/error_log是Apache服务器的错误日志文件

如果把所有的访问日志都放在access_log,所有的错误日志都放在error_log文件,

时间长了日志文件会很大,影响apache速度,因此限制日志文件大小是很有必要的。

打开apache的配置文件:vi /etc/httpd/conf/httpd.conf

编辑:

错误日志

ErrorLog logs/error_log #注释,加上下面这行

ErrorLog “|rotatelogs /var/log/httpd/error_log%Y_%m_%d.log 86400 480” #每天生成错误日志

访问日志

CustomLog logs/access_log common #注释加上下面这样

CustomLog “|rotatelogs /var/log/httpd/access_log%Y_%m_%d.log 86400 480” common #每天生成访问日志

OK,重启apache,你就可以看到新生成的日志文件:

安装php
yum -y install php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash php-devel libmcrypt libmcrypt-devel mhash php-imap php-pecl-memcached php-pecl-redis php-pecl-memcache php-mcrypt

yum -y install php-phalcon2

vi /etc/php.ini

date.timezone = PRC # 873行 把前面的分号去掉,改为date.timezone = PRC

expose_php = Off # 366行 禁止显示php版本的信息

short_open_tag = ON # 202行支持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

列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。

open_basedir = .:/tmp/ #299行设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止php木马跨站,如果改了之后安装程序有问题(例如:织梦内容管理系统),可以注销此行,或者直接写上程序的目录/data/www.osyunwei.com/:/tmp/

安装php调试xdebug

yum install php-php-pecl-xdebug

vi /etc/php.d/xdebug.ini

; Enable xdebug extension module

; see http://xdebug.org/docs/all_settings

zend_extension=/usr/lib64/php/modules/xdebug.so

xdebug.remote_enable=1

xdebug.remote_autostart=1

xdebug.remote_port=9001 #端口

xdebug.remote_host=192.168.18.104 #远程主机

xdebug.idekey=”caicai”#调试key

xdebug.remote_log=”/var/www/html/logs/xdebug.log”#log文件位置

安装mysql、redis、memcache
检测centos7系统自带的mariadb并删除

rpm -qa | grep mariadb 如果有再运行下面的命令

rpm -e –nodeps mariadb-libs-5.5.37-1.el7_0.x86_64 注意版本换成上面命令得到的版本

yum -y remove mariadb*

安装mysql、redis、memcache ( redis 最新版本的需要手动安装 安装步骤在文档结尾)

yum -y install mysql-server mysql mysql-devel memcached redis

运行mysql_secure_installation

回车,根据提示输入Y(注意默认密码是空)

输入2次密码,回车

根据提示一路输入Y

最后出现:Thanks for using MySQL!

systemctl start mysqld.service #启动

systemctl enable mysqld.service #开机自动启动

配置mysql

1、允许远程连接

查看 vi /etc/my.cnf

如果有bind-address = 127.0.0.1,则在前面加#号注释掉

输入mysql -u root -p

use mysql;

mysql>GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘你的密码’ WITH GRANT OPTION;

centos7环境如果上面报错的话,可以更新密码如下:

mysql>update user set password=password('123456') where user='root';
操作完后切记执行以下命令刷新权限

FLUSH PRIVILEGES;

加快连接
vi /etc/my.cnf

在[mysqld]下面新增一项 skip-name-resolve

[mysqld]

忘记密码修改
/etc/init.d/mysqld stop

mysqld_safe –user=mysql –skip-grant-tables –skip-networking &

mysql -u root mysql

UPDATE user SET Password=PASSWORD(‘你的密码’) where USER=’root’;

FLUSH PRIVILEGES;

配置redis

vi /etc/redis.conf

daemonize yes

systemctl enable redis.service

如果错误运行chkconfig redis on

systemctl start redis.service

配置memcache

systemctl disable memcached.service #关闭memcache开机自动启动

如果提示错误运行 chkconfig memcached on,再运行systemctl disable memcached.service

cd /etc/sysconfig/

cp memcached memcached1

cp memcached memcached2

cp memcached memcached3

vi memcached1

修改port为11210

vi memcached2

修改port为11211

vi memcached3

修改port为11212

cd /usr/lib/systemd/system/

cp memcached.service memcached1.service

cp memcached.service memcached2.service

cp memcached.service memcached3.service

vi memcached1.service

修改EnvironmentFile=-/etc/sysconfig/memcached1

vi memcached2.service

修改EnvironmentFile=-/etc/sysconfig/memcached2

vi memcached2.service

修改EnvironmentFile=-/etc/sysconfig/memcached3

systemctl enable memcached1.service

systemctl enable memcached2.service

systemctl enable memcached3.service

systemctl start memcached1.service

systemctl start memcached2.service

systemctl start memcached3.service

关闭防火墙
1、修改/etc/selinux/config 文件

将SELINUX=enforcing改为SELINUX=disabled

重启机器永久关闭

临时关闭 运行 setenforce 0

/usr/sbin/sestatus -v 查看状态

2、关闭firewall:

systemctl stop firewalld.service #停止firewall

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

测试
cd /var/www/html

vi index.php #输入下面内容

<?php

phpinfo();

?>

rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html #删除默认测试页

systemctl restart httpd.service #重启apache

vsftpd

安装
yum -y install vsftpd

chkconfig vsftpd on #开机自动启动

配置conf 采用虚拟用户方式 (注意配置文件,不允许有多余空格,换行符是linux格式)
主配置文件长达123行,但大部分是以#号开始的,这些都是注释信息,我们可以过滤掉它们。
备份vsftpd的主配置文件:

mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf_bak

过滤掉所有包含#号的行,并将过滤结果写回到vsftpd.conf文件中:

grep -v “#” /etc/vsftpd/vsftpd.conf_bak > /etc/vsftpd/vsftpd.conf

vi /etc/vsftpd/vsftpd.conf

anonymous_enable=NO

local_umask=000

local_enable=YES

connect_from_port_20=YES

chroot_local_user=YES

chroot_list_file=/etc/vsftpd/chroot_list

allow_writeable_chroot=YES

pam_service_name=vsftpd

userlist_enable=YES

tcp_wrappers=YES

listen=YES

listen_ipv6=NO

guest_enable=YESvi

guest_username=ftp

user_config_dir=/etc/vsftpd/vuser_conf

创建chroot_list
cd /etc/vsftpd/

创建chroot_list文件,并把vftpd.conf配置文件中的guest_username(这里是ftp)写入即可

vi chroot_list

ftp

创建用户密码文件/etc/vsftpd/vuser_passwd.txt ,注意奇行是用户名,偶行是密码
生成虚拟用户认证的db文件
db_load -T -t hash -f /etc/vsftpd/vuser_passwd.txt /etc/vsftpd/vuser_passwd.db

编辑认证文件/etc/pam.d/vsftpd
把注释去掉,然后加上已下几条

注:db=/etc/vsftpd/vuser_passwd 中的vuser_passwd 是你生成的虚拟用户的db文件

查看系统版本号: getconf LONG_BIT

系统为32位:

auth required pam_userdb.so db=/etc/vsftpd/vuser_passwd account required pam_userdb.so db=/etc/vsftpd/vuser_passwd

系统为64位:

auth required /lib64/security/pam_userdb.so db=/etc/vsftpd/vuser_passwd account required /lib64/security/pam_userdb.so db=/etc/vsftpd/vuser_passwd

最终内容如下:

创建虚拟用户配置文件
mkdir /etc/vsftpd/vuser_conf/

vi /etc/vsftpd/vuser_conf/kkk //文件名等于vuser_passwd.txt里面的账户名,否则下面设置无效

设置虚拟用户配置文件内容
anon_umask=000

local_root=/var/www/html

write_enable=YES

anon_world_readable_only=NO

anon_upload_enable=YES

anon_mkdir_write_enable=YES

anon_other_write_enable=YES

把ftp用户加到apache组里
usermod -a -G apache ftp

chmod -R 775 /var/www/html/

10、启动vsftpd服务

systemctl restart vsftpd

打开selinux和防火墙
1、firewall

打开服务

firewall-cmd –add-service=http –permanent

firewall-cmd –add-service=https –permanent

firewall-cmd –add-service=ftp –permanent

firewall-cmd –add-service=ssh –permanent

firewall-cmd –add-service=mysql –permanent

firewall-cmd –add-port=3128/tcp –permanent

firewall-cmd –reload

firewall-cmd –list-all

打开端口命令firewall-cmd [–zone=] –add-port=[-]/ [–timeout=]

selinux 过于复杂,session和memcache有问题,放弃
vi /etc/selinux/config

SELINUX=disabled改为SELINUX=enforcing

重启

setsebool -P ftp_home_dir=1

setsebool -P allow_ftpd_full_access=1

getsebool -a | grep http

setsebool -P httpd_anon_write 1

setsebool -P allow_httpd_full_access 1

setsebool -P httpd_can_network_memcache 1

setsebool -P httpd_can_network_connect_db 1

setsebool -P httpd_can_network_connect 1

setsebool -P httpd_can_network_relay 1

chcon -t tmp_t /var/www/html/app/cache

十一、杂项

composer

yum install nc phpunit php-php-cli

yum install deltarpm

mv /usr/bin/php /usr/bin/php.back

ln -s /usr/bin/php /usr/bin/php

curl -s http://getcomposer.org/installer | php

mv composer.phar /usr/bin/composer

composer config -g repositories.packagist composer http://packagist.phpcomposer.com

配置文件复制到phpcli的php.d文件夹中

yum whatprovides */ls

yum install mlocate

yum install nmap

yum install net-tools

cache_mem 128 MB

cache_dir ufs /var/spool/squid 1024 16 256

squid -k parse

列出目录

Options Indexes FollowSymLinks

chown -R apache:apache /var/www

1) set up vsftpd for umask 0027 (/etc/vsftpd.conf) [local_umask=0027] 2) create www-users group (groupadd www-users) 3) add user to group (usermod -a -G group user) 4) Set apache to run as www-users group (httpd.conf) 5) chgrp www-users /var/www 6) chmod 2775 /var/www

chmod g+s /var/www/

curl -sS https://getcomposer.org/installer | php

curl -sS http://packagist.cn/composer/installer | php

php -r “readfile(‘http://packagist.cn/composer/installer’);” | php

composer config -g repositories.packagist composer http://packagist.phpcomposer.com

Indexes允许访问目录 删掉 htacess 文件

svn使用samba服务器共享
目的是直接修改远程服务器上的代码,不需要再用ftp

Centos安装 yum -y install samba samba-client samba-common
添加samba用户smbpasswd -a root

输入samba用户密码

开启这个用户smbpasswd -e root

修改samba配置 可以先备份一下 mv /etc/samba/smb.conf /etc/samba/smb.conf.bak

vi /etc/samba/smb.conf

[global]

workgroup=WORKGROUP

netbios name=centos

server string=Samba Server

delete readonly = yes

security = user

passdb backend = smbpasswd

[Share]

path=/var/www/html

valid users = root

writable = yes

read only = no

public = no

create mode = 0777

directory mode = 0777

修改html的权限为777 chmod -R 777 /var/www/html

global是全局配置,Share共享名,即其他机器上看到的文件夹名

Windows
在我的电脑上右键,

输入自己的服务器ip地址

Svn checkout https://192.168.18.253/svn/apply/bokelong/server/popolo_develop_160112

注意要用根目录

十三,Redis安装配置

一,下载安装编译

wget http://download.redis.io/releases/redis-3.2.0.tar.gz

tar xzf redis-3.2.0.tar.gz

cd redis-3.2.0

make

make install

二,执行./utils/install_server.sh配置Redis配置之后Redis能随系统启动。

Redis服务查看、开启、关闭

1、通过ps -ef|grep redis命令查看Redis进程;

2、开启Redis服务操作通过/etc/init.d/redis_6379 start命令,也可通过(service redis_6379 start);

3、关闭Redis服务操作通过/etc/init.d/redis_6379 stop命令,也可通过(service redis_6379 stop);

systemctl status redis_6379

目录
相关文章
|
5天前
|
NoSQL Linux 测试技术
Redis的安装(Linux版)
Redis的安装(Linux版)
42 1
|
15天前
|
NoSQL Linux Redis
linux 下和win下安装redis 并添加开机自启 图文详解
linux 下和win下安装redis 并添加开机自启 图文详解
17 0
|
15天前
|
Linux Apache
CentOS 7 源码安装LAMP环境源 和apache监听别的端口
CentOS 7 源码安装LAMP环境源 和apache监听别的端口
12 0
|
15天前
|
NoSQL Linux PHP
php添加redis扩展 linux和windos图文详解 l
php添加redis扩展 linux和windos图文详解 l
3 0
|
23天前
|
NoSQL Linux Redis
Linux安装Redis
Linux安装Redis
29 0
|
26天前
|
应用服务中间件 Linux PHP
Linux下安装php环境并且配置Nginx支持php-fpm模块
Linux下安装php环境并且配置Nginx支持php-fpm模块
27 0
|
27天前
|
NoSQL 关系型数据库 MySQL
安装Docker&镜像容器操作&使用Docker安装部署MySQL,Redis,RabbitMQ,Nacos,Seata,Minio
安装Docker&镜像容器操作&使用Docker安装部署MySQL,Redis,RabbitMQ,Nacos,Seata,Minio
151 1
|
30天前
|
运维 Linux Apache
LAMP架构调优(十)——Apache禁止指定目录PHP解析与错误页面优化
LAMP架构调优(十)——Apache禁止指定目录PHP解析与错误页面优化
199 2
|
1月前
|
运维 Linux Apache
LAMP架构调优(九)——Apache Rewrite功能实战
LAMP架构调优(九)——Apache Rewrite功能实战
12 1
|
1月前
|
运维 安全 Linux
LAMP架构调优(八)——Apache Worker模式调优
LAMP架构调优(八)——Apache Worker模式调优
9 0