Install Apache MySOL PHP on Ubuntu Linux OS Hint:Server Guide To find the Ubuntu Server Guide related to your specific version,please go to:hpse select your Ubuntu version and then click on Ubuntu Server Guide.For the latest LTS version (14.04.1 LTS)of Ubuntu Server,please go tohtips:/help ubuntu.com/04/serverguide/index himl Parent page:Programming Applications 目录 1.Hint Server Giuide 2.To install the default LAMP stack in Ubuntu 1004 and above 3.Starting over.How to remove the LAMP stack 4.Installing Apache2 Che 3.Virtual Hosts 5.Installing PHP 5 1.Checking PHP 5 installation 4.PHP in user directories 6.Installing MYSOL with PHP 7.Afier installing PHP 8.Afer installing MysOl Set mysql bind address 2. root password 3.Create a mysal database 4.Create a mysql user 5. Backup-Settings 9.Phpmyadmin and mysql-workbench 1.Troubleshooting Phomvadmin mysal-workbench 2.Alternative:install phpMyAdmin from sourc 3.Mysal-workbench For more intormation 10.Edit Apache Configuration 11.Installing suPHP
Install Apache MySQL PHP on Ubuntu Linux OS Hint: Server Guide To find the Ubuntu Server Guide related to your specific version, please go to: https://help.ubuntu.com/, select your Ubuntu version and then click on Ubuntu Server Guide. For the latest LTS version (14.04.1 LTS) of Ubuntu Server, please go tohttps://help.ubuntu.com/14.04/serverguide/index.html Parent page: Programming Applications 目录 1. 1. Hint: Server Guide 2. To install the default LAMP stack in Ubuntu 10.04 and above 3. Starting over: How to remove the LAMP stack 4. Installing Apache 2 1. Checking Apache 2 installation 2. Troubleshooting Apache 3. Virtual Hosts 5. Installing PHP 5 1. Checking PHP 5 installation 2. Troubleshooting PHP 5 3. php.ini development vs. production 4. PHP in user directories 6. Installing MYSQL with PHP 5 7. After installing PHP 8. After installing MySQL 1. Set mysql bind address 2. Set mysql root password 3. Create a mysql database 4. Create a mysql user 5. Backup-Settings 6. Alternatively 9. Phpmyadmin and mysql-workbench 1. Troubleshooting Phpmyadmin & mysql-workbench 2. Alternative: install phpMyAdmin from source 3. Mysql-workbench 4. For more information 10. Edit Apache Configuration 11. Installing suPHP
12.Run.Stop.Test And Restart Apache 13.Using Apache 14.Status 15.Securing Apache 16.Password-Protect a Directory 1.Password-Protect a Directory With htaccess 17.thumbnails 18.Known problems 1.Skype incompatibility 19.Other Apache Options 20.Further Information This is to help people set up and install a LAMP(Linux-Apache-MySQL-PHP)server in Ubuntu. including Apache PHP 5 and MySQL4.1 or 5.0. To install the default LAMP stack in Ubuntu 10.04 and above First refresh your package index sudo apt-get update and then install the LAMP stack sudo apt-get install lamp-server^ Mind the caret(at the end. Starting over:How to remove the LAMP stack To remove the LAMP stack remove the following packages: Note:This assumes you have noother programs that require any of these packages You might wish to simulate this removal first,and only remove the packages that don't cause removal of something desired. apache2 apache2-mpa-p refork apache2-utils apache2.2-com libapache2-mod-php5 libapr1 libaprutil1 libdbd-mysql-perl libdbi-peri libnet-daemon-perl libplrpc-perl libpq5 mysql-client-5.5 mysql-common mysql-server mysql-server-5.5 php5-common php5-mysql To also remove the debconf data,use the purge option when removing To get rid of any configurations you may have made to apache.manually remove the /etc/apache2 directory once the packages have been removed. You may also want to purge these packages: mysql-client-core-5.5 mysql-server-core-5.5
12. Run, Stop, Test, And Restart Apache 13. Using Apache 14. Status 15. Securing Apache 16. Password-Protect a Directory 1. Password-Protect a Directory With .htaccess 17. thumbnails 18. Known problems 1. Skype incompatibility 19. Other Apache Options 20. Further Information This is to help people set up and install a LAMP (Linux-Apache-MySQL-PHP) server in Ubuntu, including Apache 2, PHP 5 and MySQL 4.1 or 5.0. To install the default LAMP stack in Ubuntu 10.04 and above First refresh your package index... $ sudo apt-get update ... and then install the LAMP stack: $ sudo apt-get install lamp-server^ Mind the caret (^) at the end. Starting over: How to remove the LAMP stack To remove the LAMP stack remove the following packages: 1. Note: This assumes you have no other programs that require any of these packages. You might wish to simulate this removal first, and only remove the packages that don't cause removal of something desired. apache2 apache2-mpm-prefork apache2-utils apache2.2-common libapache2-mod-php5 libapr1 libaprutil1 libdbd-mysql-perl libdbi-perl libnet-daemon-perl libplrpc-perl libpq5 mysql-client-5.5 mysql-common mysql-server mysql-server-5.5 php5-common php5-mysql To also remove the debconf data, use the purge option when removing. To get rid of any configurations you may have made to apache, manually remove the /etc/apache2 directory once the packages have been removed. You may also want to purge these packages: mysql-client-core-5.5 mysql-server-core-5.5
Installing Apache 2 Toony install the apache2 webserver,usen method to install apache2 It requires a restart for it to work: sudo /etc/init.d/apache2 restart or s sudo service apache2 restart Checking Apache 2 installation With your web browser,go to the URI http://localhost:if you read"It works!"which is the content of the file /var/www/index.html,this proves Apache works. Troubleshooting Apache If you get this error apache2:Could not determine the server's fully qualified domain name.using 17.0.0.1 Ubuntu 13.10+ Use a text editor such as "sudo nano"at the command line or "gksudo gedit"on the desktop to create a new file. s sudo nano /etc/apache2/conf-available/fqdn,conf Or s gksu "gedit /etc/apache2/conf-available/fqdn.conf" then add serverName localhost to the file,save it.and enable your new configuration file by running the command below. sudo a2enconf fadn This can all be done in a single command with the following: s echo "ServerName localhost"I sudo tee /etc/apache2/conf-available/fgdn.conf &sudo a2enconf fqdn Ubuntu 13.04 and below In older versions of Apache,the configuration files were located ina different directory.Use a text editor such as"sudo nanoat the command lineor"gksudo gedit"on the desktop to create a new file sudo nano /etc/apache2/conf.d/fgdn Or s gksu "gedit /etc/apache2/conf.d/fqdn" then add
Installing Apache 2 To only install the apache2 webserver, use any method to install: apache2 It requires a restart for it to work: $ sudo /etc/init.d/apache2 restart or $ sudo service apache2 restart Checking Apache 2 installation With your web browser, go to the URI http://localhost : if you read "It works!", which is the content of the file /var/www/index.html , this proves Apache works. Troubleshooting Apache If you get this error: apache2: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName Ubuntu 13.10+ Use a text editor such as "sudo nano" at the command line or "gksudo gedit" on the desktop to create a new file, $ sudo nano /etc/apache2/conf-available/fqdn.conf or $ gksu "gedit /etc/apache2/conf-available/fqdn.conf" then add ServerName localhost to the file, save it, and enable your new configuration file by running the command below. sudo a2enconf fqdn This can all be done in a single command with the following: $ echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/fqdn.conf && sudo a2enconf fqdn Ubuntu 13.04 and below In older versions of Apache, the configuration files were located in a different directory. Use a text editor such as "sudo nano" at the command line or "gksudo gedit" on the desktop to create a new file, $ sudo nano /etc/apache2/conf.d/fqdn or $ gksu "gedit /etc/apache2/conf.d/fqdn" then add
ServerName localhost to the file and save.Thiscnall be done ina single command with the following echo "ServerName localhost"I sudo tee /etc/apache2/conf.d/fqdn Virtual Hosts Apache2 has the concept of sites,which are separate configuration files that Apache2 will read.These are available in/etc/apache2/sites-available.By default,there is one site available You can have many different site configurations available,and activate only those that you need. As an example,we want the default site to be /home/user/public_html/.To do this,we must create a new site and then enable it in Apache2. To create a new site: 1.Copy the default websitea starting cp /etc/apache2/sites-available/000-default.con 2.Edit the new configuration file in a text editor"sudo nano"on the command line or "gksudo gedit"for example:gksudo gedit /etc/apache2/sites-available/mysite.c onf 3. Change the DocumentRoot to point to the new location.For example,/home/user/public_html/ 4.In the file:/etc/apache2/apache2.conf,change the Directory directive, replace <Directory /var/www/>to<Directory /home/user/public html/ 5.Youcan also set separate logs for each site.To do this,change the ErrorLog and Cus tomLog directives.This is optional.but handy if you have maiy sites 6.Save the file Nowwe must deactivate activate our newone.Ubuntu providestwo small iies that take re of this ()and a2dissite(apache2disable site) s sudo a2dissite 000-default &4 sudo azensite mysite Finally,we restart Apache2: s sudo /etc/init.d/apache2 restart Ifyou have not created /home/user/public htm1/.you will receive an warning message To test the new site,create a file in /home/user/public_html/: echo '<b>Hello!It is working!</b>'>/home/user/public_html/index.html Finally,browse to http:ocalhost Installing PHP 5 Toony install PHP5.useany method to install the package
ServerName localhost to the file and save. This can all be done in a single command with the following: $ echo "ServerName localhost" | sudo tee /etc/apache2/conf.d/fqdn Virtual Hosts Apache2 has the concept of sites, which are separate configuration files that Apache2 will read. These are available in /etc/apache2/sites-available. By default, there is one site available called 000-default. This is what you will see when you browse to http://localhost orhttp://127.0.0.1. You can have many different site configurations available, and activate only those that you need. As an example, we want the default site to be /home/user/public_html/. To do this, we must create a new site and then enable it in Apache2. To create a new site: 1. Copy the default website as a starting point. sudo cp /etc/apache2/sites-available/000-default.con f /etc/apache2/sites-available/mysite.conf 2. Edit the new configuration file in a text editor "sudo nano" on the command line or "gksudo gedit", for example:gksudo gedit /etc/apache2/sites-available/mysite.c onf 3. Change the DocumentRoot to point to the new location. For example, /home/user/public_html/ 4. In the file: /etc/apache2/apache2.conf, change the Directory directive, replace <Directory /var/www/> to<Directory /home/user/public _html/> 5. You can also set separate logs for each site. To do this, change the ErrorLog and CustomLog directives. This is optional, but handy if you have many sites 6. Save the file Now, we must deactivate the old site, and activate our new one. Ubuntu provides two small utilities that take care of this: a2ensite (apache2enablesite) and a2dissite (apache2disable site). $ sudo a2dissite 000-default && sudo a2ensite mysite Finally, we restart Apache2: $ sudo /etc/init.d/apache2 restart If you have not created /home/user/public_html/, you will receive an warning message To test the new site, create a file in /home/user/public_html/: $ echo '<b>Hello! It is working!</b>' > /home/user/public_html/index.html Finally, browse to http://localhost/ Installing PHP 5 To only install PHP5. use any method to install the package
libapache2-mod-php5 Enable this module by doing sudo a2enmod php5 which createsa symbolic link /etc/apache2/mods-enabled/php5 pointing to /etc/apache2/mods-availble/php5 Except if you use deprecated PHP code beginning ony byinstead ofphp"(which is highly inadvisable),open,as root,the file /etc/php5/apache2/php.ini,look for the line"short_open_tag= On",change it to"short_open_tag=Off(not including the quotation marks)and add a line of comment(beginning by a semi-colon)giving the reason,the author and the date of this change.This way.if you later want some XML or XHTML file to be served as PHP,will be ignored by PHP instead of being a PHP code mistake Relaunch Apache 2 again: s sudo service apache2 restart Checking PHP 5 installation In /var/www.create a text file called "test php".grant the world (or.at least.Ubuntu user "apache") host/test php"if you deseription of PHF configuration,it proves PHP 5 works with Apache Troubleshooting PHP5 Does your browser ask ifyou want the php file instead of displaying it?If Apache isno actually parsing the php after you restarted it,install libapache2-mod-php5.It is installed when you install the php5 package,but may have been removed inadvertently by packages which need to run a different version of php. Ifsudo a2enmod php5 retumns"S This nodule does not exist!you should purge (not just remove) the libapachemod-php5 package and reinstall it Be sure to clear your browser's cache before testing your site again.To do this in Firefox 4:Edit- Preferences PrivacyHistory:clear your recent historyDetails:choose"Everything"in"Time range to clean"and check only"cache".then click on"Clear now" Remember that.for Apache to be called the URI in your web browser must begin with "http://"If it begins with" the file is read directly by the boser. so you get(X)HTML and CSS,but no PHP.If you didn't configure any host alias or virtual host,then a local URI begins with "http://localhost"."http://127.0.0.1"or http://followed by your IP number If the problem persists,check your PHP file authorisations(it should be readable at least by Ubuntu user"apache").and check if the PHP code is correct.For instance,copy your PHP file,replace your whole PHP file c ()(withou the):if you get the PHPtes page in your web browser,then the problem is in your PHP code,not in Apache or PHP configuratic nor in file permissions.If this doesn't work,then it is a problem of file authorisation,Apache or PHP configuration,cache not emptied,or Apache not runningor not restarted.Use the display of that test file in your web browser to see the list of files influencing PHP behaviour
libapache2-mod-php5 Enable this module by doing $ sudo a2enmod php5 which creates a symbolic link /etc/apache2/mods-enabled/php5 pointing to /etc/apache2/mods-availble/php5 . Except if you use deprecated PHP code beginning only by "<?" instead of "<?php" (which is highly inadvisable), open, as root, the file /etc/php5/apache2/php.ini , look for the line "short_open_tag = On", change it to "short_open_tag = Off" (not including the quotation marks) and add a line of comment (beginning by a semi-colon) giving the reason, the author and the date of this change. This way, if you later want some XML or XHTML file to be served as PHP, the "<?xml" tag will be ignored by PHP instead of being seen as a PHP code mistake. Relaunch Apache 2 again: $ sudo service apache2 restart Checking PHP 5 installation In /var/www , create a text file called "test.php", grant the world (or, at least, Ubuntu user "apache") permission to read it, write in it the only line: "<?php phpinfo(); ?>" (without the quotation marks) then, with your web browser, go to the URI "http://localhost/test.php": if you can see a description of PHP5 configuration, it proves PHP 5 works with Apache. Troubleshooting PHP 5 Does your browser ask if you want to download the php file instead of displaying it? If Apache is not actually parsing the php after you restarted it, install libapache2-mod-php5. It is installed when you install the php5 package, but may have been removed inadvertently by packages which need to run a different version of php. If sudo a2enmod php5 returns "$ This module does not exist!", you should purge (not just remove) the libapache2-mod-php5 package and reinstall it. Be sure to clear your browser's cache before testing your site again. To do this in Firefox 4: Edit → Preferences … Privacy → History: clear your recent history → Details : choose "Everything" in "Time range to clean" and check only "cache", then click on "Clear now". Remember that, for Apache to be called, the URI in your web browser must begin with "http://". If it begins with "file://", then the file is read directly by the browser, without Apache, so you get (X)HTML and CSS, but no PHP. If you didn't configure any host alias or virtual host, then a local URI begins with "http://localhost", "http://127.0.0.1" or http://" followed by your IP number. If the problem persists, check your PHP file authorisations (it should be readable at least by Ubuntu user "apache"), and check if the PHP code is correct. For instance, copy your PHP file, replace your whole PHP file content by "<?php phpinfo(); ?>" (without the quotation marks): if you get the PHP test page in your web browser, then the problem is in your PHP code, not in Apache or PHP configuration nor in file permissions. If this doesn't work, then it is a problem of file authorisation, Apache or PHP configuration, cache not emptied, or Apache not running or not restarted. Use the display of that test file in your web browser to see the list of files influencing PHP behaviour