操作环境:CentOS 7.2
LAMP即Linux Apache Mariadb php
一、普通的yum安装构建
yum install mariadb-server httpd php php-mysql
[root@localhost ~]# yum install httpd php php-mysql mariadb-server Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Package httpd-2.4.6-40.el7.centos.x86_64 already installed and latest version Package php-5.4.16-36.el7_1.x86_64 already installed and latest version Package php-mysql-5.4.16-36.el7_1.x86_64 already installed and latest version Package 1:mariadb-server-5.5.44-2.el7.centos.x86_64 already installed and latest version Nothing to do [root@localhost ~]#
给mariadb添加额外配置/etc/my.cnf
设置mariadb的root用户密码
#首先启动mysql服务 [root@localhost ~]# systemctl start mariadb #键入mysql_secure_installation,更改密码 [root@localhost ~]# mysql_secure_installation /usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, 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@localhost ~]# cat /var/www/html/phpinfo.php [root@localhost ~]# cat /var/www/html/php-mysql.php [root@localhost ~]#
重启httpd服务然后测试
关闭数据库再次测试
[root@localhost ~]# systemctl stop mariadb [root@localhost ~]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 128 127.0.0.1:631 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 :::80 :::* LISTEN 0 128 :::22 :::* LISTEN 0 128 ::1:631 :::* LISTEN 0 100 ::1:25 :::* [root@localhost ~]# #3306端口关闭
二、编译安装LAMP
(1)操作环境:
CentOS 7:httpd-2.4, mariadb, php-5.4
安装次序:httpd, mariadb, php
(2) 开发环境:
Development Tools, Server Platform Development
(3)包版本
mariadb:ariadb-5.5.46-linux-x86_64.tar.gz
httpd:httpd-2.4.10.tar.bz2
php:php-5.4.40.tar.bz2
安装MariaDB:(通用二进制格式的程序包)
将压缩包展开至/usr/local下,并创建链接mysql
[root@localhost ~]# tar xf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local/ [root@localhost ~]# cd /usr/local/ [root@localhost local]# ls bin etc games include lib lib64 libexec mariadb-5.5.46-linux-x86_64 sbin share src [root@localhost local]# ln -sv mariadb-5.5.46-linux-x86_64 mysql ‘mysql’ -> ‘mariadb-5.5.46-linux-x86_64’ [root@localhost local]# ls bin etc games include lib lib64 libexec mariadb-5.5.46-linux-x86_64 mysql sbin share sr
查看是否有mysql用户和mysql组,如果没有,则添加
[root@localhost local]# id mysql uid=27(mysql) gid=27(mysql) groups=27(mysql)
创建mysql的数据目录并更改属组属主
[root@localhost local]# mkdir /mydata/data -pv mkdir: created directory ‘/mydata’ mkdir: created directory ‘/mydata/data’ [root@localhost local]# chown -R mysql.mysql /mydata/data/
更改mysql的安装目录中文件的属组,改为mysql
[root@localhost mysql]# chown -R root:mysql ./* [root@localhost mysql]# ll total 204 drwxr-xr-x 2 root mysql 4096 Oct 16 15:03 bin -rw-r--r-- 1 root mysql 17987 Oct 10 2015 COPYING -rw-r--r-- 1 root mysql 26545 Oct 10 2015 COPYING.LESSER drwxr-xr-x 3 root mysql 17 Oct 16 15:03 data -rw-r--r-- 1 root mysql 8245 Oct 10 2015 EXCEPTIONS-CLIENT drwxr-xr-x 3 root mysql 18 Oct 16 15:03 include -rw-r--r-- 1 root mysql 8694 Oct 10 2015 INSTALL-BINARY drwxr-xr-x 3 root mysql 4096 Oct 16 15:03 lib drwxr-xr-x 4 root mysql 28 Oct 16 15:03 man drwxr-xr-x 11 root mysql 4096 Oct 16 15:03 mysql-test -rw-r--r-- 1 root mysql 108813 Oct 10 2015 README drwxr-xr-x 2 root mysql 29 Oct 16 15:03 scripts drwxr-xr-x 27 root mysql 4096 Oct 16 15:03 share drwxr-xr-x 4 root mysql 4096 Oct 16 15:03 sql-bench drwxr-xr-x 3 root mysql 4096 Oct 16 15:03 support-files
安装msyql并添加选项
[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data --skip_name_resolve Installing MariaDB/MySQL system tables in '/mydata/data' ... 161016 15:18:52 [Note] ./bin/mysqld (mysqld 5.5.46-MariaDB) starting as process 1489 ... OK Filling help tables... 161016 15:18:52 [Note] ./bin/mysqld (mysqld 5.5.46-MariaDB) starting as process 1497 ... OK To start mysqld at boot time you have to copy .......省略...... The latest information about MariaDB is available at http://mariadb.org/. You can find additional information about the MySQL part at: http://dev.mysql.com Support MariaDB development by buying support/new features from MariaDB Corporation Ab. You can contact us about this at [email protected]. Alternatively consider joining our community based development effort: http://mariadb.com/kb/en/contributing-to-the-mariadb-project/
复制样例配置文件,并做如下修改
复制服务的启动脚本并使其开机自启
[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld [root@localhost mysql]# ls /etc/rc.d/init.d/mysqld /etc/rc.d/init.d/mysqld chkconfig --add mysqld
将编译文件中的bin目录整合至PATH
[root@localhost php-5.4.40]# echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh
更改mysql的默认root密码为xiaoshui
root@localhost php-5.4.40]# mysql_secure_installation /usr/local/mysql/bin/mysql_secure_installation: line 379: find_mysql_client: command not found NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, 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@localhost mysql]# service mysqld start Starting MySQL... [ OK ]
编译安装httpd
安装好如下的开发包
[root@localhost ~]# yum install pcre-devel openssl-devel libevent-devel apr-devel apr-util-devel -y
解压httpd源码包并cd至解压的目录
[root@localhost ~]# tar xf httpd-2.4.10.tar.bz2 [root@localhost ~]# cd httpd-2.4.10/ [root@localhost httpd-2.4.10]#
配置相应的编译选项生成makefile文件如下
#安装目录在/usr/local/apache2,配置文件所在目录为/etc/httpd等等其他的选项 [root@localhost httpd-2.4.10]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork --with-pcre --with-zlib --with-apr=/usr --with-apr-util=/usr
执行make和make install
[root@localhost httpd-2.4.10]# make && make install
添加编译的bin目录至环境变量,然后重读配置文件启动服务
[root@localhost httpd-2.4.10]# echo "export PATH=/usr/local/apache2/bin:$PATH" > /etc/profile.d/httpd.sh [root@localhost httpd-2.4.10]# . /etc/profile.d/httpd.sh [root@localhost httpd-2.4.10]# apachectl start AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message [root@localhost httpd-2.4.10]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 50 *:3306 *:* LISTEN 0 128 *:22 *:* LISTEN 0 128 127.0.0.1:631 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 :::80 :::* LISTEN 0 128 :::22 :::* LISTEN 0 128 ::1:631 :::* LISTEN 0 100 ::1:25 :::* #80端口成功开启!
访问测试
编译安装php5:
安装如下开发包
[root@localhost ~]# yum install gd-devel freetype-devel libxml2-devel libmcrypt-devel
解压php源码包
[root@localhost ~]# tar xf php-5.4.40.tar.bz2
编译安装生成makefile文件
[root@localhost php-5.4.40]# ./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-openssl --enable-mbstring --enable-xml --enable-sockets --with-freetype-dir --with-gd --with-libxml-dir=/usr --with-zlib --with-jpeg-dir --with-png-dir --with-mcrypt --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/etc/php.ini --with-config-file-scan-dir=/etc/php.d/
执行make && make install
[root@localhost php-5.4.40]# make && make install ......省略... Wrote PEAR system config file at: /usr/local/php5/etc/pear.conf You may want to add: /usr/local/php5/lib/php to your php.ini include_path /root/php-5.4.40/build/shtool install -c ext/phar/phar.phar /usr/local/php5/bin ln -s -f /usr/local/php5/bin/phar.phar /usr/local/php5/bin/phar Installing PDO headers: /usr/local/php5/include/php/ext/pdo/
复制样例文件至/etc/下做php的配置文件
[root@localhost php-5.4.40]# cp php.ini-production /etc/php.ini
提供网站测试页(编译安装的网站根路径默认在安装目录下的htdocs目录下)
[root@localhost php-5.4.40]# cat /usr/local/apache2/htdocs/phpinfo.phpHtdocs
[root@localhost php-5.4.40]# cat /usr/local/apache2/htdocs/php-mysql.php
Htdocs
编译php为httpd的模块后,编辑/etc/httpd/httpd.conf整合php至httpd:
重启服务测试
关闭mysql服务再次测试
[root@localhost php-5.4.40]# service mysqld stop Shutting down MySQL.. [ OK ] [root@localhost php-5.4.40]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 128 127.0.0.1:631 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 :::80 :::* LISTEN 0 128 :::22 :::* LISTEN 0 128 ::1:631 :::* LISTEN 0 100 ::1:25 :::*
谢谢浏览.....
编译安装中出现的问题:
如果出现了mcrypt.h错误,提示重新安装,使用yum -y libmcrypt.devel安装此开发包