I've cloned a PHP repository from git that actually is served in a server with Apache and I want to reproduce it locally. This repository is cloned in:
/home/me/test/repository
I've also installed Apache in my Ubuntu and it starts fine. Now, I need to do two things:
1. Load userdir, cgi and rewrite modules
For this, I loaded the modules by doing:
sudo a2enmod userdir
sudo a2enmod cgi
sudo a2enmod rewrite
But I don't know if have to do any extra thing :/
2. Serve the content of the repo
I have no idea of how to do this, because my logic tells me to keep the git structure to be able to push things after modifications.
I know that DocumentRoot is in /var/www/html and if I create a index.php with a simple instruction, it works fine. But how with the repo?
Related
Let's say I have a local apache2 and I need a script that runs the apache2 with a special injected VirtualHost.
More presice:
I have a xampp Installation (PHP 7.3.10, MariaDB 10.4.8, mysqlnd 5.0.12-dev, Apache 2.4.41) on Windows 10.
Several PHP projects are located all over the hard drive. Until now I modify the ./apache/conf/extra/httpd-vhosts.conf file before starting the apache2 service on every project switch. With that I can leave the project folders where there are without copying them in the xampp installation folder.
Now I am curious if I can write a script for each project (bat or sh, GitShell is installed) that will run mariadb normally and apache2 with a temporarily VirtualHost for that specific project folder as DocumentRoot.
What I currently can do:
Lay down a httpd-vhosts.conf file and a startProject.sh script in a project folder. Running the script will copy the configuration file in the xampp installation and then start the apache2 service.
That is working, but only one apache2 process can start and not multiple projects at once.
What I want:
I want to use a parameter that specifies a VirtualHost by parameter when starting apache2.
Maybe by saying apache2 to use a special config file rather then the file in the own project structure.
Or I want to use a parameter by starting the apache2 process that specifies a alternatie DocumentRoot Folder for a already specified VirtualHost.
Currently this is my approach:
#!\bin\bash
BASEDIR=$(dirname "$0")
xamppPath="C:\xampp\v7.3.10"
cd $xamppPath
"apache\bin\httpd.exe" -S "$BASEDIR\httpd-vhosts.conf" &
But -S only prints out the VirtualHosts, not setting the configuration file.
How can I achieve running a project with a script somewhere on my harddrive without overriding the existing configuration file in the xampp installation folder?
Easier: build a couple of congratulation files, use option -f to specify an effective configuration file, not -S.
Can be more complicated: user -D name and use <IfDefine name> in the configuration file to "select" sections of it to apply to a particular start.
Note: I use apachectl, not directly httpd to start/stop Apache.
In the xampp package there is no direct apachectl file, so a use of -D <name> is not possible for me. It would be the perfect solution, but unfortunately not possible.
Now I have to override the httpd-vhosts.conf file from every project I want to start it. Therefore, I am using a modified script solution:
#!\bin\bash
BASEDIR=$(dirname "$0")
xamppPath="C:\xampp\v7.3.10"
cp -f "$BASEDIR\httpd-vhosts.conf" "$xamppPath\apache\conf\extra\httpd-vhosts.conf"
sleep 1
cd $xamppPath
"apache\bin\httpd.exe" &
It is not the perfect solution, but it works.
Two apache services at the same time with two different projects is not possible, but until now not necessary.
I am running Ubuntu 16. I am fairly new to web design but I have set up a LAMP server on my Ubuntu machine and installed WordPress site. I wanted to try to mess around with PHP so I tried to install myphp.
I managed to do this and I realized that I had to install nginx also.
I did this, but my local host always diverts to a message "welcome to Nginx"
I tried to edit the configuration files but could not get it to work?
Is there a guide for installing Nginx and myphp to see phpMyAdmin, after you have already set up a WordPress site?
Like I said I am running Ubuntu 16.04.
You may need to delete the index.html file from the web root. The index.php file should remain.
On Ubuntu+nginx go to html directory using following command
cd /var/www/html/
then find out following index.nginx-debian.html and delete it or edit it as you want
To edit these file open into you editor or use Ubuntu default editor nano.
sudo nano /var/www/html/index.nginx-debian.html
To delete these file run following command.
sudo rm -rf /var/www/html/index.nginx-debian.html
these is the defautl nginx welcome page that why it appear after install, for more information check nginx default configuration file using following command.
sudo nano /etc/nginx/sites-available/default
Thanks
I configured a web service locally using FOSRestBundle, and it's working perfectly. The only thing i need to write to start my service is
php bin/console server:run xxx.xxx.x.xx:port
and it's all set.
But then i was reading some documentation about the symfony web server, and this information is confusing me:
The built-in web server is meant to be run in a controlled
environment. It is not designed to be used on public networks.
How i'm suppose to use this in my cloud environment? If i want to make this public, how should i start my REST service without using this built-in server?
What is equivalent to the "server:run" command? If i just put the code there, it will not work. I need to start the server for my REST API.
The equivaluent of the server:run command in a production environment is a bit more involved. The web server on a public facing machine has more responsibility than a local development server, and so it needs a bit more configuration.
For production (or even staging) purposes, use a production-ready web server like Apache or Nginx.
I'll share a default setup for apache, on a Debian-based (Ubuntu) system here, and detail a few common pitfalls to avoid.
Install LAMP components
ssh into your machine, and run this command to make sure that apache, php, mysql, etc, are all installed!
First, get the most recent data from the repositories:
sudo apt-get update
The LAMP components that you'll need to run symfony on:
sudo apt-get install apache2 mysql-server libapache2-mod-auth-mysql php5-mysql php5 libapache2-mod-php5 php5-mcrypt
Be sure to store down the root MySQL pass if it asks you for one. (in the event you didn't have it installed, yet.)
Configure MySQL
sudo mysql_install_db to initialize MySQL's system/help tables, etc.
sudo /usr/bin/mysql_secure_installation to drop test tables, reload privilege tables.
Jump into the MySQL shell and create a user & db for your app.
mysql -u root -p, and supply your root pw when prompted.
mysql> CREATE USER 'otuyh'#'localhost' IDENTIFIED BY 'password'; will create your otuyh user with the password password.
mysql> CREATE DATABASE otuyh_app; will create the database your app needs to run on.
mysql> GRANT ALL PRIVILEGES ON otuyh_app.* TO 'otuyh'#'localhost';
mysql> FLUSH PRIVILEGES;
Configure Apache (the production version of server:run)
Clone or upload your project to /var/www/html.
Edit /etc/apache2/sites-enabled/000-default.conf and change the line:
DocumentRoot /var/www/html to DocumentRoot /var/www/html/web
This tells apache which directory to serve requests from the web folder of your app.
Also, alter the line ServerName white-macbook to ServerName example.com where example.com is the domain name pointed at your server.
Finally, add an AllowOverride All line in there, too, to explicitly state that your .htaccess file can also add directives for the web server.
Drop an .htaccess file in your web/ folder that looks something like this:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
# Explicitly disable rewriting for front controllers
RewriteRule ^app_dev.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
RewriteRule ^(.*)$ app_dev.php [QSA,L]
</IfModule>
Alter app_dev to just app, when you're ready to change the environment to production.
Make sure you restart the apache2 service after having altered it's config: sudo service restart apache2.
Run your regular sf2 schema creation, composer install, etc.
And then, make sure that the apache user that serves the files up indeed has access to them!
Additionally, after running composer * or cache:clear as a user other than the one serving files, write permissions can get mixed up, and www-data will need this privilege to write logs, and get cached files. A quick solution:
chown -R your-unix-user:www-data ./app
find ./app/cache -type d -exec chmod 775 {} \;
find ./app/logs; -type d -exec chmod 775 {} \;
find ./app/cache -type f -exec chmod 664 {} \
find ./app/logs -type f -exec chmod 664 {} \
Like mentioned the built in Webserver is for Development only.
It is slow and open to all kinds of attacks.
You can run your Service like any other application with a Webserver.
There is a guide on the Symfony site that shows you how to do that.
http://symfony.com/doc/current/deployment.html
Or if you have root access to your cloud server you can configure your Webserver
https://symfony.com/doc/current/setup/web_server_configuration.html
I have installed macports and updated my path:
via docs:
http://guide.macports.org/#installing.shell.postflight
but now if I test any of the sites in my Sites folder, I get a 404.
so for instance if I go to localhost/~carey/test.php which is just a php_info, I get a 404
If I go to:
localhost/
I get the It Works! page
Am I missing a step to configure Macports to run apache from my Sites directory?
If I run $env from the command line I get:
TERM_PROGRAM=Apple_Terminal
SHELL=/bin/bash
TERM=xterm-256color
TMPDIR=/var/folders/rs/943jh19j31j3ld55yxqgf2mm0000gn/T/
Apple_PubSub_Socket_Render=/tmp/launch-NehzDd/Render
TERM_PROGRAM_VERSION=326
TERM_SESSION_ID=A329EAC2-AE9F-4460-BB1B-B35981BAE0ED
USER=carey
SSH_AUTH_SOCK=/tmp/launch-CgUaVv/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0:0
PATH=/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin
__CHECKFIX1436934=1
PWD=/Users/carey
LANG=en_US.UTF-8
SHLVL=1
HOME=/Users/carey
LOGNAME=carey
SECURITYSESSIONID=186b0
_=/usr/bin/env
and I can run any macport install, but I cannot configure the terminal to connect to my localhost in the browser.
So I think I have macports installed correctly, but I dont know how to make it run out of the /opt directory.
I also think this is relative to establishing the env variables, so apache knows to look to the /opt dir, but I don't know how to change it.
I am running Mavericks.
UPDATE
Following the docs recommended by eborisch here:
https://trac.macports.org/wiki/howto/MAMP
I have been able to setup the localhost directory, but still an issue.
Since I have multiple users on the machine, I had to comment out this line in httpd.conf:
Include conf/extra/httpd-userdir.conf
and added this to the httpd-userdir.conf file:
#
# Include user configurations
#
Include /private/etc/apache2/users/*.conf
which connects my Sites folder to the localhost.
I also needed to add this to the httpd.conf file to parse php files as php:
AddType application/x-httpd-php .php
Now, I have a file in my Sites dir called test.php, which has <?php phpinfo() ?>
and if I run localhost/~carey/test.php in the browser it works. phpinfo() returns that I am running php5.5.10 out of the /opt/ dir. So, all seems well. The problem is if I try to run any sites from folders in this directory. It just displays the directory tree, rather than treating it like a site.
For instance if I run,
localhost/~carey/mysite
it just returns:
Index of /~carey/mysite
Parent Directory
2005/
2006/
index.php
../
If I run
localhost/~carey/mysite/index.php
it runs that file correctly (ie looks correct in the browser)
Seems like an .htaccess issue, but not sure how I would resolve that globally for each folder in the Sites directory
any suggestions?
Probably better served on https://lists.macosforge.org/mailman/listinfo/macports-users/ the macports mailing list. But some basics:
Is the osx web server running? (Web sharing under the sharing control panel?) If so, turn it off, or configure the two to use different ports.
Is the macports apache2 installed? (sudo port install apache2)
Is it running? (sudo port load apache2)
Have you edited its configuration (/opt/local/apache2/conf/httpd.conf)?
See https://trac.macports.org/wiki/howto/MAMP for instructions on getting things up and running.
I am newbie in PHP. I have successfully installed PHP on Ubuntu, now I want start my first program. I am using gPHPEdit as IDE.
Where should I save .php files that I create? And how to run/test them?
Make sure you have LAMP installed. Do a sudo tasksel and select lamp then hit enter, its gotta be the most simple *amp install ever made. Its a good idea to install phpmyadmin: sudo apt-get install phpmyadmin. After that just copy the files to /var/www/ and then they will show up on http://localhost. I recommended using Eclipse PDT or the Netbeans build for PHP.
You should pick up a book or start following some good tutorials on the web.
If you are just scripting using php, you can save them anywhere and run the php on the terminal using the php command line interpreter.
If you are trying write web scripts (and I think you are), you need to install and configure a web server (typically apache) and save your scripts in the server's document root (typically /var/www). Also, I highly recommend you to read up a little about servers and HTTP and figure out how all this works on the inside before learning to building websites in php.
If you cannot save or copy to var/www/html, to run your php scripts on your browser. If you are using Ubuntu 14.04.
I followed these steps and it worked for me.
Execute sudo su on the terminal.
Enter your password
Execute sudo subl /etc/apache2/sites-available/000-default.conf on your terminal to open this file. Note you can change the subl to any text editor to open the file e.g sudo nano /etc/apache2/sites-available/000-default.conf.
Change DocumentRoot /var/www/html to /home/user/yoursubdir
Save the file and close it.
Execute sudo subl /etc/apache2/apache2.conf on your terminal to open this file.
Add the following to end of the file
<Directory /home/user/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Save and Close the file.
Execute sudo service apache2 restart
Go to your browser, type the URL of your script e.g 127.0.1.1/directory/document.php.
I hope this helps.
remove the index.html file from /var/www/
$ sudo rm index.html
create a new php file there:
$ sudo gedit /var/www/index.php
write in it:
<?php
print_r(phpinfo());
?>
Restart your Apache2 Server :
$ sudo service apache2 restart
OR
$ sudo /etc/init.d/apace2 restart
and point to yout localhost and /index.php
if err arises visit : http://www.allaboutlinux.eu/how-to-run-php-on-ubuntu/
https://www.php.net/manual/en/features.commandline.webserver.php
this is an easy way to test your files in php.
$ cd ~/public_html
$ php -S localhost:8000
then you can go to your browser and enter localhost:8000/myfile.php.