设为首页 收藏本站
查看: 601|回复: 0

[经验分享] ubuntu 16.04 LAMP 安装

[复制链接]

尚未签到

发表于 2018-4-29 14:39:59 | 显示全部楼层 |阅读模式
How To Install LAMP Stack On Ubuntu  16.04
  By M.el Khamlichi
  

  Share on>  
  Tweet on Twitter
           


  •   tweet
DSC0000.jpg

  LAMP is a combination of operating system and open-source software stack. The acronym LAMP came from the first letters ofLinux, Apache HTTP Server, MySQL or MariaDB database, and PHP/Perl/Python.This tutorial describes how to install LAMP stack on Ubuntu 16.04,
however the steps described below should work on previous Ubuntu
versions such as Ubuntu 15.10/15.04/14.10/14.04/13.10 etc.
Install LAMP Stack On Ubuntu 16.04
1. Install Apache
  Apache is an
open-source multi-platform web server. It provides a full range of web
server features including CGI, SSL and virtual domains.
  
  To install Apache, enter:
sudo apt-get install apache2Enable  and  start   your  apache
root@ubuntu:~# systemctl    enable  apache2  
root@ubuntu:~# systemctl    start  apache2
  
root@ubuntu:~# systemctl    status  apache2
  

  
● apache2.service - LSB: Apache2 web server
  
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  
   Active: active (running) since Wed 2016-03-02 09:23:37 PST; 1min 2s ago
  
     Docs: man:systemd-sysv-generator(8)
  
   CGroup: /system.slice/apache2.service
  
           ├─22328 /usr/sbin/apache2 -k start
  
           ├─22331 /usr/sbin/apache2 -k start
  
           └─22332 /usr/sbin/apache2 -k start
  

  
Mar 02 09:23:36 ubuntu systemd[1]: Starting LSB: Apache2 web server...
  
Mar 02 09:23:36 ubuntu apache2[22304]:  * Starting web server apache2
  
Mar 02 09:23:36 ubuntu apache2[22304]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'S
  
Mar 02 09:23:37 ubuntu apache2[22304]:  *
  
Mar 02 09:23:37 ubuntu systemd[1]: Started LSB: Apache2 web server.
  
Mar 02 09:24:34 ubuntu systemd[1]: Started LSB: Apache2 web server.
Test Apache:
  Open your web browser and navigate to http://localhost/ or http://server-ip-address/.
DSC0001.png

2. Install MySQL

  MySQL is a>sudo apt-get install mysql-server mysql-client  During installation, you’ll be asked to setup the MySQL “root” user password. Enter the password and click Ok.
DSC0002.jpg

  Re-enter the password.
DSC0003.jpg

  MySQL is installed now.
  You can verify the MySQL server status using command:
  On Ubuntu 16.04/15.10/15.04:
sudo systemctl status mysql  On Ubuntu 14.10 and previous versions:
sudo service mysql status  Sample output:
● mysql.service - MySQL Community Server  
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
  
Active: active (running) since Mon 2015-10-26 14:23:01 IST; 28s ago
  
Main PID: 3577 (mysqld_safe)
  
CGroup: /system.slice/mysql.service
  
├─3577 /bin/sh /usr/bin/mysqld_safe
  
└─3924 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --...
  

  
Oct 26 14:23:00 server systemd[1]: Starting MySQL Community Server...
  
Oct 26 14:23:00 server mysqld_safe[3577]: 151026 14:23:00 mysqld_safe Can't ....
  
Oct 26 14:23:00 server mysqld_safe[3577]: 151026 14:23:00 mysqld_safe Loggin....
  
Oct 26 14:23:01 server mysqld_safe[3577]: 151026 14:23:01 mysqld_safe Starti...l
  
Oct 26 14:23:01 server systemd[1]: Started MySQL Community Server.
  
Hint: Some lines were ellipsized, use -l to show in full.
3. Install MariaDB
  In case you want to use MariaDB instead of MySQL community edition, follow the steps given below.

  MariaDB is a drop in replacement for MySQL. It is a robust, scalable and>  First you have to remove existing MySQL
packages if any. To completely uninstall MySQL along with its
configuration files, enter the following commands one by one:
sudo systemctl stop mysqlsudo apt-get remove --purge mysql-server mysql-client mysql-commonsudo apt-get autoremovesudo apt-get autocleansudo rm -rf /var/lib/mysql/sudo rm -rf /etc/mysql/  After removing MySQL, run the following command to install MariaDB.
sudo apt-get install mariadb-server  Alternatively, you can install it using MariaDB repositoryif you want to try most recent version of MariaDB. Run the following
commands to add PPA. As of writing this, MariaDB PPA is not yet updated
to Ubuntu 16.04. However, we can use the repository of Ubuntu 15.10
instead.
sudo apt-get install software-properties-commonsudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943dbsudo add-apt-repository 'deb http://download.nus.edu.sg/mirror/mariadb/repo/10.1/ubuntu vivid main'  Update the software sources list and install MariaDB using following commands:
sudo apt-get updatesudo apt-get install mariadb-server  During installation you will be asked toset mysql ‘root’ user password. Enter the password twice, and complete
the installation.
  Important Note: In Ubuntu 16.04/15.10/15.04, MariaDB won’t ask you to set root user password during installation.
  Also, you can’t set password manually using the following command too:
mysql_secure_installation  It will throw the following error.
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB  
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
  

  
In order to log into MariaDB to secure it, we'll need the current
  
password for the root user. If you've just installed MariaDB, and
  
you haven't set the root password yet, the password will be blank,
  
so you should just press enter here.
  

  
Enter current password for root (enter for none):
  
ERROR 1698 (28000): Access denied for user 'root'@'localhost'Enter current password for root (enter for none):
  To fix this error, log in to mysql prompt without password as root user:
sudo mysql -u root  Then, run the following commands one by one in the mysql prompt:
use mysql;update user set plugin='' where User='root';flush privileges;\q  That’s it. Now, set database administrative “root” user password using command. Press Enter and go with the default settings.
mysql_secure_installation  Sample output:
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB  
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
  

  
In order to log into MariaDB to secure it, we'll need the current
  
password for the root user.  If you've just installed MariaDB, and
  
you haven't set the root password yet, the password will be blank,
  
so you should just press enter here.
  

  
Enter current password for root (enter for none):
  
OK, successfully used password, moving on...
  

  
Setting the root password ensures that nobody can log into the MariaDB
  
root user without the proper authorisation.
  

  
Set root password? [Y/n] y
  
New password:
  
Re-enter new password:
  
Password updated successfully!
  
Reloading privilege tables..
  
... Success!
  

  
By default, a MariaDB installation has an anonymous user, allowing anyone
  
to log into MariaDB 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? [Y/n]
  
... Success!
  

  
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? [Y/n]
  
... Success!
  

  
By default, MariaDB 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? [Y/n]
  
- Dropping test database...
  
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
  
... Failed!  Not critical, keep moving...
  
- Removing privileges on test database...
  
... Success!
  

  
Reloading the privilege tables will ensure that all changes made so far
  
will take effect immediately.
  

  
Reload privilege tables now? [Y/n]
  
... Success!
  

  
Cleaning up...
  

  
All done!  If you've completed all of the above steps, your MariaDB
  
installation should now be secure.
  

  
Thanks for using MariaDB!
  Check if mariadb is running or not, using the following command:
sudo service mysql status  Sample output:
● mysql.service - LSB: Start and stop the mysql database server daemon Loaded: loaded (/etc/init.d/mysql) Active: active (running) since Mon 2015-10-26 14:26:36 IST; 2min 5s ago  
Docs: man:systemd-sysv-generator(8)
  
CGroup: /system.slice/mysql.service
  
├─6387 /bin/bash /usr/bin/mysqld_safe
  
├─6388 logger -p daemon err -t /etc/init.d/mysql -i
  
└─6544 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --...
  

  
Oct 26 14:26:39 server /etc/mysql/debian-start[6595]: mysql.time_zone_transit...
  
Oct 26 14:26:39 server /etc/mysql/debian-start[6595]: mysql.time_zone_transit...
  
