一、配置
系统:Centos7.4
Apache:2.4
PHP:PHP7.2
二、Apache
- 安装Apache
-
yum install httpd
配置ServerName
-
vim /etc/httpd/conf/httpd.conf 搜索 AddType application/x-gzip .gz .tgz 然后在后面添加 AddType application/x-httpd-php .php 搜索 IfModule dir_module 在DirectoryIndex下面添加 index.php 修改#ServerName www.example.com:80 ServerName localhost:80 修改默认Web站点目录 找到: DocumentRoot "/var/www/html" 修改为: DocumentRoot "/var/www" 找到:<Directory "/var/www/html"> 修改为:<Directory "/var/www">
启动Apache服务
-
systemctl start httpd
查看httpd状态
systemctl status httpd
三、PHP7.2
- 安装wget
yum install wget
-
在/usr/local/src 目录下下载php源码包
wget http://cn2.php.net/distributions/php-7.2.4.tar.gz
-
解压源码包
tar zxvf php-7.2.4.tar.gz
-
进入解压包安装编译php需要的依赖包
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel yum -y install libxslt-devel* yum -y install perl* yum -y install httpd-devel find / -name apxs 得到的路径是:/usr/bin/apxs 于是得到--with-apsx2的路径是/usr/bin/apxs --这个是编译参数的时候用到,是配置Apache支持PHP的关键参数
-
编译参数
./configure \ --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --with-zlib-dir \ --with-freetype-dir \ --enable-mbstring \ --with-libxml-dir=/usr \ --enable-xmlreader \ --enable-xmlwriter \ --enable-soap \ --enable-calendar \ --with-curl \ --with-zlib \ --with-gd \ --with-pdo-sqlite \ --with-pdo-mysql \ --with-mysqli \ --with-mysql-sock \ --enable-mysqlnd \ --disable-rpath \ --enable-inline-optimization \ --with-bz2 \ --with-zlib \ --enable-sockets \ --enable-sysvsem \ --enable-sysvshm \ --enable-pcntl \ --enable-mbregex \ --enable-exif \ --enable-bcmath \ --with-mhash \ --enable-zip \ --with-pcre-regex \ --with-jpeg-dir=/usr \ --with-png-dir=/usr \ --with-openssl \ --enable-ftp \ --with-kerberos \ --with-gettext \ --with-xmlrpc \ --with-xsl \ --enable-fpm \ --with-fpm-user=php-fpm \ --with-fpm-group=php-fpm \ --with-fpm-systemd \ --with-apsx2 \ --disable-fileinfo
-
编译并安装
make && make install
-
复制php.ini
cp php.ini-production /usr/local/php/etc/php.ini
-
复制php-fpm配置文件
cd /usr/local/php/etc cp php-fpm.conf.default php-fpm.conf
-
配置php-fpm
vim php-fpm.conf 配置错误日志: error_log = /usr/local/php/var/php-fpm.log 配置pid文件: pid = /usr/local/php/var/run/php-fpm.pid 保存退出
cd /usr/local/php/etc/php-fpm.d cp www.conf.default www.conf
-
管理php-fpm
cd /usr/local/src/php-7.2.4 cp ./sapi/fpm/php-fpm.service 到 /usr/lib/systemd/system/下 配置开机启动php-fpm: systemctl enable php-fpm 启动php-fpm: systemctl start php-fpm 查看状态: systemctl status php-fpm
-
添加环境变量
vim /etc/profile 在末尾添加 export PATH=$PATH:'/usr/local/php/bin/' 保存退出
-
测试是否成功
php -v
-
如果需要区分web和cli
cp /usr/local/php/etc/php.ini /usr/local/php/etc/php-cli.ini
四、MySQL5.7
- 安装
- 添加源
rpm -Uvh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
-
安装
yum install mysql-community-server
- 添加源
-
设置
-
防火墙设置
firewall-cmd --zone=public --permanent --add-service=mysql firewall-cmd --reload
-
启动并设置开机自启
systemctl start mysqld 开机自启 systemctl enable mysqld
-
在更改root默认密码前,可以根据需要,关闭密码策略。 如果没有关闭密码策略,则新密码要求是大小写字母+数字+字符的组合。
vi /etc/my.cnf [mysqld] validate_password = off 重启,使修改后的密码策略生效 systemctl restart mysqld
-
修改MySQL的root默认密码
查看默认密码 grep 'temporary password' /var/log/mysqld.log //默认密码是: )U4FB:Kw!evF 2018-07-23T03:08:50.781727Z 1 [Note] A temporary password is generated for root@localhost: )U4FB:Kw!evF
运行安全设置向导,并修改默认密码 mysql_secure_installation //输入root默认密码 Enter password for user root: *** //设置新密码 New password:*** Re-enter new password: *** //是否更改root密码 Change the password for root ? ((Press y|Y for Yes, any other key for No) ://直接回车,表示No //是否删除匿名用户 Remove anonymous users? (Press y|Y for Yes, any other key for No) : y //禁止root远程登录 Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y //删除test数据库 Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y //重新加载权限表 Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
也可以使用mysql直接更改root密码 mysql -uroot -p ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'; exit;
为安全root仅限本地登录,根据需要可以新建一个有管理员权限的远程用户 mysql -uroot -p GRANT ALL PRIVILEGES ON *.* TO '用户名'@'%' IDENTIFIED BY '登录密码' WITH GRANT OPTION; FLUSH PRIVILEGES; exit;
自此,LAMP安装完成! (这里有一个小问题,是关于防火墙的,我会在下篇文章里写到)
-