闲来无事,就来再搭建一下lamp环境,贴贴我的安装步骤,熟能生巧,尤其对于我这种菜鸟。yum安装装较为简单,就不在此叙述,下面我们采用源码简单安装。(linux的安装略)
步骤一:先下载所需要的源码包(下载至/usr/src/目录下)
http://apache.dataguru.cn//httpd/httpd-2.2.23.tar.gz
http://download.chinaunix.net/down.php?id=34728&ResourceID=7159&site=1 //一般我们尽量去官网下载,但有些官网下载会收费,有时候我们也去大型的linux自由社区下载,例如我今天用的这个mysql源码包在http://download.chinaunix.net下载。
http://www.php.net/get/php-5.4.11.tar.gz/from/cn2.php.net/mirror
步骤二:安装apache
我们首先确认是否安装gcc,pcre及pcre-devel。如果没安装即执行:
[root@localhost ~]#yum install gcc pcre pcre-devel -y
接下来:
[root@localhost ~]#cd /usr/src/
[root@localhost src]# ls
[root@localhost src]# ls
apache-tomcat-6.0.36.tar.gz httpd-2.2.23.tar.gz mysql-5.0.88.tar.gz
debug jdk-6u26-dlj-linux-amd64.bin
kernels
[root@localhost src]#tar -zxvf httpd-2.2.23.tar.gz
[root@localhost src]# cd httpd-2.2.23
[root@localhost httpd-2.2.23]# ./configure --prefix=/usr/local/apahce/ --enable-so --with-rewrite (--enable-so这个参数是增加模块的意思,方便以后添加模块。--with-rewite这个参数是支持rewrite。其他参数暂时不添加,有什么需求的我们再添加什么参数安装。需要说明的是--with-pcre=/ 参数,当我们采用yum安装pcre及pcre-devel这俩个包时,我们不需要这个参数,当我们采用的是tar包源码安装那俩个包时,我们需指定包放置的路径,而不是安装路径,我们一般采用yum安装即可)
[root@localhost httpd-2.2.23]# ./configure --prefix=/usr/local/apache --with-re
write --enable-so
[root@localhost httpd-2.2.23]#make
[root@localhost httpd-2.4.3]# make install
[root@localhost httpd-2.4.3]# /usr/local/apache/bin/apachectl -t //查看apache的配置文件语法有无问题,有问题根据报错修改,无报错执行下面命令,启动apache。
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
Syntax OK //上面提示没有完整的***verName,将配置文件httpd.conf里面的ServerName前面的#去除就不会再有提醒,不修改也没什么影响。其他语法没问题。
[root@localhost httpd-2.4.3]#/usr/local/apache/bin/apachectl start //启动apache
[root@localhost httpd-2.4.3]#ps -ef |grep httpd //查看有无httpd进程,判断apache是否启动成功。
root 13638 1 0 18:39 ? 00:00:00 /usr/local/apache//bin/httpd -k start
daemon 13639 13638 0 18:39 ? 00:00:00 /usr/local/apache//bin/httpd -k start
daemon 13640 13638 0 18:39 ? 00:00:00 /usr/local/apache//bin/httpd -k start
daemon 13641 13638 0 18:39 ? 00:00:00 /usr/local/apache//bin/httpd -k start
daemon 13642 13638 0 18:39 ? 00:00:00 /usr/local/apache//bin/httpd -k start
daemon 13643 13638 0 18:39 ? 00:00:00 /usr/local/apache//bin/httpd -k start
[root@localhost httpd-2.4.3]#netstat -nutpl |grep httpd //观察httpd启动的端口,默认端口为80.
tcp 0 0 :::80 :::* LISTEN 13638/httpd //httpd服务端口为80
步骤三:安装配置mysql
[root@localhost httpd-2.4.3]#groupadd mysql //新建mysql群组
[root@localhost httpd-2.4.3]# useradd mysql -s /sbin/nologin -g mysql //新建mysql用户,并将mysql用户添加至mysql这个组,且mysql这个用户不用来登录linux系统(nologin)。
[root@localhost httpd-2.4.3]#cd /usr/src/
[root@localhost src]#tar zxvf mysql-5.0.88.tar.gz
[root@localhost src]#cd mysql-5.0.88
[root@localhost mysql-5.0.88]#./configure --prefix=/usr/loacal/mysql/
[root@localhost mysql-5.0.88]#make
[root@localhost mysql-5.0.88]#make install
[root@localhost mysql-5.0.88]#cd /usr/local/mysql/
[root@localhost mysql]#chown -R mysql:mysql . //修改/usr/local/mysql目录下的用户及属组均为mysql。
[root@localhost mysql]# /usr/local/mysql/bin/mysql_install_db --user=mysql //mysql初始化,初始化过程中会提示怎么启动mysql,怎么修改mysql用户密码。
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h localhost.localdomain password 'new-password' //修改用户密码的方法
You can start the MySQL daemon with:
cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe & //第一次启动mysql的方法
但这里尤其重要的是,执行完成后,会生成一个var目录,其属组为root,需修改为mysql。
[root@localhost mysql]#./bin/mysqld_safe & (注意:如果已经用yum安装过mysql,且没有卸载,也不打算卸载。可以查看当前有无mysql已经启动,确认其处于未启动状态,并将其配置文件移走,可以采用:/mv /etc/my.conf /etc/my.conf.bak即可。)
[root@localhost mysql]#ps -ef |grep mysqld |grep -v grep //查看是否有mysqld
进程启动
root 8133 11434 0 19:53 pts/0 00:00:00 /bin/sh ./bin/mysqld_safe
mysql 8150 8133 1 19:53 pts/0 00:00:00 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --user=mysql --pid-file=/usr/local/mysql/var/localhost.localdomain.pid --skip-external-locking
ok,进程已经启动。
[root@localhost mysql]#./bin/mysqladmin -uroot password 123456 //给root用户设定密码[root@localhost mysql]#./bin/mysql -uroot -p123456 //用root用户登录mysql服务
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.88 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases; (能进入mysql对话框,说明能用我们刚修改的密码登录mysql服务器)
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
mysql> create database li; (新建一个数据库待后面用)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| li | (新建的数据库li成功)
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> grant all on *.* to li@'192.168.1.105' identified by '123456';
Query OK, 0 rows affected (0.18 sec) (对数据库li进行授权,及添加密码)
mysql> flush privileges;
Query OK, 0 rows affected (0.06 sec)
mysql安装配置暂时告一段落。
步骤四:安装php
[root@localhost mysql]#cd /usr/local/src
[root@localhost src]#tar zxvf php-5.4.10.tar.gz
[root@localhost src]#cd php
[root@localhost php-5.4.10 ]#./configure --prefix=/usr/local/php/ \
--enable-fpm \ (此参数执行后会生成可执行的fpm ATPI,如果我们需要添加FastCGI这个加速模块需执行此参数)
--with-apxs2=/usr/local/apache/bin/apxs\ (该参数是用来整合apache)
--with-mysql=/usr/local/mysql\
--with-mysqli=/usr/local/mysql/bin/mysql_config (前俩个参数均是用来整合mysql)
[root@localhost php-5.4.10]#make
[root@localhost php-5.4.10]#make test (用来检测安装环境又无问题,执行时间比较长)
[root@localhost php-5.4.10]#make install
[root@localhost php-5.4.10]# cd /usr/local/php/
[root@localhost php]#/usr/local/apache/bin/apachectl start
在浏览器里面访问:ip/index.php
apache整合php成功。
步骤六:apache,php,mysql的整合:安装论坛Discuz
[root@localhost php]#cd /usr/src/
[root@localhost src]#http://download.comsenz.com/DiscuzX/2.5/Discuz_X2.5_SC_UTF8.zip
[root@localhost src]#unzip Discuz_X2.5_SC_UTF8.zip
[root@localhost src]#ls
[root@localhost src]# ls
apache-tomcat-6.0.36.tar.gz httpd-2.4.3.tar.gz php-5.4.10
debug jdk-6u26-dlj-linux-amd64.bin php-5.4.10.tar.gz
Discuz_X2.5_SC_UTF8.zip kernels readme
httpd-2.2.23 mysql-5.0.88 upload
httpd-2.2.23.tar.gz mysql-5.0.88.tar.gz utility
ok,到此为止,我们的lamp源码安装及搭建告一段落。如果你看到此,是对我最好的褒奖。谢谢。新年快乐!