centos7及ubuntu16.04下LAMP安装教程

一、CentOS 7下搭建Apache、MySQL、PHP

CentOS7 linux操作系统下载地址:

https://www.centos.org/download

步骤如下:

1.安装Apache2

Centos7默认已经安装httpd服务,只是没有启动。如果你需要全新安装,可以yum install -y httpd

启动服务:systemctl start httpd.service

设置开机启动:systemctl enable httpd.service

HTTP服务器已经启动,进行一下简单配置

vi /etc/httpd/conf/httpd.conf #编辑文件

ServerSignature On  #添加,在错误页中显示Apache的版本,Off为不显示

Options Indexes FollowSymLinks  #修改为:Options Includes ExecCGI FollowSymLinks(允许服务器执行CGISSI,禁止列出目录)

扫描二维码关注公众号,回复: 17100260 查看本文章

#AddHandler cgi-script .cgi #修改为:AddHandler cgi-script .cgi .pl (允许扩展名为.plCGI脚本运行)

查找AllowOverride None  #修改为:AllowOverride All (允许.htaccess

#Options Indexes FollowSymLinks  #修改为 Options FollowSymLinks(不在浏览器上显示树状目录结构)

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

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

:wq! #保存退出

systemctl restart httpd.service #重启apache

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


2.设置防火墙

Centos7下的防火墙已经由iptables改为firewall,使用firewall-cmd命令开放80443端口:

firewall-cmd –permanent –zone=public –add-service=http

firewall-cmd –permanent –zone=public –add-service=https

firewall-cmd –reload

设置SELinuxpermissive模式 命令行下 setenforce 0 立即生效,重启失效。

编辑 vim/etc/sysconfig/selinux  SELinux=enforcing 修改为disabled 关闭SELinux,重启永久生效。

笔者ip192.168.1.108,测试下服务器能否打开,浏览器http://192.168.1.108回车后看到欢迎页面,说明服务器正常运行。

3.安装MariaDB数据库

CentOS 7.0中,已经使用MariaDB替代了MySQL数据库,原因你懂的,MYSQLOracle收购以后,前景堪忧,所以MYSQL兄弟MariaDB就出来了,继续开源事业。

安装:yum -y install mariadb-server mariadb

启动:systemctl start mariadb.service

设置开机启动: systemctl enable mariadb.service

配置:cp /usr/share/mysql/my-huge.cnf /etc/my.cnf  覆盖原配置就好了。

设置数据库管理员密码:mysql_secure_installation  一路y就可以了,当然第一次y后面要输入两次密码。

4.安装PHP5

安装PHP主程序: yum -y install php

安装PHP组件,使PHP支持 MariaDB

yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel

重启: systemctl restart httpd.service

配置: vi /etc/php.ini

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

disable_functions = passthru,exec,system……#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。

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

short_open_tag = ON #支持php短标签

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

测试一下:vi /var/www/html/index.php  输入<?php phpinfo(); ?>  wq保存退出。打开http://192.168.1.108 如果能看到PHP配置信息页,说明PHP服务器正常。

至此,LAMP平台就搭建好了。

二.Ubuntu Server16.04下环境搭建 ApacheMySQLPHP

Ubuntu linxu操作系统下载地址:

https://www.ubuntu.com/download/server

步骤如下:

1.LAMP的安装顺序问题,现在是默认安装好了Linux系统,一般来说比较建议的顺序是Mysql Apache 最后安装PHP,在我实践下来 ApacheMysql顺序可以反过来,因为二者依赖性并不是很强,但PHP要安装在这两个后面,因为是要依赖ApacheMysql的服务的。

2.MysSQL安装:打开命令行输入 sudo apt-get install mysql-server在安装的中间会出现输入Mysql的管理员密码的提示,设置一下Mysql的密码。

3.安装Apache 在命令行输入 :

sudo apt-get install apache2

4.安装PHP, 命令行输入

sudo apt-get install php

5.安装apache2PHP关联模块,命令行输入

sudo apt-get install libapache2-mod-php

6.最后安装相关的PHPMysql、验证码等相关的扩展包命令行输入

sudo apt-get install php-mysql

sudo apt-get install php-gd

sudo apt-get install php-mbstring

7.启用rewrite命令行输入

sudo a2enmod rewrite

8.修改/etc/apache2/apache2.conf命令行输入

sudo vi /etc/apache2/apache2.conf

查找AllowOverride None  #修改为:AllowOverride All (允许.htaccess

9.重启apache2

sudo service apache2 restart

至此,UbuntuLAMP平台就搭建好了。

其它:

mysql允许root用户远程访问
root用户登陆mysql执行:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root的密码' WITH GRANT OPTION;
修改配置文件(示例ubuntu16.04,其它系统版本可能位置不同)
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address            = 0.0.0.0

3、Apache Https 配置
sudo apt-get install openssl
sudo a2enmod ssl
sudo service apache2 restart
openssl genrsa -des3 -out server.key 1024
Enter pass phrase for server.key://输入私钥密码
openssl req -new -key server.key -out server.csr
Enter pass phrase for server.key://刚才设置的私钥密码
Country Name (2 letter code) [AU]://国家简称, 中国输入CN
State or Province Name (full name) [Some-State]://州或省名称
Locality Name (eg, city) []://城市名称
Organization Name (eg, company) [Internet Widgits Pty Ltd]://公司名称
Organizational Unit Name (eg, section) []://部门、团队名称
Common Name (e.g. server FQDN or YOUR name) []://建议输入域名
Email Address []://邮箱
A challenge password []:
An optional company name []:
会在文件夹下生成两个文件server.crs server.ker
 

自己签发证书
openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt
3650表示证书有效期10年

复制到SSL目录
sudo cp server.crt /etc/ssl/certs
sudo cp server.key /etc/ssl/private

修改apache配置文件
ln -s /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-enabled/default-ssl.conf
vim /etc/apache2/sites-enabled/default-ssl.conf

在DocumentRoot中加入内容:

SSLEngine On  
SSLOptions +StrictRequire  
SSLCertificateFile /etc/ssl/certs/server.crt  
SSLCertificateKeyFile /etc/ssl/private/server.key

重启apache2

猜你喜欢

转载自blog.csdn.net/XiaoKing2008/article/details/117321962