centOS搭建LAMP服务器
1、配置网络
vi /etc/sysconfig/network-scripts/ifcfg-ens33
ONBOOT=yes
2、关闭防火墙(设置为开机不启动)
systemctl disable firewalld.service
3、修改主机名(可选)
hostnamectl set-hostname xxxx
4、更改selinux配置:
vi /etc/selinux/config
5、重启网络
systemctl restart network
6、确认centOS版本(本篇采用7.0以上版本):
cat /etc/redhat-release
7、检查是否安装过apache(三选一)
rpm -qa | grep httpd
apachectl -v
httpd -v
8、检查是否安装过MySQL
systemctl start mysqld.service
如果未被识别则没有安装
9、移除MySQL
yum remove mysql
rm -f /etc/my.cnf
10、卸载Apache包
rpm -qa|grep httpd
11、安装apache
yum -y install httpd
12、安装PHP
yum -y install php
13、安装php-form
yum -y install php-fpm
14、安装MySQL
下载:wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
解压:rpm -ivh mysql-community-release-el7-5.noarch.rpm
安装:yum install mysql-community-server
15、安装php-mysql
yum -y install php-mysql
16、安装常用扩展包
yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql
yum -y install php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc php-devel
yum -y install mysql-connector-odbc mysql-devel libdbi-dbd-mysql
17、启动Apache
systemctl start httpd.service #启动apache
systemctl stop httpd.service #停止apache
systemctl restart httpd.service #重启apache
systemctl enable httpd.service #设置apache开机启动
18、启动MySQL
systemctl start mysqld.service
systemctl restart mysqld.service
systemctl stop mysqld.service
systemctl enable mysqld.service
19、配置MySQL用户密码
首次登录无密码:mysql -uroot -p
use mysql;
update user set password=password("123456") where user="root";
20、网页打开
搭建开发环境
1、安装git
yum –y install git
2、配置信息
a、设置用户名:git config --global user.name "xxx"
b、输入邮箱:git config --global user.email "xxxx@xxx.com"
c、设置全局密码:git config --global user.password "xxx"
d、设置ssh公钥:ssh-keygen -t rsa -C "xxxx@xxx.com"
3、安装composer
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
php composer-setup.php
mv composer.phar /usr/local/bin/composer
composer config -g repo.packagist composer https://packagist.phpcomposer.com
composer selfupdate
4、创建thinkphp项目
composer create-project topthink/think=5.0.* tp5 --prefer-dist
5、配置apache以访问创建的项目
本项目地址:/var/www/
vi /etc/httpd/conf/httpd.conf
追加:
IncludeOptional conf.d/*.conf # 取消注释
<Directory "/var/www/tp5">
AllowOverride None
Options None
Require all granted
</Directory>
6、vi /etc/httpd/conf.d/httpd-vhosts.conf ,填入以下内容:
<VirtualHost *:80>
ServerName lamp01
DocumentRoot '/var/www/tp5/public'
<Directory "/var/www/tp5/public">
AllowOverride All
Order allow,deny
Allow from all
Options FollowSymLinks
Require all granted
DirectoryIndex index.php
</Directory>
</VirtualHost>
7、访问ip测试: