Installing Apache, Php, mysql on ubuntu server

Hi everyone,

I am new to the linux distribution so if anyone could kinnda guide me through the process would be great..

Correct me if I am wrong do I need to install apache server on ubuntu server or does ubuntu server comes with apache?

If yes, how can i install apache, php and mysql using putty as my SSH?

Any help would be appreciated

Thanks

19 Replies

http://www.howtoforge.com/perfect-server-ubuntu-8.10-p3

follow that. skip parts you don't need.

http://www.routermods.com/ubuntu

My site hosted here! and q's don't hesitate to ask!

Thanks routermods.. Great article

Excellent Article!!!

I followed along, and got no errors, but i cannot load my site. if i ping the server, i get a response, but no site.

my site is silliemunkie.com

thanks,

Jason

Are you using ubuntu?

Can your stop then start your apache or do you get errors?

I'm using Ubuntu 8.10

I rebuilt the server, and started from the beginning. It seems the problem was I deleted something from the sites-available/default

I followed the rest of the tutorial, and got a site running on silliemunkie.com

I am having trouble creating a second vHost. I went through the tutorial a second time, and created the same directories, and files. when i run a2ensite for the new domain, and then reload, i get a fail error. then my original site won't load. if i run a2dissite for the new domain and reload the original domain loads again.

Is there a configuration that i need to make to allow both vhosts to run?

thank you,

Jason

cd /etc/apache2/

sudo nano sites-available/default

Delete the ‘NameVirtualHost *’ line and change the next ‘VirtualHost’ line so the file begins like this:

ServerAdmin webmaster@localhost

DocumentRoot /var/www/

if so open up you apache error log and post it for me. /etc/apache2/error.log

The NameVirtualHost does not appear in the file

here are the entries in the error log

[Thu Dec 18 21:40:12 2008] [notice] Graceful restart requested, doing restart

(2)No such file or directory: apache2: could not open error log file /var/www/v$

Unable to open logs

(2)No such file or directory: apache2: could not open error log file /var/www/v$

Unable to open logs

[Thu Dec 18 21:40:42 2008] [warn] pid file /var/run/apache2.pid overwritten – $

[Thu Dec 18 21:40:42 2008] [notice] Apache/2.2.9 (Ubuntu) configured – resumin$

[Thu Dec 18 21:43:19 2008] [notice] Graceful restart requested, doing restart

[Thu Dec 18 21:43:19 2008] [notice] Apache/2.2.9 (Ubuntu) configured – resumin$

[Thu Dec 18 21:43:32 2008] [notice] Graceful restart requested, doing restart

(2)No such file or directory: apache2: could not open error log file /var/www/v$

Unable to open logs

(2)No such file or directory: apache2: could not open error log file /var/www/v$

Unable to open logs

[Thu Dec 18 21:44:34 2008] [warn] pid file /var/run/apache2.pid overwritten – $

[Thu Dec 18 21:44:34 2008] [notice] Apache/2.2.9 (Ubuntu) configured – resumin$

[Thu Dec 18 22:05:43 2008] [error] [client 199.217.156.114] File does not exist$

[Thu Dec 18 22:05:46 2008] [error] [client 199.217.156.114] File does not exist$

[Thu Dec 18 22:30:34 2008] [error] [client 221.192.199.36] File does not exist:$

thanks,

Jason

there is something wrong with your log folder. Make sure you adjust permissions to let apache write to the folder. and make sure you named correct or set correct path in the site:

Custom Virtual Hosts

We’ve set up the basics and now we’re ready to add our own virtual hosts so we can start to serve our domains.

Let’s go ahead and create the vhost file for domain.com:

nano /etc/apache2/sites-available/domain.com

The contents need to look like this:

Place any notes or comments you have here

It will make any customisation easier to understand in the weeks to come

domain: domain1.com

public: /var/www/vhosts/domain.com/domain.com/

# Admin email, Server Name (domain name) and any aliases

ServerAdmin webmaster@domain.com

ServerName domain.com

ServerAlias www.domain.com

Index file and Document Root (where the public files are located)

DirectoryIndex index.html

DocumentRoot /var/www/vhosts/domain.com/htdocs

****# Custom log file locations

LogLevel warn

ErrorLog /var/www/vhosts/domain.com/log/error.log

CustomLog /var/www/vhosts/domain.com/log/access.log combined****

i corrected the permissions for the logs. just want to double check my settings.

here is the default from sites-available/default

ServerAdmin webmaster@localhost

DocumentRoot /var/www/

Options FollowSymLinks

AllowOverride None

Options Indexes FollowSymLinks MultiViews

AllowOverride None

Order allow,deny

allow from all

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

AllowOverride None

Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch

Order allow,deny

Allow from all

ErrorLog /var/log/apache2/error.log

Possible values include: debug, info, notice, warn, error, crit,

alert, emerg.

LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ "/usr/share/doc/"

Options Indexes MultiViews FollowSymLinks

AllowOverride None

Order deny,allow

Deny from all

Allow from 127.0.0.0/255.0.0.0 ::1/128

here is the code from sites-available/silliemunkie.com

Place any notes or comments you have here

It will make any customisation easier to understand in the weeks to come

domain: domain1.com

public: /var/www/vhosts/domain.com/domain.com/

# Admin email, Server Name (domain name) and any aliases

ServerAdmin webmaster@silliemunkie.com

ServerName silliemunkie.com

ServerAlias www.silliemunkie.com

Index file and Document Root (where the public files are located)

DirectoryIndex index.html

DocumentRoot /var/www/vhosts/silliemunkie.com/htdocs

Custom log file locations

LogLevel warn

ErrorLog /var/www/vhosts/domain.com/log/error.log

CustomLog /var/www/vhosts/domain.com/log/access.log combined

anything look out of order?

thanks,

Jason

if i leave all of the default settings and files in place, I can view both domains. but if i run a2dissite default, and then a2ensite silliumunkie, and then reload, i can't see either site. if i reverse those changes, the sites are back on-line.

silliemunkie.com

thecatatemysourcecode.com

thanks,

Jason

Okay, i think i got it fixed. I installed webmin, and created two new virtual hosts using the webmin apache interface. Both sites load now, and display the pages i created. Which means that i missed something when i was creating the vHosts via the command line. Now i need to go through all of the files and figure out what i missed.

thanks for your help,

Jason

I found that when I needed two or more VirtualHosts, I needed to add the following to the apache2.conf file:

NameVirtualHost *:80
 <ifmodule mod_ssl.c="">NameVirtualHost *:443</ifmodule> 

If I didn't add that line, I got the following error when reloading Apache2:

[warn] default VirtualHost overlap on port 80, the first has precedence

Try the above, and see if that works.

maybe a little off topic. This page is about Nginx, mysql, php and wordpress

http://www.mensk.com/webmaster-toolbox/ … wordpress/">http://www.mensk.com/webmaster-toolbox/perfect-ubuntu-hardy-nginx-mysql5-php5-wordpress/

I post this page because I think it's a complete guide on an application (WordPress) setup, so it's very helpful for newcomers. And, one day, you may be interested in Nginx :-)

please be noted, this page is written for SliceHost, but really it can be used on any Ubuntu server.

@zhouxiaohu:

maybe a little off topic. This page is about Nginx, mysql, php and wordpress

http://www.mensk.com/webmaster-toolbox/ … wordpress/">http://www.mensk.com/webmaster-toolbox/perfect-ubuntu-hardy-nginx-mysql5-php5-wordpress/

I post this page because I think it's a complete guide on an application (WordPress) setup, so it's very helpful for newcomers. And, one day, you may be interested in Nginx :-)

please be noted, this page is written for SliceHost, but really it can be used on any Ubuntu server.

To add some extra confusion, in my signature there's a guide for Lighttpd instead of Apache and nginx, in combination with PHP/MySQL and mail via Google apps for domain (with msmtp)

Seemed appropriate to ask questions in this ongoing thread. I'm setting up a web server so I can ultimately transfer my site there. I used the perfect server guide found at the beginning of this thread on a clean install of Ubuntu 8.10. Before I jump to the end, some notes on the process:

(1) I began with step 8.

(2) AppArmor did not seem to be installed by default.

(3) Step 15 asks you to telnet to test an install. My results differed slightly:

250-AUTH PLAIN NTLM LOGIN DIGEST-MD5 CRAM-MD5

instead of

250-AUTH PLAIN LOGIN

(4) phpMyAdmin was not included in guide, but I installed it before step 22 (ISPConfig installation). At this point, the phpMyAdmin index page would show text (due to php being disabled globally I assume) and visiting the site would display "It works!" or some variation of.

(5) The installation of ISPConfig 3 seemed to duplicate a lot of the packages I had already installed following the guide. I left those out. I did not install suPHP.

(6) During the installation of ISPConfig I landed at this prompt: > ISPConfig Port [8080]:
Without finding any further instructions I quit and was greeted with:
> Installation terminated by user.
This was not my intention. If there's further configuration to do I'm unsure how to go about it.

(7) I made the Apache fixes as instructed for ISPConfig, then uncommented the lines in /etc/mime.types for PHP, assuming this would let me run php files (such as phpmyadmin). However… things appear to be fubar'd. I get a nice 404 visiting the site now, and restarting Apache gives me this warning:
> [warn]NameVirtualHost *:80 has no VirtualHosts

Is the installation salvageable, or do I start from scratch? Any help is appreciated.

> Correct me if I am wrong do I need to install apache server on ubuntu server or does ubuntu server comes with apache?
You might want to install lighttpd instead of apache, depending on how much memory your linode account has, as it uses less RAM.

Steps

1. Firewall

# apt-get install arno-iptables-firewall