Oct 26 14:26:39 server /etc/mysql/debian-start[6595]: mysql.user ...
  
Oct 26 14:26:39 server /etc/mysql/debian-start[6595]: Phase 2/6: Fixing views
  
Oct 26 14:26:39 server /etc/mysql/debian-start[6595]: Processing databases
  
Oct 26 14:26:39 server /etc/mysql/debian-start[6595]: information_schema
  
Oct 26 14:26:39 server /etc/mysql/debian-start[6595]: mysql
  
Oct 26 14:26:39 server /etc/mysql/debian-start[6595]: performance_schema
  
Oct 26 14:26:39 server /etc/mysql/debian-start[6653]: Checking for insecure r...
  
Oct 26 14:26:39 server /etc/mysql/debian-start[6657]: Triggering myisam-recov...
  
Hint: Some lines were ellipsized, use -l to show in full.
4. Install PHP  (PHP7)
  PHP (recursive acronym
for PHP: Hypertext Preprocessor) is a widely used open-source general
purpose scripting language that is especially suited for web developmentand can be embedded into HTML.
  Install PHP with following command:
sudo apt-get update  
sudo apt-get install php7.0-mysql php7.0-curl php7.0-json php7.0-cgi  php7.0 libapache2-mod-php7
  Test  your php version
root@ubuntu:~# php -v  
PHP 7.0.3-3 (cli) ( NTS )
  
Copyright (c) 1997-2016 The PHP Group
  
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
  
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
  
root@ubuntu:~#
  To test PHP, create a sample “testphp.php” file in Apache document root folder.
sudo vi  /var/www/html/testphp.php  Add the following lines:
<?php  
phpinfo();
  
?>
  Restart apache2 service.
  On Ubuntu 15.10/15.04:
sudo systemctl restart apache2  On Ubuntu 14.10 and lower versions:
sudo service apache2 restart  Navigate to http://server-ip-address/testphp.php. It will display all the details about php such as version, build date and commands etc.
DSC0004.png

  If you want to install all php modules at once, enter the command sudo apt-get install php* and restart the apache2 service. To verify the modules, open web browser and navigate to http://server-ip-address/testphp.php. You will able to see all installed php modules.
5. Manage MySQL Databases (Optional)
Install phpMyAdmin
  phpMyAdmin is a free
open-source web interface tool used to manage your MySQL databases. It
is available in the Official Debian repositories. So install it with
command:
sudo apt-get install phpmyadmin  Select the Web server that should be automatically configured to run phpMyAdmin. In my case, it is apache2.
DSC0005.jpg

  The phpMyAdmin must have a database
installed and configured before it can be used. This can be optionally
handled by dbconfig-common.
  Select ‘Yes’ to configure database for phpmyadmin wjth dbconfig-common.
DSC0006.jpg

  Enter password of the database’s administrative user.
DSC0007.jpg

  Enter MySQL application password for phpmyadmin:
DSC0008.jpg

  Re-enter password:
DSC0009.jpg

  Success! phpMyAdmin installation is installed.
  Additional Note: if youfollowed all steps carefully, phpMyAdmin should work just fine. In casephpMyAdmin is not working, please do the following steps.
  Open terminal, and type:
sudo nano /etc/apache2/apache2.conf  Add the following line at the end.
Include /etc/phpmyadmin/apache.conf  Save and Exit. Restart apache service:
  On Ubuntu 16.04/15.10/15.04:
sudo systemctl restart apache2  On Ubuntu 14.10 and lower versions:
sudo /etc/init.d/apache2 restart6. Access phpMyAdmin Web Console
  Now, you can access the phpmyadmin console by navigating to http://server-ip-address/phpmyadmin/ from your browser.
  Enter your MySQL username and password which you have given in previous steps. In my case its “root” and “ubuntu”.
DSC00010.jpg

  You will be redirected to PhpMyAdmin main web interface.

  From here, you can manage your MySQL databases from phpMyAdmin web interface.
  That’s it. Your LAMP stack is ready to use.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-453651-1-1.html 上篇帖子: Ubuntu虚拟机使用USB 下篇帖子: Ubuntu侧边栏移动到底部
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表