阿里云免费领了半年的服务器,lamp环境搭建了n次,这里总结一下基本操作。
安装apache2apt install apache2 -y
安装mysql
apt install mysql-server -y
mysql安全配置
mysql_secure_installation
是否安装验证密码插件
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: N
怕麻烦选择N,另外只要密码安全就没啥。
设置新密码
New password:
Re-enter new password:
是否删除匿名用户 Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
是否禁用远程root登陆 Y
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
删除测试数据库并访问它 Y
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
重新加载权限表 Y
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
OK!
安装php
apt install php -y
修改首先访问php文件
打开/etc/apache2/mods-enabled/dir.conf文件并将其更改为首先列出index.php。
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
重启Apache
systemctl restart apache2
文件放在/var/www/html
安装php模块例如安装curl
apt install php-curl
在查找所需的模块时遇到问题,只需输入apt install php-(模块的第一个字母),然后点击TAB键。Ubuntu将显示所有匹配的包。
# apt install php-c
php-cache-integration-tests php-cgi php-common php-console-table
php-cache-lite php-cli php-composer-ca-bundle php-constant-time
php-cache-tag-interop php-cli-prompt php-composer-semver php-curl
php-cas php-codecoverage php-composer-spdx-licenses
php-cassandra php-codesniffer php-console-commandline
常用命令
/etc/init.d/apache2 start //启动Apache服务
/etc/init.d/apache2 stop //停止Apache服务
/etc/init.d/apache2 restart //重启Apache服务
也可以使用
systemctl restart apache2