The installation will prompt you for the ports to enabled. Ports you may want to enable:
* 7 echo (for ping)

  • 22 ssh

  • 25 smtp

  • 80 http

  • 110 pop3

  • 143 Imap

  • 443 https

  • 993 Imap over ssl/tls

  • 995 pop3 over ssl/tls

  • 3306 mysql
    2. Create a script, say, ~/firewall-stop to flush all iptables rules (just in case you need it).

#!/bin/bash 
echo "Stopping firewall and allowing everyone..." 
iptables -F 
iptables -X 
iptables -t nat -F 
iptables -t nat -X 
iptables -t mangle -F 
iptables -t mangle -X 
iptables -P INPUT ACCEPT 
iptables -P FORWARD ACCEPT 
iptables -P OUTPUT ACCEPT 
# sudo chmod u+x ~/firewall-stop

You can execute it

# sudo ~/firewall-stop

if you get locked out, from the linode console java applet (without needing to ssh).

3. Install lighttpd

# aptitude install lighttpd 

4. Either create a file uploads directory for lighttpd or set uploadtmpdir in php.ini and create the directory, setting the group to www-data (chgrp) and setting the permissions appropriately. This step is not needed as of lighttpd 1.4.19 and above.

# mkdir /var/cache/lighttpd/uploads 
# chgrp –R www-data /var/cache/lighttpd/uploads 
# chmod g+rw /var/cache/lighttpd/uploads 

5. Enable fastcig and auth modules

# lighty-enable-mod fastcgi auth 

6. Install php and phpmyadmin

# aptitude install php-cgi php5-cli php-db php-pear php5-gd php5-mcrypt php5-mysql php5-xcache phpmyadmin

7. Create the ‘recommended’ php.ini

# cp /usr/share/doc/php5-common/examples/php.ini-recommended /etc/php5/cgi/php.ini 

8. Configure fast-cgi

fastcgi.server = 
(
 ".php" =>  ((     "bin-path" => "/usr/bin/php-cgi -c /etc/php5/cgi/php.ini", 
    "socket" => "/tmp/php.socket", 
    "max-procs" => 1, 
    "idle-timeout" => 20, 
    "bin-environment" => ( "PHP_FCGI_CHILDREN" => "4", "PHP_FCGI_MAX_REQUESTS" => "10000" ), 
"bin-copy-environment" => ( "PATH", "SHELL", "USER" ), 
"broken-scriptfilename" => "enable"
 )) 
) 

See Lighttpd and PHP configuration for more information. max-procs = 1 is recommended is using an php op code cacher.

9. Install php op code cacher xcache.

# aptitude install  php5-xcache

Encrypt and set the password for the administration page for xcache. See How to Install XCache Administration Page. You need to encrypt your xcache admin password by creating and running this php script:
substituting your actuall password for "password". Then edit /etc/php5/conf.d/xcache.ini and change the lines

xcache.admin.user = "mOo"
xcache.admin.pass = "5f4dcc3b5aa765d61d8327deb882cf99"

using a user name of your choice and the encrypted password generate from the script above.

10. Set up any virtual hosts for lighttpd (If you have many, then you would want to either enable simple_vhost or use the built-in evhost.path-pattern setting in /etc/lighttpd/lighttpd.conf).

Sampe virtual hosts

# sudo nano /etc/lighttpd/lighttpd.conf
$HTTP["host"] =~ "^(www\.)?sampledomain1.com$" {
 server.document-root = "/usr/share/phpgedview/"
}

$HTTP["host"] =~ "^(www\.)?someblog.com$" {
 server.document-root = "/usr/share/wordpress/"
}

$HTTP["host"] =~ "^(www\.)?sampledomain3.com$" {
   server.document-root = "/var/www/sampledomain3.com/"
}

# /etc/init.d/lighttpd force-reload. 

=~ signifies a regular expresssion syntax is being used.

Include any aliases in a separate file.

# sudo nano /etc/lighttpd/myconf.conf
alias.url += ( "/xcache-admin" => "/usr/share/xcache/admin",
"/aptitude" => "/usr/share/doc/aptitude/html/en",
"/apt-doc" => "/usr/share/doc/apt-doc")

Edit /etc/lighttpd/lighttpd.conf and add the line

include "myconf.conf"

after the virtual host entries.

11. Set up users and password for any password-protected lighttpd directories. See this guide: Lighttpd setup a password protected directory

12. restart lighttpd

# /etc/init.d/lighttpd restart 

Following up on my previous post: I blanked out my installation and started from scratch. I installed ISPConfig 2 and was able to login without problems. I updated the e-mail address to my own from the default root@localhost then logged out. I installed phpMyAdmin only to find out I could no longer connect to ISPConfig. I uncommented PHP in /etc/mime.types and in /etc/apache2/mods-enabled/php5.conf (as per the Perfect Server guide) which gets phpMyAdmin working, but still no luck with ISPConfig. Any ideas what I may have missed?

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct