yumphpdevel
『壹』 LAMP - CentOS7+Apache2.4+Mysql8+php7.3環境搭建
yum -y install epel-release
yum -y install yum-utils
yum update
yum -y install httpd
systemctl enable httpd
systemctl start httpd
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
# 隱藏版本號
vim /etc/httpd/conf.d/secure.conf
TraceEnable off
ServerSignature Off
ServerTokens Prod
# 配置vhost
vim /etc/httpd/conf.d/vhosts.conf
DocumentRoot "/var/www/html"
ServerName example.com
ServerAlias www.example.com
ErrorLog "logs/example.com-error_log"
CustomLog "logs/example.com-access_log" combined
yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional
yum install certbot python2-certbot-apache
certbot --apache
systemctl restart httpd
# 安裝MySQL8 YUM源
rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
yum install mysql-community-server
systemctl enable mysqld
systemctl start mysqld
# 查看自動生成的MySQL密碼
grep "password" /var/log/mysqld.log
# 登錄MySQL後修改密碼
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密碼';
# 刷新MySQL許可權表
FLUSH PRIVILEGES;
yum-config-manager --disable remi-php54
yum-config-manager --enable remi-php73
yum -y install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-opcache php-redis php-soap
# 隱藏php版本號
vim /etc/php.ini
expose_php = off
系統參數設置
# 文件打開數設置
ulimit -n 65535
vim /etc/security/limits.d/nofile.conf
* soft nofile 65535
* hard nofile 65535
# 內核網路優化
vim /etc/sysctl.conf
# 啟用timewait 快速回收
net.ipv4.tcp_tw_recycle = 1
『貳』 linux centos 7 下用yum 安裝iso鏡像里自帶的php5.4.16版本的但是沒有php-fqm文件不知道怎麼重啟php服務
systemctl restart php-fpm.service #這條命令是重啟php服務
下面是一個比較靠譜的php安裝步驟:
先刪除已有的php版本 ,執行下面的命令刪除php
yum remove php-common
然後像安裝那樣問你是否繼續的,輸入yes即可
添加 yum 源
CentOS 6.x 的源
# rpm -Uvh http://download.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
安裝 PHP
# yum install --enablerepo=remi,remi-php56 php php-opcache php-pecl-apcu php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-pdo php-pear php-fpm php-cli php-xml php-bcmath php-process php-gd php-common
註:安裝5.6版本為remi-php56,安裝5.5版本為remi-php55
『叄』 centos伺服器怎麼配置環境
安裝apache:
yum install httpd httpd-devel
啟動apache:
/etc/init.d/httpd start
此時輸入伺服器的IP地址,應該看到apache的服務頁面,埠不用輸,apache默認就是使用80埠
安裝mysql:
yum install mysql mysql-server
啟動mysql:
/etc/init.d/mysqld start
安裝php
yum install php php-devel
重啟apache使php生效
/etc/init.d/httpd restart
此時可以在目錄:/var/www/html/下建立一個PHP文件
代碼:
<?php phpinfo(); ?>
然後訪問這個文件,就能看到PHP的一些信息,php.ini配置文件的路徑可以在這個頁面上看到
安裝php的擴展
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
安裝完擴展之後需要再次重啟apache
/etc/init.d/httpd restart
測試mysql是否鏈接成功的php代碼
<?php
$con = mysql_connect("10.0.@.@@","@@","@@");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mydb", $con);
$result = mysql_query("SELECT * FROM sys_user");
while($row = mysql_fetch_array($result))
{
echo $row['UserName'] . " " . $row['PassWord'] . " " . $row['id'];
echo "<br />";
}
mysql_close($con);
?>
可以把上面的代碼傳入目錄/var/www/html/
就可以看到執行情況
『肆』 linux php-7.1.8怎麼安裝php-devel
用yum安裝
首先查找yum包 看有沒有對應版本
yumsearchphp-devel
rpm-Uvhhttps://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm-Uvhhttps://mirror.webtatic.com/yum/el7/webtatic-release.rpm
之後再次查找安裝就好了!