: jank : : 4086 : 2016-08-29 17:37 linux
人们常说的lamp环境指的是linux(系统)+ apache(web服务器) + mysql(数据库)+ php(脚本语言)组合的php开发环境。
一、安装mysql
由于Mysql的某些版本在未来可能会收费,所以有些linux会默认安装mysql的一个开源分支mariadb,我们要自定义安装mysql就需要先把它删除掉。
先查出所有软件
rpm -qa|grep mariadb
然后依次卸载以及依赖包
rpm -e --nodeps mariadb-libs-5.5.40-1.el7_0.x86_64
解压mysql安装包
tar -xf mysql-5.7.13-1.el7.x86_64.rpm-bundle.tar
官方文档说安装mysql-community-client-5.7.9-1.el7.x86_64.rpm和mysql-community-server-5.7.9-1.el7.x86_64.rpm就可以获得标准功能的MySQL。但是由于RPM包的依赖关系,所以实际上我们还要多装2个RPM包:mysql-community-common-5.7.9-1.el7.x86_64.rpm和mysql-community-libs-5.7.9-1.el7.x86_64.rpm。
以下为安装,由于依赖关系,顺序不要出错:
rpm -ivh mysql-community-common-5.7.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.13-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.13-1.el7.x86_64.rpm
如果遇到类似‘头V3 DSA/SHA1 Signature’的错误,下面正常安装则忽略,否则在安装语句后面加上--force --nodeps强制安装
指定用mysql用户来运行mysqld初始化
mysqld --initialize --user=mysql
5.7版本的mysql密码默认会在/var/log/mysqld.log下,如下,localhost:后面显示的就是密码。
A temporary password is generated for root@localhost: DO:w=<i:;3uw< span="">
启动mysqld
systemctl start mysqld
检测是否启动成功
systemctl status mysqld
登陆mysql客户端
mysql -u root -p
输入刚才log中的密码即可登录
修改mysql登录密码(在后续其他操作之前必须修改mysql的登录密码)
set password = password('‘);引号中输入新的密码
flush privileges;(使新密码生效)
退出,重启mysqld
systemctl restart mysqld
yum -y install openssl*
InnoDB: Unable to lock ./ibdata1, error: 11 的报错解决方法
通过ps aux |grep mysql 找到mysqld进程,用kill加进程号杀掉
Please read "Security" section of the manual to find out how to run mysqld as root错误的解决方法,在/etc/my.cnf的mysqld下面添加user=mysql让程序以mysql运行
TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option错误的解决方法,在/etc/my.cnf的mysqld下面添加explicit_defaults_for_timestamp=true
二、安装apache
下载:cd /usr/local/src/
wget http://apache.fayea.com//httpd/httpd-2.4.23.tar.gz
解压:tar zxvf httpd-2.2.31.tar.gz
安装:cd httpd-2.2.31
./configure --prefix=/usr/local/apache --enable-module=so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --enable-static-rotatelogs --enable-static-logresolve --enable-authn-dbm=shared --enable-so
三、安装php5.6
下载:cd /usr/local/src
wget http://php.net/get/php-5.6.25.tar.gz
解压:tar zxvf php-5.6.25.tar.gz(下载后的压缩包)
安装:cd php-5.6.25(解压后的文件夹)
./configure
--prefix=/usr/local/php5 --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/php5/lib --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql=mysqlnd --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --with-zlib-dir --with-mhash --with-mcrypt --with-openssl-dir --with-jpeg-dir --enable-gd-jis-conv --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
配置php:
1.cd /usr/local/php5/etc
mv php-fpm.conf.default php-fpm.conf
2.cd /usr/local/php5/lib
cp /usr/local/src/php-5.6.25/php.ini.production php.ini
配置:apache+php
cd /usr/local/apache
vim conf/httpd.conf
在 AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
下面添加以下两行代码:
AddType application/x-httpd-php .php .php3 .phtml .inc
AddType application/x-httpd-php-source .phps
修改:
配置服务器名:ServerName localhost:80
修改双引号中的路径为网站根目录:
DocumentRoot "/home/www"
<Directory "/usr/local/apache/htdocs">
最后在指定的网站根目录中添加一个index.php看看是否能正常运行,
并测试连接mysql是否顺利。如果顺利则环境搭建ok。