LAMP环境搭建
程序员文章站
2022-07-02 15:33:50
[TOC] "上一篇" 文章讲述了如何搭建LNMP开发环境,这次将讲述如何搭建 开发环境。搭建环境的过程中需要下载一些安装包,我们可以通过CentOS的yum命令下载,也可以通过FileZilla工具提前下载好,然后传输到CentOS中,这里我们假定我们把下载好的安装包都放到了/usr/src目录下 ......
目录
文章讲述了如何搭建lnmp开发环境,这次将讲述如何搭建lamp
开发环境。搭建环境的过程中需要下载一些安装包,我们可以通过centos的yum命令下载,也可以通过filezilla工具提前下载好,然后传输到centos中,这里我们假定我们把下载好的安装包都放到了/usr/src目录下,放到这里的目的是统一便于管理,你也可以放到你喜欢的目录中。
安装apache
安装依赖
sudo yum install gcc gcc-c++ perl perl-devel expat expat-devel autoconf libtool openssl openssl-devel
安装apr
下载地址:https://apr.apache.org,这里统一把安装包都下载到/usr/src目录下,便于管理 cd /usr/src tar -zxvf apr-1.6.3.tar.gz cd apr-1.6.3 ./configure --prefix=/usr/local/apr make && make install
安装apr-util
下载地址:https://apr.apache.org/ cd /usr/src tar -zxvf apr-util-1.6.1.tar.gz cd apr-util-1.6.1 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr make && make install
安装pcre
下载地址:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ cd /usr/src tar zxvf pcre-8.42.tar.gz cd pcre-8.42 ./configure --prefix=/usr/local/pcre make && make install
编译安装apache
tar zxvf httpd-2.4.33.tar.gz cd httpd-2.4.33 ./configure \ --prefix=/usr/local/apache \ --enable-ssl \ --enable-so \ --with-apr=/usr/local/apr \ --with-apr-util=/usr/local/apr-util \ --with-pcre=/usr/local/pcre make && make install
配置环境变量
vi /etc/profile export path="$path:/usr/local/apache/bin" source /etc/profile
设置开机自启
vim /etc/rc.d/rc.local /usr/local/apache/bin/apachectl start
其他配置
sr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak cp /usr/local/apache/conf/extra/httpd-vhosts.conf /usr/local/apache/conf/extra/httpd-vhosts.conf.bak vi /usr/local/apache/conf/httpd.conf 去掉152行前面的#号,开启重写模块 去掉194行前面的#号,去除错误信息 239行允许重写 allowoverride all 开启apache: apachectl -k start
关闭防火墙
centos6: service iptables stop 临时关闭 chkconfig --level 2345 iptables off 永久关闭 centos7: systemctl stop firewalld.service #令关闭防火墙 systemctl disable firewalld.service #关闭防火墙开机自启动 通过浏览器输入ip测试成功
安装mysql
安装依赖
(1)cmake是新版mysql的编译工具,必须安装
sudo yum install gcc gcc-c++ cmake ncurses-devel
如果你的系统是centos7,你还需要安装如下依赖
sudo yum install perl perl-devel autoconf
编译安装mysql
useradd -s /sbin/nologin -m mysql # 添加mysql用户 wget https://dev.mysql.com/get/downloads/mysql-5.6/mysql-5.6.41.tar.gz tar zxvf mysql-5.6.41.tar.gz cd mysql-5.6.41 cmake -dcmake_install_prefix=/usr/local/mysql-5.6.41 \ -dmysql_unix_addr=/usr/local/mysql-5.6.41/tmp/mysql.sock \ -dmysql_datadir=/usr/local/mysql-5.6.41/data \ -ddefault_charset=utf8 \ -ddefault_collation=utf8_general_ci \ -dwith_extra_charsets=all \ -dwith_myisam_storage_engine=1 \ -dwith_innobase_storage_engine=1 \ -dwith_memory_storage_engine=1 \ -dwith_readline=1 \ -dwith_innodb_memcached=1 \ -dwith_debug=off \ -dwith_zlib=bundled \ -denabled_local_infile=1 \ -denabled_profiling=on \ -dmysql_maintainer_mode=off \ -dmysql_tcp_port=3306 make && make install
mysql配置
cd /usr/local/mysql-5.6.41 chown mysql.mysql /usr/local/mysql-5.6.41/data mkdir tmp chown mysql.mysql /usr/local/mysql-5.6.41/tmp rm -f /etc/my.cnf cp support-files/my-default.cnf /etc/my.cnf scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql
加入守护进程
cd /usr/local ln -s mysql-5.6.41 mysql cd /usr/local/mysql cp support-files/mysql.server /etc/init.d/mysqld chkconfig --add mysqld
配置环境变量
vim /etc/profile export path="/usr/local/mysql/bin" source /etc/profile
启动mysql
service mysqld start mysql -u root -p #第一次登陆不需要密码,回车即可 set password for root@localhost = password('root'); #修改密码
安装php
安装依赖
sudo yum install gcc gcc-c++ libxml2 libxml2-devel curl-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel
编译安装php
tar zxvf php-7.2.3.tar.gz cd php-7.2.3 ./configure \ --prefix=/usr/local/php \ --enable-mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-mysql-sock=/usr/local/mysql/tmp/mysql.sock \ --with-apxs2=/usr/local/apache/bin/apxs \ --with-zlib \ --with-gd \ --with-png-dir \ --with-jpeg-dir \ --with-freetype-dir \ --with-openssl \ --enable-mbstring \ --enable-xml \ --enable-zip \ --enable-sockets \ --with-curl make && make install
配置apache与php关联
vi /usr/local/apache/conf/httpd.conf # 加入 在 加载了php模块之后 <filesmatch "\.php$"> sethandler application/x-httpd-php </filesmatch> # 保存,退出,重启
配置环境变量
vi /etc/profile export path="$path:/usr/local/php/bin" source /etc/profile cp /usr/src/php-7.2.3/php.ini-development /usr/local/php/lib/php.ini vi /usr/local/php/lib/php.ini date.timezone = prc (大约在932行)
配置虚拟主机
vi /usr/local/apache/conf/httpd.conf # 258行,默认首页加入index.php # 483行,开启虚拟主机支持 vi /usr/local/apache/conf/extra/httpd-vhosts.conf vi /usr/local/apache/conf/extra/httpd-vhosts.conf <virtualhost *:80> serveradmin www.huiwan.com documentroot "/mnt/hgfs/web/huiwan" servername www.huiwan.com #errorlog "logs/dummy-host2.example.com-error_log" #customlog "logs/dummy-host2.example.com-access_log" common <directory "/mnt/hgfs/web/huiwan"> options indexes multiviews allowoverride all require all granted </directory> </virtualhost>
下一篇: Redis安装教程