LAMP/LNMP 环境搭建
一.检查系统环境
①确认centos版本
[root@localhost ~]# cat /etc/redhat-release
rpm -qa | grep httpd
或者:
apachectl -v
httpd -v
service mysqld start
如果未被识别则没有安装
如果系统安装过,或者安装失败,清理一下系统
yum remove mysql
rm -f /etc/my.cnf
rpm -qa|grep httpd
注意:如果是新的系统或者你从来没有尝试安装过,则以上步骤省略
二.安装Apache、PHP、Mysql
停止防火墙服务
[root@localhost ~]# systemctl stop firewalld.service
禁用防火墙开机启动服务
[root@localhost ~]# systemctl disable firewalld.service
①安装apache
[root@localhost ~]# yum -y install httpd
[root@localhost ~]# yum -y install php
[root@localhost ~]# yum -y install php-fpm
[root@localhost ~]# yum -y install mysql
[root@localhost ~]# yum install mariadb-server
[root@localhost ~]# yum -y install php-mysql
三.安装基本常用扩展包
①安装Apache扩展包
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
四.配置Apache、mysql开机启动
systemctl start httpd.service #启动apache
systemctl stop httpd.service #停止apache
systemctl restart httpd.service #重启apache
systemctl enable httpd.service #设置apache开机启动
重启数据库
#启动MariaDB
[root@localhost ~]# systemctl start mariadb.service
#停止MariaDB
[root@localhost ~]# systemctl stop mariadb.service
#重启MariaDB
[root@localhost ~]# systemctl restart mariadb.service
#设置开机启动
[root@localhost ~]# systemctl enable mariadb.service
五.配置Mysql
初次安装mysql是没有密码的,我们要设置密码,mysql的默认账户为root
方式1:设置 MySQL 数据 root 账户的密码:
[root@localhost ~]# mysql_secure_installation
当出现如下提示时候直接按回车:
Enter current password for root
出现如下再次回车:
Set root password? [Y/n]
出现如下提示输入你需要设置的密码,这里输入了root,输入密码是不显示的,回车后再输入一次确认:
New password:
此时此刻呢还会有四个确认,分别是:
Remove anonymous users? [Y/n]
Disallow root login remotely? [Y/n]
Remove test database and access to it? [Y/n]
Reload privilege tables now? [Y/n]
直接回车即可.
修改mysql密码:set password for 'root'@'localhost'=password('root');
mysql授权远程连接(navicat等): grant all on *.* to root identified by 'root';
六.测试环境
我们在浏览器地址栏输入,正常显示,说明我们的lamp 环境搭建成功
七.安装nginx
yum install yum-priorities -y
wget
yum install nginx
Nginx 版本号可变更版本
八.配置nginx
①nginx启动,停止,重启
systemctl start nginx.service #启动nginx
systemctl stop nginx.service #停止
systemctl restart nginx.service #重启
systemctl enable nginx.service #设置开机启动
更改nginx端口号(根据自己需求)
cd /etc/nginx/conf.d/
vim default.conf
systemctl start php-fpm.service #启动php-fpm
systemctl enable php-fpm.service #设置开机启动
vi /etc/nginx/conf.d/default.conf,把之前的#给去掉就可以了,顺手改一下
location ~ .php$ {
root html;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name;
include fastcgi_params;
}
方法二 安装nginx
启动nginx,并设置为开机启动
systemctl start nginx
systemctl enable nginx
vim /etc/nginx/conf.d/default.conf
访问即可看到php页面
修改完成配置记得启动apache 和php-fpm 哦!
九.负载配置
upstream site{
server {
server_name localhost;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
proxy_pass ;
apache 默认目录 /var/www/html
nginx 默认目录 /usr/share/nginx/html
升级php版本
查看yum的可安装的php版本列表
yum provides php
开始升级PHP更新源:
rpm -Uvh
yum remove php-common -y #移除系统自带的php-common
查看php版本
php -v
安装php fpm:
systemctl start php-fpm.service 【启动】
systemctl enable php-fpm.service【开机自启动】
CentOS yum有时出现"Could not retrieve mirrorlist "的解决办法——resolv.conf的配置
原因:没有配置resolv.conf
解决方法:
到/etc目录下配置resolv.conf加入nameserver IP,如:
search localdomain
保存再次运行上面的命令就可以.
nginx目录 : /usr/share/nginx/html
/etc/nginx/conf.d/default.conf nginx配置目录
apache目录 : /var/www/html
/etc/httpd/conf/httpd.conf apache配置文件
nginx 配置域名
cd /etc/nginx
cp default.conf imooc.conf
修改server_name imooc.test.com 以及项目目录
配置虚拟域名 windows 访问需要在host增加 linuxip
ServerName
DocumentRoot "/var/www/html/learnlaravel/public"
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
关闭防火墙
setenforce 0
安装步骤:
①.、首先要配置IIS环境,需要开启的功能如图:
"缺少 mysqli 扩展.请检查 PHP 配置. a href='Documentation.html#faqmysql' target='documentation'img src='themes/dot.gif' title='文档' alt='文档' class='icon ic_b_help' //a",请重启IIS即可.
①.1、数据库创建完成
请按以下步骤操作:
进入gd库源码目录目录,然后输入如下命令:
phpize
./configure --prefix=/usr/bin/php --with-php-config=/usr/bin/php/php-config
make
sudo make install
接着你就可以看到生成的so路径,大致如下:
然后在php.ini文件里加上:
以上内容摘自:.
SuSE Linux上搭建apache◆php◆mysql环境
shell groupadd mysql
shell useradd -g mysql mysql
shell cd /usr/local
shell gunzip /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
shell ln -s full-path-to-mysql-VERSION-OS mysql
shell cd mysql
shell chown -R mysql .
shell chgrp -R mysql .
shell scripts/mysql_install_db --user=mysql
shell chown -R root .
shell chown -R mysql data
shell bin/mysqld_safe --user=mysql
安装完成后把php.ini-dist复制到/usr/local/php/lib/,并重命名为php.ini.基本到这里PHP就安装成功了,如果中间出现错误,除了在配置的时候没有选对选项之后一般都不出现错误.
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
并确保文件中有以下一句话,没有就自己添加在所有LoadModule之后:
#/usr/local/httpd/bin/apachectl restart
先确保php.ini路径正确.
在apache配置文件httpd.conf里使用PHPIniDir指写php.ini的在目录
如:PHPIniDir
"f:/php"
在f:\php\php.ini里加入
extension_dir
=
"f:\php\ext"
(f:\php
改成你自己的php目录)
重启apache
php
phpinfo();
看一下GD是否已经加载上,
如果已经加载上,在页面中间会显示类似以下信息
gd
GD
Support
enabled
Version
or
higher
FreeType
Linkage
with
freetype
T1Lib
GIF
Read
Create
JPG
PNG
WBMP