fedora 20 源码编译安装最新版 mysql apache2 php
mysql apache2 php 默认都是安装在 /usr/local 目录下面的.
/usr/local/mysql
/usr/local/apache2
/usr/local/php
我新建了一个 /server 目录, 把它们都安装在这个目录下面, 方便管理.
/server/mysql
/server/apache2
/server/php
1. 先安装 mysql 和 apache2 的依赖包, 解决好依赖问题, 省的配置是出问题
[plain] view plaincopy
-
[kuaile@kuailepc ~]$ sudo yum-builddep install community-mysql-serversudo //安装mysql的依赖包
-
[kuaile@kuailepc ~]$ sudo yum-builddep install apache //安装apache的依赖包
yum-builddep 这个工具很强大 , 自动把软件包的依赖全部安装完毕. 不用自己慢慢一个一个安装.
2. 安装mysql
创建mysql组和mysql用户
-
[kuaile@kuailepc ~]$ sudo groupadd mysql
-
[kuaile@kuailepc ~]$ sudo useradd -r -g mysql mysql
解压源码并进入到其目录
-
[kuaile@kuailepc ~]$ cd /home/kuaile/bd
-
[kuaile@kuailepc bd]$ ls
-
apache-tomcat-8.0.0-RC10-src.tar.gz nginx-1.4.4.tar.gz
-
apache-tomcat-8.0.0-RC10.tar.gz php-5.5.8.tar.gz
-
httpd-2.4.7.tar.gz postgresql-9.3.2.tar.bz2
-
mariadb-5.5.34.tar.gz resin-4.0.38-src.zip
-
mysql-5.6.15.tar.gz subversion-1.8.5.tar.gz
-
[kuaile@kuailepc bd]$ tar zxvf mysql-5.6.15.tar.gz
-
[kuaile@kuailepc bd]$ cd /home/kuaile/bd/mysql-5.6.15
-
[kuaile@kuailepc mysql-5.6.15]$ ls
-
BUILD dbug libmysqld regex unittest
-
BUILD-CMAKE Docs libservices scripts VERSION
-
client Doxyfile-perfschema man sql vio
-
cmake extra mysql-test sql-bench win
-
CMakeLists.txt include mysys sql-common zlib
-
cmd-line-utils INSTALL-SOURCE mysys_ssl storage
-
config.h.cmake INSTALL-WIN-SOURCE packaging strings
-
configure.cmake libevent plugin support-files
-
COPYING libmysql README tests
设置编译优化参数
-
[kuaile@kuailepc mysql-5.6.15]$ export CFLAGS="-O2 -mtune=corei7 -march=corei7"
-
[kuaile@kuailepc mysql-5.6.15]$ export CXXFLAGS="-O2 -mtune=corei7 -march=corei7"
这是我自己根据自己的cpu而设定的优化参数,并不通用,
下面的更通用一点,让gcc自己检测cpu,自己根据cpu优化
-
[kuaile@kuailepc mysql-5.6.15]$ export CFLAGS="-O2 -mtune=native -march=native"
-
[kuaile@kuailepc mysql-5.6.15]$ export CXXFLAGS="-O2 -mtune=native -march=native"
下面俩条命令可以参看到 -mtune=native -march=native 的具体优化参数的值
-
//查看 -march=native 的值
-
[kuaile@localhost ~]$ gcc -march=native -E -v - </dev/null 2>&1 | grep cc1
-
/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/cc1 -E -quiet -v - -march=corei7 -mcx16 -msahf -mno-movbe -mno-aes -mno-pclmul -mpopcnt -mno-abm -mno-lwp -mno-fma -mno-fma4 -mno-xop -mno-bmi -mno-bmi2 -mno-tbm -mno-avx -mno-avx2 -msse4.2 -msse4.1 -mno-lzcnt -mno-rtm -mno-hle -mno-rdrnd -mno-f16c -mno-fsgsbase -mno-rdseed -mno-prfchw -mno-adx -mfxsr -mno-xsave -mno-xsaveopt --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=4096 -mtune=corei7
-
-
//查看 -mtune=native 的值
-
[kuaile@localhost ~]$ gcc -mtune=native -E -v - </dev/null 2>&1 | grep cc1
-
/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/cc1 -E -quiet -v - --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=4096 -mtune=corei7 -march=x86-64
配置编译选项
-
[kuaile@kuailepc mysql-5.6.15]$ cmake . \
-
> -DCMAKE_INSTALL_PREFIX=/server/mysql \ //设置mysql的安装目录为/server/mysql. 默认的是/usr/local/mysql
-
> -DMYSQL_DATADIR=/server/mysqldata \ //设置mysql数据的目录为/server/mysqldata. 默认是在mysql的安装目录下面
-
> -DSYSCONFDIR=/etc //设置mysql配置文件my.cnf所在目录是/etc. 默认是mysql的安装目录下面
-
-- Running cmake version 2.8.12.1 //mysql 默认的生成的配置文件就在安装目录下面, 需要拷贝到 /etc 目录下面
-
-- The C compiler identification is GNU 4.8.2
-
-- The CXX compiler identification is GNU 4.8.2
-
......
-
-- Library mysqlserver depends on OSLIBS -lpthread;m;crypt;dl;aio
-
-- Configuring done
-
-- Generating done
-
-- Build files have been written to: /home/kuaile/bd/mysql-5.6.15
-
// 开始编译
-
[kuaile@kuailepc mysql-5.6.15]$ make -j4 //-j4 四线程编译, 默认是1线程的, -j 是让make程序自己确定线程数
-
Scanning dependencies of target INFO_BIN
-
Scanning dependencies of target INFO_SRC
-
Scanning dependencies of target abi_check
-
Scanning dependencies of target zlib
-
[ 0%] [ 0%] Building C object zlib/CMakeFiles/zlib.dir/adler32.c.o
-
Built target INFO_SRC
-
Scanning dependencies of target yassl
-
[ 0%] Built target INFO_BIN
-
...
-
Linking CXX executable pfs_connect_attr-t
-
[100%] Built target mysqld
-
Scanning dependencies of target udf_example
-
[100%] Building CXX object sql/CMakeFiles/udf_example.dir/udf_example.cc.o
-
[100%] Built target pfs_connect_attr-t
-
Linking CXX shared module udf_example.so
-
[100%] Built target udf_example
-
-
[kuaile@kuailepc mysql-5.6.15]$ sudo make install //编译完成数安装
-
[ 0%] Built target INFO_BIN
-
[ 0%] Built target INFO_SRC
-
[ 0%] Built target abi_check
-
...
-
-- Installing: /server/mysql/man/man1/mysql-stress-test.pl.1
-
-- Installing: /server/mysql/man/man1/mysql_config_editor.1
-
-- Installing: /server/mysql/man/man8/mysqld.8
-
-- Installing: /server/mysql/support-files/solaris/postinstall-solaris
-
[kuaile@kuailepc mysql-5.6.15]$
-
-
[kuaile@kuailepc mysql-5.6.15]$ cd /server/mysql/
-
[kuaile@kuailepc mysql]$ ls
-
bin data include lib mysql-test scripts sql-bench
-
COPYING docs INSTALL-BINARY man README share support-files
-
[kuaile@kuailepc mysql]$ sudo chown -R mysql . //更改mysql的安装目录所有者为mysql
-
[kuaile@kuailepc mysql]$ sudo chgrp -R mysql . //更改mysql的安装目录所有组为mysql
-
// 初始化mysql的数据库, 不是默认目录的需要添加参数 --datadir=/server/mysqldata 指定目录
-
[kuaile@kuailepc mysql]$ sudo scripts/mysql_install_db --user=mysql --datadir=/server/mysqldata
-
-
1625987
-
OK
-
-
To start mysqld at boot time you have to copy
-
support-files/mysql.server to the right place for your system
-
-
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
-
To do so, start the server, then issue the following commands:
-
-
./bin/mysqladmin -u root password 'new-password'
-
./bin/mysqladmin -u root -h kuailepc password 'new-password'
-
-
Alternatively you can run:
-
-
./bin/mysql_secure_installation
-
-
which will also give you the option of removing the test
-
databases and anonymous user created by default. This is
-
strongly recommended for production servers.
-
-
See the manual for more instructions.
-
-
You can start the MySQL daemon with:
-
-
cd . ; ./bin/mysqld_safe &
-
-
You can test the MySQL daemon with mysql-test-run.pl
-
-
cd mysql-test ; perl mysql-test-run.pl
-
-
Please report any problems with the ./bin/mysqlbug script!
-
-
The latest information about MySQL is available on the web at
-
-
http://www.mysql.com
-
-
Support MySQL by buying support/licenses at http://shop.mysql.com
-
-
New default config file was created as ./my.cnf and
-
will be used by default by the server when you start it.
-
You may edit this file to change server settings
-
-
[kuaile@kuailepc mysql]$
-
-
[kuaile@kuailepc mysql]$ sudo chown -R root . //更改mysql的安装目录所有者为root
-
[kuaile@kuailepc mysql]$ cd /server
-
[kuaile@kuailepc server]$ ls
-
mysql mysqldata
-
[kuaile@kuailepc server]$ chown -R mysql mysqldata //更改mysql的数据库目录所有者为mysql
-
[kuaile@kuailepc server]$ cd mysql
-
[kuaile@kuailepc mysql]$ ls
-
in data include lib mysql-test scripts sql-bench
-
COPYING docs INSTALL-BINARY man README share support-files
-
[kuaile@kuailepc mysql]$ sudo support-files/mysql.server start //启动mysql服务
-
[sudo] password for kuaile:
-
Starting MySQL. [ 确定 ]
-
[kuaile@kuailepc mysql]$
-
[kuaile@kuailepc mysql]$ ./bin/mysqladmin -u root password 'like#girls&boys' // 设定mysql的root的密码
-
//[kuaile@kuailepc mysql]$ ./bin/mysqladmin -u root -h localhost password 'like#girls&boys'
-
[kuaile@kuailepc mysql]$
-
[kuaile@kuailepc mysql]$ sudo ./bin/mysql_secure_installation //运行mysql的安全设置
-
[sudo] password for kuaile:
-
-
-
-
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
-
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
-
-
In order to log into MySQL to secure it, we'll need the current
-
password for the root user. If you've just installed MySQL, and
-
you haven't set the root password yet, the password will be blank,
-
so you should just press enter here.
-
-
Enter current password for root (enter for none): //根据提示输入刚才设置的root的密码, 没设置的就直接回车
-
OK, successfully used password, moving on...
-
-
Setting the root password ensures that nobody can log into the MySQL
-
root user without the proper authorisation.
-
-
You already have a root password set, so you can safely answer 'n'.
-
-
Change the root password? [Y/n] y //是否更改密码, 是的输入俩次新的密码
-
New password:
-
Re-enter new password:
-
Password updated successfully!
-
Reloading privilege tables..
-
... Success!
-
-
-
By default, a MySQL installation has an anonymous user, allowing anyone
-
to log into MySQL without having to have a user account created for
-
them. This is intended only for testing, and to make the installation
-
go a bit smoother. You should remove them before moving into a
-
production environment.
-
-
Remove anonymous users? [Y/n] y //是否移除 anonymous 用户
-
... Success!
-
-
Normally, root should only be allowed to connect from 'localhost'. This
-
ensures that someone cannot guess at the root password from the network.
-
-
Disallow root login remotely? [Y/n] y //是否不允许root远程登陆
-
... Success!
-
-
By default, MySQL comes with a database named 'test' that anyone can
-
access. This is also intended only for testing, and should be removed
-
before moving into a production environment.
-
-
Remove test database and access to it? [Y/n] y //是否删除测试数据
-
- Dropping test database...
-
... Success!
-
- Removing privileges on test database...
-
... Success!
-
-
Reloading the privilege tables will ensure that all changes made so far
-
will take effect immediately.
-
-
Reload privilege tables now? [Y/n] y //是否重载授权表
-
... Success!
-
-
-
-
-
All done! If you've completed all of the above steps, your MySQL
-
installation should now be secure.
-
-
Thanks for using MySQL!
-
-
-
Cleaning up...
-
-
[kuaile@kuailepc mysql]$
-
[kuaile@kuailepc mysql]$ sudo support-files/mysql.server stop //停止mysql服务
-
Shutting down MySQL.. [ 确定 ]
-
[kuaile@kuailepc mysql]$
3. 安装apache2
-
[kuaile@kuailepc ~]$ cd /home/kuaile/bd
-
[kuaile@kuailepc bd]$ ls
-
abb mysql-5.6.15.tar.gz
-
apache-tomcat-8.0.0-RC10-src.tar.gz nginx-1.4.4.tar.gz
-
apache-tomcat-8.0.0-RC10.tar.gz php-5.5.8.tar.gz
-
httpd-2.4.7.tar.gz postgresql-9.3.2.tar.bz2
-
mariadb-5.5.34.tar.gz resin-4.0.38-src.zip
-
mysql-5.6.15 subversion-1.8.5.tar.gz
-
[kuaile@kuailepc bd]$ tar zxvf httpd-2.4.7.tar.gz
-
[kuaile@kuailepc bd]$ ls
-
abb mysql-5.6.15.tar.gz
-
apache-tomcat-8.0.0-RC10-src.tar.gz nginx-1.4.4.tar.gz
-
apache-tomcat-8.0.0-RC10.tar.gz php-5.5.8.tar.gz
-
httpd-2.4.7 postgresql-9.3.2.tar.bz2
-
httpd-2.4.7.tar.gz resin-4.0.38-src.zip
-
mariadb-5.5.34.tar.gz subversion-1.8.5.tar.gz
-
mysql-5.6.15
-
[kuaile@kuailepc bd]$ cd httpd-2.4.7/
-
//设置编译优化参数, 同上,根据情况修改
-
[kuaile@kuailepc httpd-2.4.7]$ export CFLAGS="-O2 -mtune=corei7 -march=corei7"
-
[kuaile@kuailepc httpd-2.4.7]$ export CXXFLAGS="-O2 -mtune=corei7 -march=corei7"
-
[kuaile@kuailepc httpd-2.4.7]$ ./configure --prefix=/server/apache2 --enable-module=so
-
[kuaile@kuailepc httpd-2.4.7]$ make -j4
-
[kuaile@kuailepc httpd-2.4.7]$ sudo make install
-
[kuaile@kuailepc httpd-2.4.7]$
-
[kuaile@kuailepc httpd-2.4.7]$ cd /server/apache2
-
[kuaile@kuailepc apache2]$ ls
-
bin cgi-bin error icons logs manual
-
build conf htdocs include man modules
-
[kuaile@kuailepc apache2]$ sudo bin/apachectl start //启动apache2 服务
这时,用浏览器打开 127.0.0.1 显示 It's work 及apache2 成功启动.
apache2 默认的 web 存放目录在安装目录下面的 htdocs 文件夹, 就是 /server/apache2/htdocs
我把它修改为 /server/WWW 目录了
编辑 apache2 的配置文件,默认在安装目录下的 /cnf/httpd.cnf, 就是 /server/apache2/cnf/httpd.cnf
sudo vi /server/apache2/cnf/httpd.cnf
把 htdocs 更改为 /server/WWW
把
DocumentRoot "/server/apache2/htdocs"
<Directory "/server/apache2/htdocs">
更改为
DocumentRoot "/server/WWWW"
<Directory "/server/WWW">
4. 安装php
-
[kuaile@kuailepc apache2]$ cd /home/kuaile/bd
-
[kuaile@kuailepc bd]$ ls
-
abb mysql-5.6.15.tar.gz
-
apache-tomcat-8.0.0-RC10-src.tar.gz nginx-1.4.4.tar.gz
-
apache-tomcat-8.0.0-RC10.tar.gz php-5.5.8.tar.gz
-
httpd-2.4.7 postgresql-9.3.2.tar.bz2
-
httpd-2.4.7.tar.gz resin-4.0.38-src.zip
-
mariadb-5.5.34.tar.gz subversion-1.8.5.tar.gz
-
mysql-5.6.15
-
[kuaile@kuailepc bd]$ tar zxvf php-5.5.8.tar.gz
-
[kuaile@kuailepc bd]$ cd php-5.5.8
-
[kuaile@kuailepc php-5.5.8]$ ./configure --prefix=/server/php --with-mysql --with-apxs2=/server/apache2/bin/apxs
-
[kuaile@kuailepc php-5.5.8]$ make -j4
-
[kuaile@kuailepc php-5.5.8]$ sudo make install
-
-
// 拷贝php的默认配置文件到安装目录
-
[kuaile@kuailepc php-5.5.8]$ sudo cp php.ini-development /server/php/lib/php.ini
安装完成后, 开始配置.
还是打开apache2 的配置文件 /server/apache2/cnf/httpd.cnf
sudo vi /server/apache2/cnf/httpd.cnf
检查apache2是否启用了php模块,
LoadModule php5_module modules/libphp5.so
如果这行前面有注释 # 号 , 就把它去掉.
添加php类型主页
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
index.html 后面添加上 index.php.
找到 AddType 的位置, 在下面就添加php的类型
AddType application/x-httpd-php .php .php2, .php3, .php4, .php5, .php6 .phtml .inc
AddType application/x-httpd-php-source .phps
配置完成后,新建个ceshi.php文件测试一下.
ceshi.php文件内容为
<?php
phpinfo();
?>
把它放到apache2 的 web目录下面, 也就是 /server/WWW 目录下面.
重启 apache 服务, 每次更改配置文件后, 都需要重启才生效.
在浏览器里输入 php 文件的地址, 127.0.0.1/ceshi.php.
如图就是安装成功了.
(责任编辑:IT) |